2025-01-10 19:17:20 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
2025-05-03 01:16:53 +00:00
|
|
|
"fmt"
|
2025-04-22 14:40:16 +00:00
|
|
|
"log/slog"
|
|
|
|
|
"sync"
|
2025-01-10 19:17:20 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-04-22 14:40:16 +00:00
|
|
|
"github.com/docker/docker/api/types/network"
|
|
|
|
|
"github.com/docker/docker/client"
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-01-10 19:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
2025-04-22 14:40:16 +00:00
|
|
|
const (
|
|
|
|
|
networkName = "queryorchestration_test"
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-03 11:29:10 +00:00
|
|
|
var (
|
|
|
|
|
networkOnce sync.Once
|
|
|
|
|
)
|
2025-04-22 14:40:16 +00:00
|
|
|
|
2025-05-05 09:31:21 +00:00
|
|
|
func GetNetwork(t testing.TB) string {
|
2025-05-03 11:29:10 +00:00
|
|
|
networkOnce.Do(func() {
|
|
|
|
|
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
|
|
|
|
require.NoError(t, err)
|
2025-04-22 14:40:16 +00:00
|
|
|
|
2025-05-05 09:31:21 +00:00
|
|
|
_, err = cli.NetworkCreate(t.Context(), networkName, network.CreateOptions{
|
2025-05-03 11:29:10 +00:00
|
|
|
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)
|
2025-04-22 14:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-03 11:29:10 +00:00
|
|
|
slog.Info("created network", "name", networkName)
|
2025-05-03 01:16:53 +00:00
|
|
|
})
|
2025-04-22 14:40:16 +00:00
|
|
|
|
2025-05-03 11:29:10 +00:00
|
|
|
return networkName
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|