Merged in feature/dockerfileintest (pull request #130)
Dockerfile in Test * dockerfile * network * const
This commit is contained in:
+1
-1
@@ -13,8 +13,8 @@
|
||||
"COGNITO_CLIENT_ID": "552cqkf3640t39ncehkmgpce31",
|
||||
"COGNITO_CLIENT_SECRET": "aaknqeq9ajr07qjch4tkq38ulghvn2i8v7tn3d2fcv44uevfemf",
|
||||
"COGNITO_DOMAIN": "https://us-east-21y6po8rr8.auth.us-east-2.amazoncognito.com",
|
||||
"COGNITO_USER_POOL_ID": "us-east-2_1y6po8rR8",
|
||||
"COGNITO_REGION": "us-east-2",
|
||||
"COGNITO_USER_POOL_ID": "us-east-2_1y6po8rR8",
|
||||
"DB_NOSSL": "true",
|
||||
"DOCUMENT_CLEAN_URL": "http://localstack:4566/queue/us-east-1/000000000000/document_clean",
|
||||
"DOCUMENT_INIT_URL": "http://localstack:4566/queue/us-east-1/000000000000/document_init",
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestRunMigrations(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
NoMigrations: true,
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestClean(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestClient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestCollector(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestDocument(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestQueries(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -231,7 +231,7 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -450,7 +450,7 @@ func TestQueriesList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -506,7 +506,7 @@ func TestListQueryClients(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestResults(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -162,7 +162,7 @@ func TestResultValues(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -376,7 +376,7 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -176,7 +176,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -247,7 +247,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -414,7 +414,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -507,7 +507,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -609,7 +609,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -743,7 +743,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -830,7 +830,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -865,7 +865,7 @@ func TestClientSync(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -1070,7 +1070,7 @@ func BenchmarkIsClientSynced(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(b, ctx)
|
||||
net := test.GetNetwork(b, ctx)
|
||||
_ = test.CreateDB(b, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -1090,7 +1090,7 @@ func BenchmarkGetDocumentExternal(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(b, ctx)
|
||||
net := test.GetNetwork(b, ctx)
|
||||
_ = test.CreateDB(b, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestTextExtraction(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -131,7 +131,7 @@ func TestTextTextractPart(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
@@ -261,7 +261,7 @@ func TestTextOutPart(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestNewAPI(t *testing.T) {
|
||||
|
||||
cfg := &BaseConfig{}
|
||||
_ = serviceconfig.InitializeConfig(cfg)
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
NoMigrations: true,
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestNewRunner(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cfg := &TestConfig{}
|
||||
_ = serviceconfig.InitializeConfig(cfg)
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
|
||||
a := test.CreateAWSContainer(t, ctx, cfg, net)
|
||||
test.SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestNewServer(t *testing.T) {
|
||||
|
||||
cfg := &server.BaseConfig{}
|
||||
_ = serviceconfig.InitializeConfig(cfg)
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
NoMigrations: true,
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestSetDBPool(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
err := cfg.SetDBPool(ctx)
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestCalculateAndCompareETag(t *testing.T) {
|
||||
|
||||
cfg := &StoreConfig{}
|
||||
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
acfg := test.CreateAWSContainer(t, ctx, cfg, net)
|
||||
test.SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
|
||||
test.CreateBucket(t, ctx, cfg)
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestCreateAPI(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
_ = serviceconfig.InitializeConfig(cfg)
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{NoMigrations: true})
|
||||
|
||||
acfg := &test.APIConfig{
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestCreateQueueContainer(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cfg := &TestAWSConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
qcfg := CreateAWSContainer(t, ctx, cfg, net)
|
||||
assert.NotNil(t, qcfg)
|
||||
|
||||
+18
-16
@@ -13,8 +13,10 @@ import (
|
||||
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/gruntwork-io/terratest/modules/shell"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
@@ -43,7 +45,7 @@ var (
|
||||
imageBuild sync.Once
|
||||
)
|
||||
|
||||
func buildImage(t testing.TB) {
|
||||
func buildImage(t testing.TB, ctx context.Context) {
|
||||
imageBuild.Do(func() {
|
||||
dockerContextPath, err := os.Getwd()
|
||||
require.NoError(t, err, "Failed to get current directory")
|
||||
@@ -54,25 +56,25 @@ func buildImage(t testing.TB) {
|
||||
candidatePath := filepath.Join(dockerContextPath, dockerfilePath)
|
||||
|
||||
t.Logf("Checking for Dockerfile at: %s", dockerContextPath)
|
||||
if _, err := os.Stat(candidatePath); err == nil {
|
||||
dockerfilePath = candidatePath
|
||||
t.Logf("Found Dockerfile at: %s", candidatePath)
|
||||
_, err := os.Stat(candidatePath)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
dockerContextPath = filepath.Join(dockerContextPath, "..")
|
||||
}
|
||||
|
||||
dockerBuildCmd := shell.Command{
|
||||
Command: "docker",
|
||||
Args: []string{
|
||||
"build",
|
||||
"--file", dockerfilePath,
|
||||
"--tag", imageTag,
|
||||
dockerContextPath,
|
||||
},
|
||||
}
|
||||
err = shell.RunCommandE(t, dockerBuildCmd)
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
require.NoError(t, err)
|
||||
|
||||
buildContext, err := archive.TarWithOptions(dockerContextPath, &archive.TarOptions{})
|
||||
require.NoError(t, err)
|
||||
defer buildContext.Close()
|
||||
|
||||
_, err = cli.ImageBuild(ctx, buildContext, types.ImageBuildOptions{
|
||||
Dockerfile: dockerfilePath,
|
||||
Tags: []string{imageTag},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -111,7 +113,7 @@ func createContainer(t testing.TB, ctx context.Context, network string, cfg *con
|
||||
env[string(GetRunnerEnvFromName(e))] = GetQueueURL(t, cfg.Cfg, e)
|
||||
}
|
||||
|
||||
buildImage(t)
|
||||
buildImage(t, ctx)
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: imageTag,
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestBuildImage(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
buildImage(t)
|
||||
buildImage(t, t.Context())
|
||||
|
||||
exists := docker.DoesImageExist(t, imageTag, nil)
|
||||
assert.True(t, exists)
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestCreateDB(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
dbcfg := test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{NoMigrations: true})
|
||||
|
||||
assert.NotNil(t, dbcfg)
|
||||
@@ -35,7 +35,7 @@ func TestCreateDBWithMigrations(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
net := test.GetNetwork(t, ctx)
|
||||
dbcfg := test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
||||
|
||||
assert.NotNil(t, dbcfg)
|
||||
|
||||
@@ -91,7 +91,7 @@ type Dependencies struct {
|
||||
}
|
||||
|
||||
func CreateFullDependencies(t testing.TB, ctx context.Context, cfg FullDependenciesConfig) (Dependencies, func()) {
|
||||
network := DepNetwork.Get(t, ctx)
|
||||
network := GetNetwork(t, ctx)
|
||||
|
||||
deps := Dependencies{
|
||||
Network: network,
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestWaitForMockEndpoint(t *testing.T) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
server, cleanup := CreateMockServer(t, ctx, net)
|
||||
defer cleanup()
|
||||
|
||||
+17
-46
@@ -12,59 +12,30 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type NetworkManager struct {
|
||||
networkName string
|
||||
mutex sync.Mutex
|
||||
initialized bool
|
||||
}
|
||||
|
||||
var (
|
||||
DepNetwork = &NetworkManager{}
|
||||
)
|
||||
|
||||
const (
|
||||
networkName = "queryorchestration_test"
|
||||
)
|
||||
|
||||
func (nm *NetworkManager) Get(t testing.TB, ctx context.Context) string {
|
||||
nm.mutex.Lock()
|
||||
defer nm.mutex.Unlock()
|
||||
var (
|
||||
networkOnce sync.Once
|
||||
)
|
||||
|
||||
if nm.initialized {
|
||||
return nm.networkName
|
||||
}
|
||||
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
require.NoError(t, err)
|
||||
|
||||
nm.networkName = networkName
|
||||
|
||||
current, err := cli.NetworkList(ctx, network.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
for _, c := range current {
|
||||
if c.Name == nm.networkName {
|
||||
found = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
return nm.networkName
|
||||
}
|
||||
|
||||
_, err = cli.NetworkCreate(ctx, nm.networkName, network.CreateOptions{
|
||||
Driver: "bridge",
|
||||
})
|
||||
conflictErrorMsg := fmt.Sprintf("Error response from daemon: network with name %s already exists", nm.networkName)
|
||||
if err != nil && err.Error() != conflictErrorMsg {
|
||||
func GetNetwork(t testing.TB, ctx context.Context) string {
|
||||
networkOnce.Do(func() {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
slog.Info("created network", "name", nm.networkName)
|
||||
_, err = cli.NetworkCreate(ctx, 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)
|
||||
}
|
||||
|
||||
nm.initialized = true
|
||||
slog.Info("created network", "name", networkName)
|
||||
|
||||
return nm.networkName
|
||||
})
|
||||
|
||||
return networkName
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
func TestDepNetworkGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
name := test.DepNetwork.Get(t, ctx)
|
||||
name := test.GetNetwork(t, ctx)
|
||||
assert.NotNil(t, name)
|
||||
|
||||
newName := test.DepNetwork.Get(t, ctx)
|
||||
newName := test.GetNetwork(t, ctx)
|
||||
assert.Equal(t, name, newName)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestCreateBucket(t *testing.T) {
|
||||
|
||||
cfg := &StoreConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
acfg := CreateAWSContainer(t, ctx, cfg, net)
|
||||
SetStoreClient(t, ctx, cfg, acfg.ExternalEndpoint)
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestCreateStoreClient(t *testing.T) {
|
||||
|
||||
cfg := &StoreConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
acfg := CreateAWSContainer(t, ctx, cfg, net)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestCreateQueue(t *testing.T) {
|
||||
|
||||
cfg := &TestConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
a := CreateAWSContainer(t, ctx, cfg, net)
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestAssertMessageWait(t *testing.T) {
|
||||
|
||||
cfg := &TestConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
a := CreateAWSContainer(t, ctx, cfg, net)
|
||||
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
||||
@@ -77,7 +77,7 @@ func TestAssertMessageBodyWait(t *testing.T) {
|
||||
|
||||
cfg := &TestConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
a := CreateAWSContainer(t, ctx, cfg, net)
|
||||
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
||||
@@ -101,7 +101,7 @@ func TestAssertMessageAttrWait(t *testing.T) {
|
||||
|
||||
cfg := &TestConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
a := CreateAWSContainer(t, ctx, cfg, net)
|
||||
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestCreateRunner(t *testing.T) {
|
||||
|
||||
cfg := &TestConfig{}
|
||||
|
||||
net := DepNetwork.Get(t, ctx)
|
||||
net := GetNetwork(t, ctx)
|
||||
|
||||
a := CreateAWSContainer(t, ctx, cfg, net)
|
||||
SetQueueClient(t, ctx, cfg, a.ExternalEndpoint)
|
||||
|
||||
Reference in New Issue
Block a user