From 352c8702239a219d8ba76da0e3a96fbec710dffb Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 22 Feb 2024 10:51:53 -0500 Subject: [PATCH 1/3] Move the client tests into a test package This work has been extracted from #2202 and is related to #2180. See the original PR for the full context and reasoning. This will help with the documentation, since all examples will now have the module prefixes. --- docker_auth_config_test.go | 158 ++++++++++++++++++++++++++++++++ docker_auth_test.go | 182 ++++--------------------------------- docker_client_test.go | 8 +- docker_exec_test.go | 19 ++-- docker_mounts.go | 6 ++ utils_test.go | 41 +++++++++ 6 files changed, 238 insertions(+), 176 deletions(-) create mode 100644 docker_auth_config_test.go create mode 100644 utils_test.go diff --git a/docker_auth_config_test.go b/docker_auth_config_test.go new file mode 100644 index 0000000000..9094a01cf1 --- /dev/null +++ b/docker_auth_config_test.go @@ -0,0 +1,158 @@ +// This test is testing very internal logic that should not be exported away from this package. We'll +// leave it in the main testcontainers package. Do not use for user facing examples. +package testcontainers + +import ( + "context" + "path/filepath" + "testing" + + "github.com/cpuguy83/dockercfg" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go/internal/core" +) + +const exampleAuth = "https://example-auth.com" + +var testDockerConfigDirPath = filepath.Join("testdata", ".docker") + +var indexDockerIO = core.IndexDockerIO + +func TestGetDockerConfig(t *testing.T) { + const expectedErrorMessage = "Expected to find %s in auth configs" + + // Verify that the default docker config file exists before any test in this suite runs. + // Then, we can safely run the tests that rely on it. + defaultCfg, err := dockercfg.LoadDefaultConfig() + require.NoError(t, err) + require.NotEmpty(t, defaultCfg) + + t.Run("without DOCKER_CONFIG env var retrieves default", func(t *testing.T) { + t.Setenv("DOCKER_CONFIG", "") + + cfg, err := getDockerConfig() + require.NoError(t, err) + require.NotEmpty(t, cfg) + + assert.Equal(t, defaultCfg, cfg) + }) + + t.Run("with DOCKER_CONFIG env var pointing to a non-existing file raises error", func(t *testing.T) { + t.Setenv("DOCKER_CONFIG", filepath.Join(testDockerConfigDirPath, "non-existing")) + + cfg, err := getDockerConfig() + require.Error(t, err) + require.Empty(t, cfg) + }) + + t.Run("with DOCKER_CONFIG env var", func(t *testing.T) { + t.Setenv("DOCKER_CONFIG", testDockerConfigDirPath) + + cfg, err := getDockerConfig() + require.NoError(t, err) + require.NotEmpty(t, cfg) + + assert.Len(t, cfg.AuthConfigs, 3) + + authCfgs := cfg.AuthConfigs + + if _, ok := authCfgs[indexDockerIO]; !ok { + t.Errorf(expectedErrorMessage, indexDockerIO) + } + if _, ok := authCfgs["https://example.com"]; !ok { + t.Errorf(expectedErrorMessage, "https://example.com") + } + if _, ok := authCfgs["https://my.private.registry"]; !ok { + t.Errorf(expectedErrorMessage, "https://my.private.registry") + } + }) + + t.Run("DOCKER_AUTH_CONFIG env var takes precedence", func(t *testing.T) { + t.Setenv("DOCKER_AUTH_CONFIG", `{ + "auths": { + "`+exampleAuth+`": {} + }, + "credsStore": "desktop" + }`) + t.Setenv("DOCKER_CONFIG", testDockerConfigDirPath) + + cfg, err := getDockerConfig() + require.NoError(t, err) + require.NotEmpty(t, cfg) + + assert.Len(t, cfg.AuthConfigs, 1) + + authCfgs := cfg.AuthConfigs + + if _, ok := authCfgs[indexDockerIO]; ok { + t.Errorf("Not expected to find %s in auth configs", indexDockerIO) + } + if _, ok := authCfgs[exampleAuth]; !ok { + t.Errorf(expectedErrorMessage, exampleAuth) + } + }) + + t.Run("retrieve auth with DOCKER_AUTH_CONFIG env var", func(t *testing.T) { + base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret + + t.Setenv("DOCKER_AUTH_CONFIG", `{ + "auths": { + "`+exampleAuth+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } + }, + "credsStore": "desktop" + }`) + + registry, cfg, err := DockerImageAuth(context.Background(), exampleAuth+"/my/image:latest") + require.NoError(t, err) + require.NotEmpty(t, cfg) + + assert.Equal(t, exampleAuth, registry) + assert.Equal(t, "gopher", cfg.Username) + assert.Equal(t, "secret", cfg.Password) + assert.Equal(t, base64, cfg.Auth) + }) + + t.Run("match registry authentication by host", func(t *testing.T) { + base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret + imageReg := "example-auth.com" + imagePath := "/my/image:latest" + + t.Setenv("DOCKER_AUTH_CONFIG", `{ + "auths": { + "`+exampleAuth+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } + }, + "credsStore": "desktop" + }`) + + registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath) + require.NoError(t, err) + require.NotEmpty(t, cfg) + + assert.Equal(t, imageReg, registry) + assert.Equal(t, "gopher", cfg.Username) + assert.Equal(t, "secret", cfg.Password) + assert.Equal(t, base64, cfg.Auth) + }) + + t.Run("fail to match registry authentication due to invalid host", func(t *testing.T) { + base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret + imageReg := "example-auth.com" + imagePath := "/my/image:latest" + invalidRegistryURL := "://invalid-host" + + t.Setenv("DOCKER_AUTH_CONFIG", `{ + "auths": { + "`+invalidRegistryURL+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } + }, + "credsStore": "desktop" + }`) + + registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath) + require.Equal(t, err, dockercfg.ErrCredentialsNotFound) + require.Empty(t, cfg) + + assert.Equal(t, imageReg, registry) + }) +} diff --git a/docker_auth_test.go b/docker_auth_test.go index 514cf753c7..8a5d469d24 100644 --- a/docker_auth_test.go +++ b/docker_auth_test.go @@ -1,169 +1,23 @@ -package testcontainers +package testcontainers_test import ( "context" "fmt" "os" - "path/filepath" "testing" - "github.com/cpuguy83/dockercfg" "github.com/docker/docker/api/types" "github.com/docker/docker/client" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go/internal/core" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) -const exampleAuth = "https://example-auth.com" - -var testDockerConfigDirPath = filepath.Join("testdata", ".docker") - -var indexDockerIO = core.IndexDockerIO - -func TestGetDockerConfig(t *testing.T) { - const expectedErrorMessage = "Expected to find %s in auth configs" - - // Verify that the default docker config file exists before any test in this suite runs. - // Then, we can safely run the tests that rely on it. - defaultCfg, err := dockercfg.LoadDefaultConfig() - require.NoError(t, err) - require.NotEmpty(t, defaultCfg) - - t.Run("without DOCKER_CONFIG env var retrieves default", func(t *testing.T) { - t.Setenv("DOCKER_CONFIG", "") - - cfg, err := getDockerConfig() - require.NoError(t, err) - require.NotEmpty(t, cfg) - - assert.Equal(t, defaultCfg, cfg) - }) - - t.Run("with DOCKER_CONFIG env var pointing to a non-existing file raises error", func(t *testing.T) { - t.Setenv("DOCKER_CONFIG", filepath.Join(testDockerConfigDirPath, "non-existing")) - - cfg, err := getDockerConfig() - require.Error(t, err) - require.Empty(t, cfg) - }) - - t.Run("with DOCKER_CONFIG env var", func(t *testing.T) { - t.Setenv("DOCKER_CONFIG", testDockerConfigDirPath) - - cfg, err := getDockerConfig() - require.NoError(t, err) - require.NotEmpty(t, cfg) - - assert.Len(t, cfg.AuthConfigs, 3) - - authCfgs := cfg.AuthConfigs - - if _, ok := authCfgs[indexDockerIO]; !ok { - t.Errorf(expectedErrorMessage, indexDockerIO) - } - if _, ok := authCfgs["https://example.com"]; !ok { - t.Errorf(expectedErrorMessage, "https://example.com") - } - if _, ok := authCfgs["https://my.private.registry"]; !ok { - t.Errorf(expectedErrorMessage, "https://my.private.registry") - } - }) - - t.Run("DOCKER_AUTH_CONFIG env var takes precedence", func(t *testing.T) { - t.Setenv("DOCKER_AUTH_CONFIG", `{ - "auths": { - "`+exampleAuth+`": {} - }, - "credsStore": "desktop" - }`) - t.Setenv("DOCKER_CONFIG", testDockerConfigDirPath) - - cfg, err := getDockerConfig() - require.NoError(t, err) - require.NotEmpty(t, cfg) - - assert.Len(t, cfg.AuthConfigs, 1) - - authCfgs := cfg.AuthConfigs - - if _, ok := authCfgs[indexDockerIO]; ok { - t.Errorf("Not expected to find %s in auth configs", indexDockerIO) - } - if _, ok := authCfgs[exampleAuth]; !ok { - t.Errorf(expectedErrorMessage, exampleAuth) - } - }) - - t.Run("retrieve auth with DOCKER_AUTH_CONFIG env var", func(t *testing.T) { - base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret - - t.Setenv("DOCKER_AUTH_CONFIG", `{ - "auths": { - "`+exampleAuth+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } - }, - "credsStore": "desktop" - }`) - - registry, cfg, err := DockerImageAuth(context.Background(), exampleAuth+"/my/image:latest") - require.NoError(t, err) - require.NotEmpty(t, cfg) - - assert.Equal(t, exampleAuth, registry) - assert.Equal(t, "gopher", cfg.Username) - assert.Equal(t, "secret", cfg.Password) - assert.Equal(t, base64, cfg.Auth) - }) - - t.Run("match registry authentication by host", func(t *testing.T) { - base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret - imageReg := "example-auth.com" - imagePath := "/my/image:latest" - - t.Setenv("DOCKER_AUTH_CONFIG", `{ - "auths": { - "`+exampleAuth+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } - }, - "credsStore": "desktop" - }`) - - registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath) - require.NoError(t, err) - require.NotEmpty(t, cfg) - - assert.Equal(t, imageReg, registry) - assert.Equal(t, "gopher", cfg.Username) - assert.Equal(t, "secret", cfg.Password) - assert.Equal(t, base64, cfg.Auth) - }) - - t.Run("fail to match registry authentication due to invalid host", func(t *testing.T) { - base64 := "Z29waGVyOnNlY3JldA==" // gopher:secret - imageReg := "example-auth.com" - imagePath := "/my/image:latest" - invalidRegistryURL := "://invalid-host" - - t.Setenv("DOCKER_AUTH_CONFIG", `{ - "auths": { - "`+invalidRegistryURL+`": { "username": "gopher", "password": "secret", "auth": "`+base64+`" } - }, - "credsStore": "desktop" - }`) - - registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath) - require.Equal(t, err, dockercfg.ErrCredentialsNotFound) - require.Empty(t, cfg) - - assert.Equal(t, imageReg, registry) - }) -} - func TestBuildContainerFromDockerfile(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ - FromDockerfile: FromDockerfile{ + req := testcontainers.ContainerRequest{ + FromDockerfile: testcontainers.FromDockerfile{ Context: "./testdata", }, AlwaysPullImage: true, // make sure the authentication takes place @@ -180,7 +34,7 @@ func TestBuildContainerFromDockerfile(t *testing.T) { func removeImageFromLocalCache(t *testing.T, image string) { ctx := context.Background() - testcontainersClient, err := NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion)) + testcontainersClient, err := testcontainers.NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion)) if err != nil { t.Log("could not create client to cleanup registry: ", err) } @@ -209,8 +63,8 @@ func TestBuildContainerFromDockerfileWithDockerAuthConfig(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ - FromDockerfile: FromDockerfile{ + req := testcontainers.ContainerRequest{ + FromDockerfile: testcontainers.FromDockerfile{ Context: "./testdata", Dockerfile: "auth.Dockerfile", }, @@ -238,8 +92,8 @@ func TestBuildContainerFromDockerfileShouldFailWithWrongDockerAuthConfig(t *test ctx := context.Background() - req := ContainerRequest{ - FromDockerfile: FromDockerfile{ + req := testcontainers.ContainerRequest{ + FromDockerfile: testcontainers.FromDockerfile{ Context: "./testdata", Dockerfile: "auth.Dockerfile", }, @@ -266,14 +120,14 @@ func TestCreateContainerFromPrivateRegistry(t *testing.T) { prepareLocalRegistryWithAuth(t) ctx := context.Background() - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: "localhost:5001/redis:5.0-alpine", AlwaysPullImage: true, // make sure the authentication takes place ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("Ready to accept connections"), } - redisContainer, err := GenericContainer(ctx, GenericContainerRequest{ + redisContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: req, Started: true, }) @@ -286,7 +140,7 @@ func prepareLocalRegistryWithAuth(t *testing.T) { wd, err := os.Getwd() require.NoError(t, err) // copyDirectoryToContainer { - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: "registry:2", ExposedPorts: []string{"5001:5000/tcp"}, Env: map[string]string{ @@ -295,7 +149,7 @@ func prepareLocalRegistryWithAuth(t *testing.T) { "REGISTRY_AUTH_HTPASSWD_PATH": "/auth/htpasswd", "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY": "/data", }, - Files: []ContainerFile{ + Files: []testcontainers.ContainerFile{ { HostFilePath: fmt.Sprintf("%s/testdata/auth", wd), ContainerFilePath: "/auth", @@ -309,13 +163,13 @@ func prepareLocalRegistryWithAuth(t *testing.T) { } // } - genContainerReq := GenericContainerRequest{ + genContainerReq := testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, } - registryC, err := GenericContainer(ctx, genContainerReq) + registryC, err := testcontainers.GenericContainer(ctx, genContainerReq) require.NoError(t, err) t.Cleanup(func() { @@ -329,14 +183,14 @@ func prepareLocalRegistryWithAuth(t *testing.T) { t.Cleanup(cancel) } -func prepareRedisImage(ctx context.Context, req ContainerRequest, t *testing.T) (Container, error) { - genContainerReq := GenericContainerRequest{ +func prepareRedisImage(ctx context.Context, req testcontainers.ContainerRequest, t *testing.T) (testcontainers.Container, error) { + genContainerReq := testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, } - redisC, err := GenericContainer(ctx, genContainerReq) + redisC, err := testcontainers.GenericContainer(ctx, genContainerReq) return redisC, err } diff --git a/docker_client_test.go b/docker_client_test.go index 4b582493bb..d96a031ddb 100644 --- a/docker_client_test.go +++ b/docker_client_test.go @@ -1,4 +1,4 @@ -package testcontainers +package testcontainers_test import ( "context" @@ -6,12 +6,14 @@ import ( "testing" "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go" ) func TestGetDockerInfo(t *testing.T) { t.Run("works", func(t *testing.T) { ctx := context.Background() - c, err := NewDockerClientWithOpts(ctx) + c, err := testcontainers.NewDockerClientWithOpts(ctx) require.NoError(t, err) info, err := c.Info(ctx) @@ -21,7 +23,7 @@ func TestGetDockerInfo(t *testing.T) { t.Run("is goroutine safe", func(t *testing.T) { ctx := context.Background() - c, err := NewDockerClientWithOpts(ctx) + c, err := testcontainers.NewDockerClientWithOpts(ctx) require.NoError(t, err) count := 1024 diff --git a/docker_exec_test.go b/docker_exec_test.go index 7e1cd4bc2f..d2a9e615c9 100644 --- a/docker_exec_test.go +++ b/docker_exec_test.go @@ -1,4 +1,4 @@ -package testcontainers +package testcontainers_test import ( "context" @@ -8,16 +8,17 @@ import ( "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" tcexec "github.com/testcontainers/testcontainers-go/exec" ) func TestExecWithMultiplexedResponse(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: nginxAlpineImage, } - container, err := GenericContainer(ctx, GenericContainerRequest{ + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, @@ -74,11 +75,11 @@ func TestExecWithOptions(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: nginxAlpineImage, } - container, err := GenericContainer(ctx, GenericContainerRequest{ + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, @@ -108,11 +109,11 @@ func TestExecWithOptions(t *testing.T) { func TestExecWithMultiplexedStderrResponse(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: nginxAlpineImage, } - container, err := GenericContainer(ctx, GenericContainerRequest{ + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, @@ -136,11 +137,11 @@ func TestExecWithMultiplexedStderrResponse(t *testing.T) { func TestExecWithNonMultiplexedResponse(t *testing.T) { ctx := context.Background() - req := ContainerRequest{ + req := testcontainers.ContainerRequest{ Image: nginxAlpineImage, } - container, err := GenericContainer(ctx, GenericContainerRequest{ + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ProviderType: providerType, ContainerRequest: req, Started: true, diff --git a/docker_mounts.go b/docker_mounts.go index 4906a90692..aed3010361 100644 --- a/docker_mounts.go +++ b/docker_mounts.go @@ -81,6 +81,12 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions { return s.TmpfsOptions } +// PrepareMounts maps the given []ContainerMount to the corresponding +// []mount.Mount for further processing +func (m ContainerMounts) PrepareMounts() []mount.Mount { + return mapToDockerMounts(m) +} + // mapToDockerMounts maps the given []ContainerMount to the corresponding // []mount.Mount for further processing func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount { diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000000..40bf66e7da --- /dev/null +++ b/utils_test.go @@ -0,0 +1,41 @@ +package testcontainers_test + +import ( + "context" + "os" + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go" +) + +const ( + mysqlImage = "docker.io/mysql:8.0.36" + nginxDelayedImage = "docker.io/menedev/delayed-nginx:1.15.2" + nginxImage = "docker.io/nginx" + nginxAlpineImage = "docker.io/nginx:alpine" + nginxDefaultPort = "80/tcp" + nginxHighPort = "8080/tcp" + daemonMaxVersion = "1.41" +) + +var providerType = testcontainers.ProviderDocker + +func init() { + if strings.Contains(os.Getenv("DOCKER_HOST"), "podman.sock") { + providerType = testcontainers.ProviderPodman + } +} + +func terminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr testcontainers.Container) { + tb.Helper() + if ctr == nil { + return + } + tb.Cleanup(func() { + tb.Log("terminating container") + require.NoError(tb, ctr.Terminate(ctx)) + }) +} From 79f11ff8bba718e3a6f41d6a04b4972c04b5c144 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 28 Feb 2024 14:34:48 -0500 Subject: [PATCH 2/3] Revert changes to the `docker_mounts` file --- docker_mounts.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docker_mounts.go b/docker_mounts.go index aed3010361..4906a90692 100644 --- a/docker_mounts.go +++ b/docker_mounts.go @@ -81,12 +81,6 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions { return s.TmpfsOptions } -// PrepareMounts maps the given []ContainerMount to the corresponding -// []mount.Mount for further processing -func (m ContainerMounts) PrepareMounts() []mount.Mount { - return mapToDockerMounts(m) -} - // mapToDockerMounts maps the given []ContainerMount to the corresponding // []mount.Mount for further processing func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount { From 7810638e45039d989853fa6229f37887dbb807a6 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 4 Mar 2024 09:38:09 -0500 Subject: [PATCH 3/3] Remove utils and convert to the test helpers --- testhelpers_test.go | 20 ++++++++++++++++++++ utils_test.go | 41 ----------------------------------------- 2 files changed, 20 insertions(+), 41 deletions(-) delete mode 100644 utils_test.go diff --git a/testhelpers_test.go b/testhelpers_test.go index 480cf857a3..40bf66e7da 100644 --- a/testhelpers_test.go +++ b/testhelpers_test.go @@ -2,6 +2,8 @@ package testcontainers_test import ( "context" + "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -9,6 +11,24 @@ import ( "github.com/testcontainers/testcontainers-go" ) +const ( + mysqlImage = "docker.io/mysql:8.0.36" + nginxDelayedImage = "docker.io/menedev/delayed-nginx:1.15.2" + nginxImage = "docker.io/nginx" + nginxAlpineImage = "docker.io/nginx:alpine" + nginxDefaultPort = "80/tcp" + nginxHighPort = "8080/tcp" + daemonMaxVersion = "1.41" +) + +var providerType = testcontainers.ProviderDocker + +func init() { + if strings.Contains(os.Getenv("DOCKER_HOST"), "podman.sock") { + providerType = testcontainers.ProviderPodman + } +} + func terminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr testcontainers.Container) { tb.Helper() if ctr == nil { diff --git a/utils_test.go b/utils_test.go deleted file mode 100644 index 40bf66e7da..0000000000 --- a/utils_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package testcontainers_test - -import ( - "context" - "os" - "strings" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/testcontainers/testcontainers-go" -) - -const ( - mysqlImage = "docker.io/mysql:8.0.36" - nginxDelayedImage = "docker.io/menedev/delayed-nginx:1.15.2" - nginxImage = "docker.io/nginx" - nginxAlpineImage = "docker.io/nginx:alpine" - nginxDefaultPort = "80/tcp" - nginxHighPort = "8080/tcp" - daemonMaxVersion = "1.41" -) - -var providerType = testcontainers.ProviderDocker - -func init() { - if strings.Contains(os.Getenv("DOCKER_HOST"), "podman.sock") { - providerType = testcontainers.ProviderPodman - } -} - -func terminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr testcontainers.Container) { - tb.Helper() - if ctr == nil { - return - } - tb.Cleanup(func() { - tb.Log("terminating container") - require.NoError(tb, ctr.Terminate(ctx)) - }) -}