Skip to content

Commit

Permalink
refactor: apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
prskr committed Jul 12, 2022
1 parent 20affdd commit 009b4b7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions compose.go
Expand Up @@ -63,7 +63,7 @@ type waitService struct {
publishedPort int
}

func NewDockerComposeApi(filePaths []string, identifier string) (*dockerComposeAPI, error) {
func NewDockerComposeAPI(filePaths []string, identifier string) (*dockerComposeAPI, error) {
dockerCli, err := command.NewDockerCli()
if err != nil {
return nil, err
Expand Down Expand Up @@ -96,7 +96,7 @@ func NewDockerComposeApi(filePaths []string, identifier string) (*dockerComposeA
// running Compose services.
//
// Deprecated: NewLocalDockerCompose returns a DockerCompose compatible instance which is superseded
// by ComposeStack use NewDockerComposeApi instead to get a ComposeStack compatible instance
// by ComposeStack use NewDockerComposeAPI instead to get a ComposeStack compatible instance
func NewLocalDockerCompose(filePaths []string, identifier string, opts ...LocalDockerComposeOption) *LocalDockerCompose {
dc := &LocalDockerCompose{
LocalDockerComposeOptions: &LocalDockerComposeOptions{
Expand Down
12 changes: 6 additions & 6 deletions compose_api.go
Expand Up @@ -156,22 +156,22 @@ func (d *dockerComposeAPI) Up(ctx context.Context, opts ...StackUpOption) (err e
return err
}

grp, grpCtx := errgroup.WithContext(ctx)
errGrp, errGrpCtx := errgroup.WithContext(ctx)

for svc, strategy := range d.waitStrategies { // pinning the variables
svc := svc
strategy := strategy

grp.Go(func() error {
target, err := d.ServiceContainer(grpCtx, svc)
errGrp.Go(func() error {
target, err := d.ServiceContainer(errGrpCtx, svc)
if err != nil {
return err
}
return strategy.WaitUntilReady(grpCtx, target)
return strategy.WaitUntilReady(errGrpCtx, target)
})
}

return grp.Wait()
return errGrp.Wait()
}

func (d *dockerComposeAPI) WaitForService(s string, strategy wait.Strategy) ComposeStack {
Expand All @@ -198,8 +198,8 @@ func (d *dockerComposeAPI) ServiceContainer(ctx context.Context, svcName string)
filters.Arg("label", fmt.Sprintf("%s=%s", api.ServiceLabel, svcName)),
),
}
containers, err := d.dockerClient.ContainerList(ctx, listOptions)

containers, err := d.dockerClient.ContainerList(ctx, listOptions)
if err != nil {
return nil, err
}
Expand Down
90 changes: 45 additions & 45 deletions compose_api_test.go
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/testcontainers/testcontainers-go/wait"
)

func TestDockerComposeApi(t *testing.T) {
func TestDockerComposeAPI(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -30,13 +30,13 @@ func TestDockerComposeApi(t *testing.T) {
assert.NoError(t, compose.Up(ctx, Wait(true)), "compose.Up()")
}

func TestDockerComposeApiStrategyForInvalidService(t *testing.T) {
func TestDockerComposeAPIStrategyForInvalidService(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -58,13 +58,13 @@ func TestDockerComposeApiStrategyForInvalidService(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithWaitLogStrategy(t *testing.T) {
func TestDockerComposeAPIWithWaitLogStrategy(t *testing.T) {
path := "./testresources/docker-compose-complex.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -86,13 +86,13 @@ func TestDockerComposeApiWithWaitLogStrategy(t *testing.T) {
assert.Contains(t, serviceNames, "mysql")
}

func TestDockerComposeApiWithRunServices(t *testing.T) {
func TestDockerComposeAPIWithRunServices(t *testing.T) {
path := "./testresources/docker-compose-complex.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -116,13 +116,13 @@ func TestDockerComposeApiWithRunServices(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithWaitForService(t *testing.T) {
func TestDockerComposeAPIWithWaitForService(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -146,13 +146,13 @@ func TestDockerComposeApiWithWaitForService(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithWaitHTTPStrategy(t *testing.T) {
func TestDockerComposeAPIWithWaitHTTPStrategy(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -176,13 +176,13 @@ func TestDockerComposeApiWithWaitHTTPStrategy(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithContainerName(t *testing.T) {
func TestDockerComposeAPIWithContainerName(t *testing.T) {
path := "./testresources/docker-compose-container-name.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -206,13 +206,13 @@ func TestDockerComposeApiWithContainerName(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithWaitStrategy_NoExposedPorts(t *testing.T) {
func TestDockerComposeAPIWithWaitStrategy_NoExposedPorts(t *testing.T) {
path := "./testresources/docker-compose-no-exposed-ports.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -233,13 +233,13 @@ func TestDockerComposeApiWithWaitStrategy_NoExposedPorts(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiWithMultipleWaitStrategies(t *testing.T) {
func TestDockerComposeAPIWithMultipleWaitStrategies(t *testing.T) {
path := "./testresources/docker-compose-complex.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -262,13 +262,13 @@ func TestDockerComposeApiWithMultipleWaitStrategies(t *testing.T) {
assert.Contains(t, serviceNames, "mysql")
}

func TestDockerComposeApiWithFailedStrategy(t *testing.T) {
func TestDockerComposeAPIWithFailedStrategy(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -294,13 +294,13 @@ func TestDockerComposeApiWithFailedStrategy(t *testing.T) {
assert.Contains(t, serviceNames, "nginx")
}

func TestDockerComposeApiComplex(t *testing.T) {
func TestDockerComposeAPIComplex(t *testing.T) {
path := "./testresources/docker-compose-complex.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -318,13 +318,13 @@ func TestDockerComposeApiComplex(t *testing.T) {
assert.Contains(t, serviceNames, "mysql")
}

func TestDockerComposeApiWithEnvironment(t *testing.T) {
func TestDockerComposeAPIWithEnvironment(t *testing.T) {
path := "./testresources/docker-compose-simple.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestDockerComposeApiWithEnvironment(t *testing.T) {
assertContainerEnvironmentVariables(t, identifier, "nginx", present, absent)
}

func TestDockerComposeApiWithMultipleComposeFiles(t *testing.T) {
func TestDockerComposeAPIWithMultipleComposeFiles(t *testing.T) {
composeFiles := []string{
"testresources/docker-compose-simple.yml",
"testresources/docker-compose-postgres.yml",
Expand All @@ -362,8 +362,8 @@ func TestDockerComposeApiWithMultipleComposeFiles(t *testing.T) {

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi(composeFiles, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI(composeFiles, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand Down Expand Up @@ -395,13 +395,13 @@ func TestDockerComposeApiWithMultipleComposeFiles(t *testing.T) {
assertContainerEnvironmentVariables(t, identifier, "nginx", present, absent)
}

func TestDockerComposeApiWithVolume(t *testing.T) {
func TestDockerComposeAPIWithVolume(t *testing.T) {
path := "./testresources/docker-compose-volume.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand All @@ -414,13 +414,13 @@ func TestDockerComposeApiWithVolume(t *testing.T) {
assert.NoError(t, err, "compose.Up()")
}

func TestDockerComposeApiWithBuild(t *testing.T) {
func TestDockerComposeAPIWithBuild(t *testing.T) {
path := "./testresources/docker-compose-build.yml"

identifier := testNameHash(t.Name())

compose, err := NewDockerComposeApi([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeApi()")
compose, err := NewDockerComposeAPI([]string{path}, identifier)
assert.NoError(t, err, "NewDockerComposeAPI()")

t.Cleanup(func() {
assert.NoError(t, compose.Down(context.Background(), RemoveOrphans(true), RemoveImagesLocal), "compose.Down()")
Expand Down

0 comments on commit 009b4b7

Please sign in to comment.