Move some helper functions into dockertestutil package
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
b331e3f736
commit
f68ba7504f
3 changed files with 143 additions and 0 deletions
21
integration/dockertestutil/network.go
Normal file
21
integration/dockertestutil/network.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package dockertestutil
|
||||
|
||||
import "github.com/ory/dockertest/v3"
|
||||
|
||||
func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (*dockertest.Network, error) {
|
||||
networks, err := pool.NetworksByName(name)
|
||||
if err != nil || len(networks) == 0 {
|
||||
if _, err := pool.CreateNetwork(name); err == nil {
|
||||
// Create does not give us an updated version of the resource, so we need to
|
||||
// get it again.
|
||||
networks, err := pool.NetworksByName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &networks[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
return &networks[0], nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue