-
-
Notifications
You must be signed in to change notification settings - Fork 580
chore!: export DockerCompose type in compose package #2953
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
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify why this doesn't work already, as a quick test seems to indicate it does?
func TestHelloWorld(t *testing.T) {
compose, err := compose.NewDockerCompose("test")
require.NoError(t, err)
err = compose.Down(context.Background())
require.NoError(t, err)
}
@stevenh Yep, you are absolutely right! The type doesn't need to be exported for the methods which are exported to be accessible outside of the package. |
So we can close this and the associated issue? |
I think the documentation should clarify or emphasise the necessity to use the |
@xbc5 I agree, it's a bit confusing, but I believe the reason for the different interface name ( Where would you like to see documentation updated? |
Inline, on the Also, this is the first place I looked to get acquainted with the factory: so perhaps there too? Again, not necessary if it returns the interface. Thanks for doing this. |
Sorry I think you miss-understood my comment in the issue, I meant we should update the reason for the fix of exporting the returned type to detail that returning an unexported type restricts it's use, as it means it cannot be stored in a type or passed as a variable to a function, for example neither of the following are possible type MyType struct {
Stack *dockerCompose
}
func MyFunc(stack *dockerCompose) {
....
} You should always return types and accept interfaces. For info on why see this. |
@stevenh appreciate the review and sharing your wisdom! Great reference you linked there with returning types and accepting interfaces! I went back to the original implementation, which exports the There was a I don't suppose adding an interface implementation check (or interface compliance assertion) would be useful here to drive home the fact that the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One clarifying question.
Due to the breaking change the PR title also needs a ! adding to it and "BREAKING CHANGE" to the description see conventional commits.
BREAKING CHANGE: rename DockerCompose interface to DockerComposer to prevent a naming collision when exporting DockerCompose type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @jasonyunicorn for your work here 🙇
Waiting for a final +1 from @stevenh to merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…er-28.0.1incompatible * main: chore!: export DockerCompose type in compose package (#2953) chore(deps): bump golang.org/x/net from 0.33.0 to 0.36.0 in /modules (#3033) chore(sonar): set main as default branch (#3038) fix(sonar): run on ubuntu and the lowest Go version (#3037) fix(ci): update core path in sonar build (#3036) fix: use empty dir for the core (#3035) fix: pass secret to the reusable workflow (#3034) chore(ci): use new GH action for SonarQube (#3007)
* main: chore!: export DockerCompose type in compose package (testcontainers#2953) chore(deps): bump golang.org/x/net from 0.33.0 to 0.36.0 in /modules (testcontainers#3033)
* main: chore(deps)!: bump github.com/docker/docker from 27.1.1+incompatible to 28.0.1+incompatible (testcontainers#3017) chore!: export DockerCompose type in compose package (testcontainers#2953) chore(deps): bump golang.org/x/net from 0.33.0 to 0.36.0 in /modules (testcontainers#3033) chore(sonar): set main as default branch (testcontainers#3038) fix(sonar): run on ubuntu and the lowest Go version (testcontainers#3037) fix(ci): update core path in sonar build (testcontainers#3036) fix: use empty dir for the core (testcontainers#3035) fix: pass secret to the reusable workflow (testcontainers#3034) chore(ci): use new GH action for SonarQube (testcontainers#3007)
What does this PR do?
Exports the
DockerCompose
type in the compose packge.BREAKING CHANGE: The DockerCompose interface, used for the LocalDockerCompose implementation (shelling out to the local binary), was renamed to DockerComposer to prevent a
naming collision when exporting DockerCompose type.
Why is it important?
Returning an un-exported type from a constructor function limits the flexibility and usability of the returned instance. Callers can use the exported methods, but cannot declare variables of that type, pass instances to other functions, or embed them in structs without exposing the constructor itself.
Related issues