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

feat: prepare modules for the new API #2610

Merged

Conversation

mdelapenya
Copy link
Collaborator

  • feat: define new API for modules using Run
  • chore: update module generator
  • docs: update module generation
  • fixup: modulegen
  • docs: update module pages

What does this PR do?

This PR updates all the modules, the module generator and the current docs to use the new API:

  • deprecates RunContainer in favor of Run
  • the Run function needs the Docker image as second argument, which forces users to know which image is used in their tests.
  • updates the Go templates to generate new modules following this new API

Why is it important?

Prepare for a more consistent API that makes evident which image is used.

Follow-ups

Modules catalog examples will need to be udpated in consequence.

@mdelapenya mdelapenya requested a review from a team as a code owner June 27, 2024 12:40
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Jun 27, 2024
@mdelapenya mdelapenya self-assigned this Jun 27, 2024
Copy link

netlify bot commented Jun 27, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 88ced06
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6683d0915ccfd00008efb377
😎 Deploy Preview https://deploy-preview-2610--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.


```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error)
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error)
Copy link
Contributor

@thaJeztah thaJeztah Jul 2, 2024

Choose a reason for hiding this comment

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

Silly thought / wild thought / thinking out loud; as this is changing the interface;

docker run is a combination of steps;

  1. create container
    • if image is missing, pull the image (depending on pull settings)
    • once image is pulled;
    • create container again
  2. start container
  3. attach to the container (if in foreground)

Specifically, the "image is missing" (and what to do in that case) is something that could be relevant for testing;

  • Do you want the image to be pulled?
  • Perhaps you want the image to be loaded (offline tar of images)
  • Perhaps even need the image to be built

Wondering if the img string should be / could be a functional argument that allows controlling this (in future);

  • PullImageIfMissing("foo:latest")
  • LoadImageIfMissing("foo:latest", "/path/to/tar")
  • ...

We probably don't need all of those implemented, but it would allow for those to be expanded on 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Before this change, we have (deprecated in this PR) a testcontainers.WithImage functional opt, that could leverage what you propose. We already have support for loading images from tar files, and the code will automatically pull the image if missing. So I'd see the second use case as a nice addition.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we have to be that considerate for this change at hand (where we want to be pragmatic and move forward to allow support for Official Modules in tc-go soon), but it is for sure something to consider more for the v1 release of tc-go.

tc-java essentially provides support for such an abstraction, in practice mostly realized through a Future<String> parameter. However, the resulting API needs to be on a higher abstraction level, so that it encapsulates pulling, building or loading images.

Copy link
Collaborator Author

@mdelapenya mdelapenya Jul 2, 2024

Choose a reason for hiding this comment

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

we want to be pragmatic and move forward

Indeed. My comment for the niceness is for follow-ups, not for this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm merging this, taking your ideas as follow-ups. Thanks all for the discussion here

@mdelapenya mdelapenya merged commit 8e4728b into testcontainers:main Jul 4, 2024
108 checks passed
mdelapenya added a commit that referenced this pull request Jul 4, 2024
* main:
  feat: prepare modules for the new API (#2610)
@Glup3
Copy link

Glup3 commented Jul 4, 2024

will the package also be updated soon? related to #2625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants