From 0d3bdc7cff2baba9058d599ea154996e5d42c171 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Mon, 23 Oct 2023 14:49:12 +0200 Subject: [PATCH] fix: ci pipeline --- docker.go | 5 +++++ runnable-mail_test.go | 11 ++++++----- runnable-sftp_test.go | 19 +++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 docker.go diff --git a/docker.go b/docker.go new file mode 100644 index 0000000..fd5ecb4 --- /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 a0705f8..bc6e5ca 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 2772434..0df2b11 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, -- GitLab