From 80b45a182724d3557d16ad4c376ad26b0c61723f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Thu, 20 Mar 2025 19:22:44 +0000 Subject: [PATCH] refactor!: delete deprecated `TestcontainersConfig` struct --- config.go | 29 ----------------------------- docker.go | 11 ++--------- modules/compose/compose_api.go | 2 +- options.go | 5 +++-- provider.go | 2 +- reaper.go | 4 ++-- reaper_test.go | 8 +++----- 7 files changed, 12 insertions(+), 49 deletions(-) delete mode 100644 config.go diff --git a/config.go b/config.go deleted file mode 100644 index 91a333107d..0000000000 --- a/config.go +++ /dev/null @@ -1,29 +0,0 @@ -package testcontainers - -import ( - "github.com/testcontainers/testcontainers-go/internal/config" -) - -// TestcontainersConfig represents the configuration for Testcontainers -type TestcontainersConfig struct { - Host string `properties:"docker.host,default="` // Deprecated: use Config.Host instead - TLSVerify int `properties:"docker.tls.verify,default=0"` // Deprecated: use Config.TLSVerify instead - CertPath string `properties:"docker.cert.path,default="` // Deprecated: use Config.CertPath instead - RyukDisabled bool `properties:"ryuk.disabled,default=false"` // Deprecated: use Config.RyukDisabled instead - RyukPrivileged bool `properties:"ryuk.container.privileged,default=false"` // Deprecated: use Config.RyukPrivileged instead - Config config.Config -} - -// ReadConfig reads from testcontainers properties file, storing the result in a singleton instance -// of the TestcontainersConfig struct -func ReadConfig() TestcontainersConfig { - cfg := config.Read() - return TestcontainersConfig{ - Host: cfg.Host, - TLSVerify: cfg.TLSVerify, - CertPath: cfg.CertPath, - RyukDisabled: cfg.RyukDisabled, - RyukPrivileged: cfg.RyukPrivileged, - Config: cfg, - } -} diff --git a/docker.go b/docker.go index e20026c387..b5278afa25 100644 --- a/docker.go +++ b/docker.go @@ -1493,15 +1493,8 @@ func (p *DockerProvider) RunContainer(ctx context.Context, req ContainerRequest) // Config provides the TestcontainersConfig read from $HOME/.testcontainers.properties or // the environment variables -func (p *DockerProvider) Config() TestcontainersConfig { - return TestcontainersConfig{ - Host: p.config.Host, - TLSVerify: p.config.TLSVerify, - CertPath: p.config.CertPath, - RyukDisabled: p.config.RyukDisabled, - RyukPrivileged: p.config.RyukPrivileged, - Config: p.config, - } +func (p *DockerProvider) Config() config.Config { + return p.config } // DaemonHost gets the host or ip of the Docker daemon where ports are exposed on diff --git a/modules/compose/compose_api.go b/modules/compose/compose_api.go index 56f6795cee..f4acd7dd87 100644 --- a/modules/compose/compose_api.go +++ b/modules/compose/compose_api.go @@ -331,7 +331,7 @@ func (d *DockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro var termSignals []chan bool var reaper *testcontainers.Reaper - if !d.provider.Config().Config.RyukDisabled { + if !d.provider.Config().RyukDisabled { // NewReaper is deprecated: we need to find a way to create the reaper for compose // bypassing the deprecation. reaper, err = testcontainers.NewReaper(ctx, testcontainers.SessionID(), d.provider, "") diff --git a/options.go b/options.go index a930c54104..e2fd86f795 100644 --- a/options.go +++ b/options.go @@ -13,6 +13,7 @@ import ( "github.com/docker/docker/api/types/network" tcexec "github.com/testcontainers/testcontainers-go/exec" + "github.com/testcontainers/testcontainers-go/internal/config" "github.com/testcontainers/testcontainers-go/internal/core" "github.com/testcontainers/testcontainers-go/wait" ) @@ -182,12 +183,12 @@ func (c CustomHubSubstitutor) Description() string { // - if the HubImageNamePrefix configuration value is set, the image is returned as is. func (c CustomHubSubstitutor) Substitute(image string) (string, error) { registry := core.ExtractRegistry(image, "") - cfg := ReadConfig() + cfg := config.Read() exclusions := []func() bool{ func() bool { return c.hub == "" }, func() bool { return registry != "" }, - func() bool { return cfg.Config.HubImageNamePrefix != "" }, + func() bool { return cfg.HubImageNamePrefix != "" }, } for _, exclusion := range exclusions { diff --git a/provider.go b/provider.go index d2347b7f3b..7cb0f61647 100644 --- a/provider.go +++ b/provider.go @@ -91,7 +91,7 @@ type ContainerProvider interface { ReuseOrCreateContainer(context.Context, ContainerRequest) (Container, error) // reuses a container if it exists or creates a container without starting RunContainer(context.Context, ContainerRequest) (Container, error) // create a container and start it Health(context.Context) error - Config() TestcontainersConfig + Config() config.Config } // GetProvider provides the provider implementation for a certain type diff --git a/reaper.go b/reaper.go index 4e46f0e381..09d00a1676 100644 --- a/reaper.go +++ b/reaper.go @@ -61,7 +61,7 @@ var ( // The ContainerProvider interface should usually satisfy this as well, so it is pluggable type ReaperProvider interface { RunContainer(ctx context.Context, req ContainerRequest) (Container, error) - Config() TestcontainersConfig + Config() config.Config } // NewReaper creates a Reaper with a sessionID to identify containers and a provider to use @@ -377,7 +377,7 @@ func (r *reaperSpawner) newReaper(ctx context.Context, sessionID string, provide dockerHostMount := core.MustExtractDockerSocket(ctx) port := r.port() - tcConfig := provider.Config().Config + tcConfig := provider.Config() req := ContainerRequest{ Image: config.ReaperDefaultImage, ExposedPorts: []string{string(port)}, diff --git a/reaper_test.go b/reaper_test.go index 59c780fa3e..b553ebb643 100644 --- a/reaper_test.go +++ b/reaper_test.go @@ -27,14 +27,12 @@ type mockReaperProvider struct { req ContainerRequest hostConfig *container.HostConfig endpointSettings map[string]*network.EndpointSettings - config TestcontainersConfig + config config.Config } func newMockReaperProvider(cfg config.Config) *mockReaperProvider { m := &mockReaperProvider{ - config: TestcontainersConfig{ - Config: cfg, - }, + config: cfg, } return m @@ -62,7 +60,7 @@ func (m *mockReaperProvider) RunContainer(_ context.Context, req ContainerReques return nil, errExpected } -func (m *mockReaperProvider) Config() TestcontainersConfig { +func (m *mockReaperProvider) Config() config.Config { return m.config }