Skip to content

Commit e3611ba

Browse files
youshibinmdelapenyastevenh
authored
chore!: export DockerCompose type in compose package (testcontainers#2953)
* chore!: rename (deprecated) interface to prevent name collision BREAKING CHANGE: rename DockerCompose interface to DockerComposer to prevent a naming collision when exporting DockerCompose type * chore: rename DockerCompose to make it exported * docs: update message because of changing interface name * chore: use ComposeStack interface instead in unit test --------- Co-authored-by: Manuel de la Peña <[email protected]> Co-authored-by: Steven Hartland <[email protected]>
1 parent 1fd8d41 commit e3611ba

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

modules/compose/compose.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ type ComposeStack interface {
7878
ServiceContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error)
7979
}
8080

81-
// Deprecated: DockerCompose is the old shell escape based API
81+
// Deprecated: DockerComposer is the old shell escape based API
8282
// use ComposeStack instead
83-
// DockerCompose defines the contract for running Docker Compose
84-
type DockerCompose interface {
83+
// DockerComposer defines the contract for running Docker Compose
84+
type DockerComposer interface {
8585
Down() ExecError
8686
Invoke() ExecError
87-
WaitForService(string, wait.Strategy) DockerCompose
88-
WithCommand([]string) DockerCompose
89-
WithEnv(map[string]string) DockerCompose
90-
WithExposedService(string, int, wait.Strategy) DockerCompose
87+
WaitForService(string, wait.Strategy) DockerComposer
88+
WithCommand([]string) DockerComposer
89+
WithEnv(map[string]string) DockerComposer
90+
WithExposedService(string, int, wait.Strategy) DockerComposer
9191
}
9292

9393
type waitService struct {
@@ -123,11 +123,11 @@ func WithProfiles(profiles ...string) ComposeStackOption {
123123
return ComposeProfiles(profiles)
124124
}
125125

126-
func NewDockerCompose(filePaths ...string) (*dockerCompose, error) {
126+
func NewDockerCompose(filePaths ...string) (*DockerCompose, error) {
127127
return NewDockerComposeWith(WithStackFiles(filePaths...))
128128
}
129129

130-
func NewDockerComposeWith(opts ...ComposeStackOption) (*dockerCompose, error) {
130+
func NewDockerComposeWith(opts ...ComposeStackOption) (*DockerCompose, error) {
131131
composeOptions := composeStackOptions{
132132
Identifier: uuid.New().String(),
133133
temporaryPaths: make(map[string]bool),
@@ -162,7 +162,7 @@ func NewDockerComposeWith(opts ...ComposeStackOption) (*dockerCompose, error) {
162162
dockerClient := dockerCli.Client()
163163
provider.SetClient(dockerClient)
164164

165-
composeAPI := &dockerCompose{
165+
composeAPI := &DockerCompose{
166166
name: composeOptions.Identifier,
167167
configs: composeOptions.Paths,
168168
temporaryConfigs: composeOptions.temporaryPaths,
@@ -180,7 +180,7 @@ func NewDockerComposeWith(opts ...ComposeStackOption) (*dockerCompose, error) {
180180
return composeAPI, nil
181181
}
182182

183-
// Deprecated: NewLocalDockerCompose returns a DockerCompose compatible instance which is superseded
183+
// Deprecated: NewLocalDockerCompose returns a DockerComposer compatible instance which is superseded
184184
// by ComposeStack use NewDockerCompose instead to get a ComposeStack compatible instance
185185
//
186186
// NewLocalDockerCompose returns an instance of the local Docker Compose, using an

modules/compose/compose_api.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const (
180180
RemoveImagesLocal
181181
)
182182

183-
type dockerCompose struct {
183+
type DockerCompose struct {
184184
// used to synchronize operations
185185
lock sync.RWMutex
186186

@@ -235,21 +235,21 @@ type dockerCompose struct {
235235
provider *testcontainers.DockerProvider
236236
}
237237

238-
func (d *dockerCompose) ServiceContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error) {
238+
func (d *DockerCompose) ServiceContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error) {
239239
d.lock.Lock()
240240
defer d.lock.Unlock()
241241

242242
return d.lookupContainer(ctx, svcName)
243243
}
244244

245-
func (d *dockerCompose) Services() []string {
245+
func (d *DockerCompose) Services() []string {
246246
d.lock.Lock()
247247
defer d.lock.Unlock()
248248

249249
return d.project.ServiceNames()
250250
}
251251

252-
func (d *dockerCompose) Down(ctx context.Context, opts ...StackDownOption) error {
252+
func (d *DockerCompose) Down(ctx context.Context, opts ...StackDownOption) error {
253253
d.lock.Lock()
254254
defer d.lock.Unlock()
255255

@@ -271,7 +271,7 @@ func (d *dockerCompose) Down(ctx context.Context, opts ...StackDownOption) error
271271
return d.composeService.Down(ctx, d.name, options.DownOptions)
272272
}
273273

274-
func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err error) {
274+
func (d *DockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err error) {
275275
d.lock.Lock()
276276
defer d.lock.Unlock()
277277

@@ -436,23 +436,23 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) (err erro
436436
return nil
437437
}
438438

439-
func (d *dockerCompose) WaitForService(s string, strategy wait.Strategy) ComposeStack {
439+
func (d *DockerCompose) WaitForService(s string, strategy wait.Strategy) ComposeStack {
440440
d.lock.Lock()
441441
defer d.lock.Unlock()
442442

443443
d.waitStrategies[s] = strategy
444444
return d
445445
}
446446

447-
func (d *dockerCompose) WithEnv(m map[string]string) ComposeStack {
447+
func (d *DockerCompose) WithEnv(m map[string]string) ComposeStack {
448448
d.lock.Lock()
449449
defer d.lock.Unlock()
450450

451451
d.projectOptions = append(d.projectOptions, withEnv(m))
452452
return d
453453
}
454454

455-
func (d *dockerCompose) WithOsEnv() ComposeStack {
455+
func (d *DockerCompose) WithOsEnv() ComposeStack {
456456
d.lock.Lock()
457457
defer d.lock.Unlock()
458458

@@ -461,7 +461,7 @@ func (d *dockerCompose) WithOsEnv() ComposeStack {
461461
}
462462

463463
// cachedContainer returns the cached container for svcName or nil if it doesn't exist.
464-
func (d *dockerCompose) cachedContainer(svcName string) *testcontainers.DockerContainer {
464+
func (d *DockerCompose) cachedContainer(svcName string) *testcontainers.DockerContainer {
465465
d.containersLock.Lock()
466466
defer d.containersLock.Unlock()
467467

@@ -471,7 +471,7 @@ func (d *dockerCompose) cachedContainer(svcName string) *testcontainers.DockerCo
471471
// lookupContainer is used to retrieve the container instance from the cache or the Docker API.
472472
//
473473
// Safe for concurrent calls.
474-
func (d *dockerCompose) lookupContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error) {
474+
func (d *DockerCompose) lookupContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error) {
475475
if c := d.cachedContainer(svcName); c != nil {
476476
return c, nil
477477
}
@@ -506,7 +506,7 @@ func (d *dockerCompose) lookupContainer(ctx context.Context, svcName string) (*t
506506
// lookupNetworks is used to retrieve the networks that are part of the compose stack.
507507
//
508508
// Safe for concurrent calls.
509-
func (d *dockerCompose) lookupNetworks(ctx context.Context) error {
509+
func (d *DockerCompose) lookupNetworks(ctx context.Context) error {
510510
networks, err := d.dockerClient.NetworkList(ctx, dockernetwork.ListOptions{
511511
Filters: filters.NewArgs(
512512
filters.Arg("label", fmt.Sprintf("%s=%s", api.ProjectLabel, d.name)),
@@ -529,7 +529,7 @@ func (d *dockerCompose) lookupNetworks(ctx context.Context) error {
529529
return nil
530530
}
531531

532-
func (d *dockerCompose) compileProject(ctx context.Context) (*types.Project, error) {
532+
func (d *DockerCompose) compileProject(ctx context.Context) (*types.Project, error) {
533533
const nameAndDefaultConfigPath = 2
534534
projectOptions := make([]cli.ProjectOptionsFn, len(d.projectOptions), len(d.projectOptions)+nameAndDefaultConfigPath)
535535

modules/compose/compose_api_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ func TestDockerComposeAPIWithProfiles(t *testing.T) {
142142

143143
for name, test := range testcases {
144144
t.Run(name, func(t *testing.T) {
145+
var compose ComposeStack
145146
compose, err := NewDockerComposeWith(WithStackFiles(path), WithProfiles(test.withProfiles...))
146147
require.NoError(t, err, "NewDockerCompose()")
147148

148149
ctx, cancel := context.WithCancel(context.Background())
149150
t.Cleanup(cancel)
150151

151152
for _, service := range test.wantServices {
152-
compose = compose.WaitForService(service, wait.NewHTTPStrategy("/").WithPort("80/tcp").WithStartupTimeout(10*time.Second)).(*dockerCompose)
153+
compose = compose.WaitForService(service, wait.NewHTTPStrategy("/").WithPort("80/tcp").WithStartupTimeout(10*time.Second))
153154
}
154155
err = compose.Up(ctx, Wait(true))
155156
cleanup(t, compose)
@@ -695,7 +696,7 @@ func testNameHash(name string) StackIdentifier {
695696
}
696697

697698
// cleanup is a helper function that schedules the compose stack to be stopped when the test ends.
698-
func cleanup(t *testing.T, compose *dockerCompose) {
699+
func cleanup(t *testing.T, compose ComposeStack) {
699700
t.Helper()
700701
t.Cleanup(func() {
701702
require.NoError(t, compose.Down(

modules/compose/compose_local.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,30 @@ func (dc *LocalDockerCompose) Invoke() ExecError {
190190

191191
// Deprecated: it will be removed in the next major release
192192
// WaitForService sets the strategy for the service that is to be waited on
193-
func (dc *LocalDockerCompose) WaitForService(service string, strategy wait.Strategy) DockerCompose {
193+
func (dc *LocalDockerCompose) WaitForService(service string, strategy wait.Strategy) DockerComposer {
194194
dc.waitStrategySupplied = true
195195
dc.WaitStrategyMap[waitService{service: service}] = strategy
196196
return dc
197197
}
198198

199199
// Deprecated: it will be removed in the next major release
200200
// WithCommand assigns the command
201-
func (dc *LocalDockerCompose) WithCommand(cmd []string) DockerCompose {
201+
func (dc *LocalDockerCompose) WithCommand(cmd []string) DockerComposer {
202202
dc.Cmd = cmd
203203
return dc
204204
}
205205

206206
// Deprecated: it will be removed in the next major release
207207
// WithEnv assigns the environment
208-
func (dc *LocalDockerCompose) WithEnv(env map[string]string) DockerCompose {
208+
func (dc *LocalDockerCompose) WithEnv(env map[string]string) DockerComposer {
209209
dc.Env = env
210210
return dc
211211
}
212212

213213
// Deprecated: it will be removed in the next major release
214214
// WithExposedService sets the strategy for the service that is to be waited on. If multiple strategies
215215
// are given for a single service running on different ports, both strategies will be applied on the same container
216-
func (dc *LocalDockerCompose) WithExposedService(service string, port int, strategy wait.Strategy) DockerCompose {
216+
func (dc *LocalDockerCompose) WithExposedService(service string, port int, strategy wait.Strategy) DockerComposer {
217217
dc.waitStrategySupplied = true
218218
dc.WaitStrategyMap[waitService{service: service, publishedPort: port}] = strategy
219219
return dc

0 commit comments

Comments
 (0)