Skip to content

Commit

Permalink
handle panic in network creation for integrations
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Feb 4, 2025
1 parent 005389c commit e2b425a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion integration/dockertestutil/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dockertestutil
import (
"errors"
"net"
"fmt"

"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
Expand All @@ -12,7 +13,10 @@ var ErrContainerNotFound = errors.New("container not found")

func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (*dockertest.Network, error) {
networks, err := pool.NetworksByName(name)
if err != nil || len(networks) == 0 {
if err != nil {
return nil, fmt.Errorf("looking up network names: %w", err)
}
if 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.
Expand All @@ -22,6 +26,8 @@ func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (*dockertest.Ne
}

return &networks[0], nil
} else {
return nil, fmt.Errorf("creating network: %w", err)
}
}

Expand Down

0 comments on commit e2b425a

Please sign in to comment.