From d75c42cc0138835df34013b60dac5f30b0146d18 Mon Sep 17 00:00:00 2001 From: WSchmi001 Date: Sun, 10 Dec 2023 14:51:28 -0800 Subject: [PATCH] Add additional docker containers and require more ports for better testing. Fix cases where the error was wrong. --- docker-compose.yml | 15 ++++++++++++++- idock.go | 5 +---- idock_test.go | 18 +++++++++--------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 44d6c4e..fda3dc0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" \ No newline at end of file diff --git a/idock.go b/idock.go index 6e8f59e..f4abda6 100644 --- a/idock.go +++ b/idock.go @@ -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() diff --git a/idock_test.go b/idock_test.go index 6bc575e..4be3d88 100644 --- a/idock_test.go +++ b/idock_test.go @@ -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", @@ -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", @@ -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, }, @@ -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), @@ -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) @@ -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++ @@ -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),