Skip to content

Commit

Permalink
Add additional docker containers and require more ports for better te…
Browse files Browse the repository at this point in the history
…sting. Fix cases where the error was wrong.
  • Loading branch information
schmidtw committed Dec 10, 2023
1 parent 2d464dc commit d75c42c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
15 changes: 14 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,18 @@ services:
nginx:
image: nginx
ports:
- "8000:80"
- "7999:80"
dynamodb:
container_name: dynamodb
hostname: dynamodb.local.amazonaws.com
image: amazon/dynamodb-local
command: -jar DynamoDBLocal.jar -inMemory -sharedDb
ports:
- "7998:8000"
kinesis:
container_name: kinesis
hostname: kinesis
image: saidsef/aws-kinesis-local
ports:
- "7997:4567"
version: "3.8"
5 changes: 1 addition & 4 deletions idock.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,7 @@ func (c *IDock) isPortOpen(ctx context.Context, port int) error {

conn, err := d.DialContext(ctx, "tcp", address)
if err != nil {
if ctx.Err() == nil {
err = errTimedOut
}
return err
return errTimedOut
}
conn.Close()

Expand Down
18 changes: 9 additions & 9 deletions idock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestIDock_startDocker(t *testing.T) {
dockerComposeFile: "docker-compose.yml",
dockerMaxWait: 15 * time.Second,
localhost: "localhost",
dockerTCPPorts: []int{8000},
dockerTCPPorts: []int{7999, 7998, 7997},
},
}, {
description: "success, verbosity",
Expand All @@ -53,7 +53,7 @@ func TestIDock_startDocker(t *testing.T) {
dockerComposeFile: "docker-compose.yml",
dockerMaxWait: 15 * time.Second,
localhost: "localhost",
dockerTCPPorts: []int{8000},
dockerTCPPorts: []int{7999},
},
}, {
description: "a docker-compose file, but not enough ports",
Expand All @@ -62,7 +62,7 @@ func TestIDock_startDocker(t *testing.T) {
dockerComposeFile: "docker-compose.yml",
dockerMaxWait: 3 * time.Second,
localhost: "localhost",
dockerTCPPorts: []int{8000, 9999},
dockerTCPPorts: []int{7999, 9999},
},
expectErr: unknownErr,
},
Expand Down Expand Up @@ -259,13 +259,13 @@ func TestNewAndOptions(t *testing.T) {

DockerComposeFile("docker-compose.yml"),
DockerMaxWait(5 * time.Second),
RequireDockerTCPPorts(8000),
RequireDockerTCPPorts(7999),

AfterDocker(func(context.Context, *IDock) {}),

Program(func() {}),
ProgramMaxWait(5 * time.Second),
RequireProgramTCPPorts(8000),
RequireProgramTCPPorts(7999),

AfterProgram(func(context.Context, *IDock) {}),
CleanupAttempts(3),
Expand All @@ -286,13 +286,13 @@ func TestNewAndOptions(t *testing.T) {

assert.Equal("docker-compose.yml", c.dockerComposeFile)
assert.Equal(15*time.Second, c.dockerMaxWait)
assert.Equal([]int{8000}, c.dockerTCPPorts)
assert.Equal([]int{7999}, c.dockerTCPPorts)

assert.NotNil(c.afterDocker)

assert.NotNil(c.program)
assert.Equal(15*time.Second, c.programMaxWait)
assert.Equal([]int{8000}, c.programTCPPorts)
assert.Equal([]int{7999}, c.programTCPPorts)

assert.NotNil(c.afterProgram)
assert.Equal(5, c.cleanupAttempts)
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestRun(t *testing.T) {

DockerComposeFile("docker-compose.yml"),
DockerMaxWait(15 * time.Second),
RequireDockerTCPPorts(8000),
RequireDockerTCPPorts(7999),

AfterDocker(func(context.Context, *IDock) {
afterDockerCallCount++
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestRun(t *testing.T) {

DockerComposeFile("docker-compose.yml"),
DockerMaxWait(15 * time.Second),
RequireDockerTCPPorts(8000),
RequireDockerTCPPorts(7999),

ProgramMaxWait(100 * time.Millisecond),
RequireProgramTCPPorts(port, 99),
Expand Down

0 comments on commit d75c42c

Please sign in to comment.