Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove most uses of TestcontainersConfig and deprecated TestcontainersConfig fields. #2614

Merged
merged 6 commits into from
Jul 2, 2024

Conversation

thaJeztah
Copy link
Contributor

What does this PR do?

remove TestProviderHasConfig as it wasn't testing anything

This test was verifying that DockerProvider.Config() returned a
non-nil value, but Config() does not return a pointer, so it
would always pass (even with an empty struct).

TestContainerLogWithErrClosed: rename variable that shadowed import

NewDockerProvider: inline intermediate variables

modules/compose: NewDockerComposeWith: don't use deprecated RyukDisabled

The TestcontainersConfig.RyukDisabled field is deprecated.
NewDockerProvider() uses ReadConfig() internally to load the config,
which always copies its value from config.Config.RyukDisabled field,
which is not deprecated.

This patch removes the extra redirection, and changes the code to
use Config.RyukDisabled instead.

DockerProvider: don't use legacy TestcontainersConfig internally

All fields in TestcontainersConfig are deprecated, making it a
wrapper around config.Config and DockerProvider internally only
depends on config.Config. All deprecated fields contain a copy
of values available in config.Config.

However, the exported Config() has TestcontainersConfig as return type;
filling the deprecated fields is is currently handled by ReadConfig, but
straightforward, so we can inline that code in the Config() method.

This patch:

  • changes the (non-exported) config field to hold a config.Config (which
    provides all the data used).
  • removes internal uses of the Config() method; the Config() method
    did not provide value for internal use; the config field is not mutated
    (so no synchronisation needed for concurrency).
  • updates the Config() method to handle conversion of the config.Config
    to a TestcontainersConfig (effectively inlining a copy of ReadConfig)

After this patch, the only remaining use of ReadConfig in testcontainers-go
itself is in tests (TestReadConfig); as a follow-up, we can consider
deprecating ReadConfig and TestcontainersConfig, although DockerProvider
may need a new Config() method with a different signature if its config
must be accessible for others, which would require the ContainerProvider
and ReaperProvider interfaces to be updated.

Why is it important?

Remove uses of deprecated fields to make it easier to spot where it's still used.

Follow-ups

consider deprecating ReadConfig and TestcontainersConfig, although DockerProvider
may need a new Config() method with a different signature if its config
must be accessible for others, which would require the ContainerProvider
and ReaperProvider interfaces to be updated.

This test was verifying that DockerProvider.Config() returned a
non-nil value, but Config() does not return a pointer, so it
would always pass (even with an empty struct).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The TestcontainersConfig.RyukDisabled field is deprecated.
NewDockerProvider() uses ReadConfig() internally to load the config,
which always copies its value from config.Config.RyukDisabled field,
which is not deprecated.

This patch removes the extra redirection, and changes the code to
use Config.RyukDisabled instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
All fields in TestcontainersConfig are deprecated, making it a
wrapper around config.Config and DockerProvider internally only
depends on config.Config. All deprecated fields contain a copy
of values available in config.Config.

However, the exported `Config()` has TestcontainersConfig as return type;
filling the deprecated fields is is currently handled by ReadConfig, but
straightforward, so we can inline that code in the `Config()` method.

This patch:

- changes the (non-exported) config field to hold a config.Config (which
  provides all the data used).
- removes internal uses of the `Config()` method; the `Config()` method
  did not provide value for internal use; the `config` field is not mutated
  (so no synchronisation needed for concurrency).
- updates the `Config()` method to handle conversion of the config.Config
  to a `TestcontainersConfig` (effectively inlining a copy of `ReadConfig`)

After this patch, the only remaining use of `ReadConfig` in testcontainers-go
itself is in tests (`TestReadConfig`); as a follow-up, we can consider
deprecating `ReadConfig` and `TestcontainersConfig`, although `DockerProvider`
may need a new `Config()` method with a different signature if its config
must be accessible for others, which would require the `ContainerProvider`
and `ReaperProvider` interfaces to be updated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah requested a review from a team as a code owner June 29, 2024 10:11
Copy link

netlify bot commented Jun 29, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit b4af24f
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6683d3b662908c00088025b2
😎 Deploy Preview https://deploy-preview-2614--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdelapenya mdelapenya self-assigned this Jul 2, 2024
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Jul 2, 2024
@mdelapenya mdelapenya merged commit 79d8da1 into testcontainers:main Jul 2, 2024
108 checks passed
mdelapenya added a commit that referenced this pull request Jul 2, 2024
* main:
  fix: never cache JSON representation of a container (#2606)
  chore: remove most uses of  TestcontainersConfig and deprecated TestcontainersConfig fields. (#2614)
  chore(deps): bump github.com/docker/docker from v27.0.2 to v27.0.3 (#2615)
  chore(deps): bump github.com/docker/docker from v26.1.4 to v27.0.2 (#2593)
@thaJeztah thaJeztah deleted the cleanup_legacy_config branch July 2, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants