diff --git a/docker.go b/docker.go new file mode 100644 index 0000000000000000000000000000000000000000..fd5ecb4a140739451f8291e5d3fe32959cf59b86 --- /dev/null +++ b/docker.go @@ -0,0 +1,5 @@ +package jobqueue + +const ( + DOCKER_TEST_HOST_IP = "172.17.0.1" +) diff --git a/runnable-mail_test.go b/runnable-mail_test.go index a0705f83b31491d3e83d2c2349a01b0b0f194ebb..bc6e5ca5bc2884adf9c4ae185174b7be95ac7a0b 100644 --- a/runnable-mail_test.go +++ b/runnable-mail_test.go @@ -33,6 +33,9 @@ func startTestSMTPDockerImageAndContainer(t *testing.T, port string, ctx context _ = reader host, _, _ := net.SplitHostPort(cli.DaemonHost()) + if host == "" || host == "unix" { + host = DOCKER_TEST_HOST_IP + } hostConfig := &container.HostConfig{ PortBindings: nat.PortMap{ @@ -109,9 +112,7 @@ func TestMailRunner(t *testing.T) { time.Sleep(1 * time.Second) }) - host := "172.17.0.1" - - listener, err := net.Listen("tcp", host+":0") + listener, err := net.Listen("tcp", DOCKER_TEST_HOST_IP+":0") if err != nil { t.Errorf("Unexpected error: %v", err) return @@ -133,7 +134,7 @@ func TestMailRunner(t *testing.T) { waitCtx, waitCancel := context.WithTimeout(ctx, 60*time.Second) defer waitCancel() for { - conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, portAsString), 1*time.Second) + conn, err := net.DialTimeout("tcp", net.JoinHostPort(DOCKER_TEST_HOST_IP, portAsString), 1*time.Second) if err == nil { err = conn.Close() assert.Nil(t, err) @@ -156,7 +157,7 @@ func TestMailRunner(t *testing.T) { From: "from@example.com", Subject: "this is a test", Body: "this is the body", - Server: host, + Server: DOCKER_TEST_HOST_IP, Port: portAsString, Username: "", Password: "", diff --git a/runnable-sftp_test.go b/runnable-sftp_test.go index 277243459e51ac985758199d79a2190b09a95c08..0df2b11e033a91cdcf5371fb4fdb0893b41eefd5 100644 --- a/runnable-sftp_test.go +++ b/runnable-sftp_test.go @@ -34,6 +34,9 @@ func startSFTPTestDockerImageAndContainer(t *testing.T, port string, volume stri _ = reader host, _, _ := net.SplitHostPort(cli.DaemonHost()) + if host == "" || host == "unix" { + host = DOCKER_TEST_HOST_IP + } hostConfig := &container.HostConfig{ PortBindings: nat.PortMap{ @@ -109,9 +112,7 @@ func TestSFTPCRunnerLocalToRemote(t *testing.T) { time.Sleep(1 * time.Second) }) - host := "172.17.0.1" - - listener, err := net.Listen("tcp", host+":0") + listener, err := net.Listen("tcp", DOCKER_TEST_HOST_IP+":0") if err != nil { t.Errorf("Unexpected error: %v", err) return @@ -133,7 +134,7 @@ func TestSFTPCRunnerLocalToRemote(t *testing.T) { waitCtx, waitCancel := context.WithTimeout(ctx, 60*time.Second) defer waitCancel() for { - conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, portAsString), 1*time.Second) + conn, err := net.DialTimeout("tcp", net.JoinHostPort(DOCKER_TEST_HOST_IP, portAsString), 1*time.Second) if err == nil { err = conn.Close() assert.Nil(t, err) @@ -162,7 +163,7 @@ func TestSFTPCRunnerLocalToRemote(t *testing.T) { } sftpRunnable := &SFTPRunnable{ - Host: host, + Host: DOCKER_TEST_HOST_IP, Port: portAsInt, User: "demo", Insecure: true, @@ -204,9 +205,7 @@ func TestSFTPCRunnerRemoteToLocal(t *testing.T) { time.Sleep(1 * time.Second) }) - host := "127.0.0.1" - - listener, err := net.Listen("tcp", host+":0") + listener, err := net.Listen("tcp", DOCKER_TEST_HOST_IP+":0") if err != nil { t.Errorf("Unexpected error: %v", err) return @@ -238,7 +237,7 @@ func TestSFTPCRunnerRemoteToLocal(t *testing.T) { waitCtx, waitCancel := context.WithTimeout(ctx, 60*time.Second) defer waitCancel() for { - conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, portAsString), 1*time.Second) + conn, err := net.DialTimeout("tcp", net.JoinHostPort(DOCKER_TEST_HOST_IP, portAsString), 1*time.Second) if err == nil { err = conn.Close() assert.Nil(t, err) @@ -259,7 +258,7 @@ func TestSFTPCRunnerRemoteToLocal(t *testing.T) { tempDir := t.TempDir() sftpRunnable := &SFTPRunnable{ - Host: host, + Host: DOCKER_TEST_HOST_IP, Port: portAsInt, User: "demo", Insecure: true,