package test import ( "fmt" "log/slog" "sync" "testing" "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" "github.com/stretchr/testify/require" ) const ( networkName = "queryorchestration_test" ) var networkOnce sync.Once func GetNetwork(t testing.TB) string { networkOnce.Do(func() { cli := getDockerClient(t) defer cli.Close() _, err := cli.NetworkCreate(t.Context(), networkName, network.CreateOptions{ Driver: network.NetworkBridge, }) conflictErrorMsg := fmt.Sprintf("Error response from daemon: network with name %s already exists", networkName) if err != nil && err.Error() != conflictErrorMsg { require.NoError(t, err) } slog.Info("created network", "name", networkName) }) return networkName } func getDockerClient(t testing.TB) *client.Client { cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) require.NoError(t, err) return cli }