-
-
Notifications
You must be signed in to change notification settings - Fork 522
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!: export DockerCompose type in compose package #2953
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
2819e47
to
5e8663b
Compare
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? |
5e8663b
to
9f7a5ca
Compare
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. |
9f7a5ca
to
fe9bac3
Compare
@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.
@@ -141,14 +141,15 @@ func TestDockerComposeAPIWithProfiles(t *testing.T) { | |||
|
|||
for name, test := range testcases { | |||
t.Run(name, func(t *testing.T) { | |||
var compose ComposeStack |
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.
question: is this and the change to cleanup needed?
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.
No, neither of those commits / changes are absolutely necessary, but I though it was a great place to practice the "accept interfaces" recommendation in the blog which you referenced.
I'm happy to remove / revert the changes / commits though.
In that case, we may want to consider adding the interface implementation check which I recommended. Otherwise, I could see future changes on the ComposeStack
interface breaking the condition that DockerCompose
satisfies said interface.
BREAKING CHANGE: rename DockerCompose interface to DockerComposer to prevent a naming collision when exporting DockerCompose type
b8a4af3
to
104a311
Compare
What does this PR do?
Exports the
DockerCompose
type in the compose packge.BREAKING CHANGE: The DockerCompose interface 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