diff --git a/internal/ports.go b/internal/ports.go index 13a951a..3dfc52e 100644 --- a/internal/ports.go +++ b/internal/ports.go @@ -39,7 +39,7 @@ func isPortActive(host string, port int) bool { func (r *RunConfig) portsFoundCount() int { count := 0 for _, status := range r.hostPortsReady { - if status == true { + if status { count += 1 } } @@ -48,7 +48,7 @@ func (r *RunConfig) portsFoundCount() int { func (r *RunConfig) allPortsFound() bool { for _, status := range r.hostPortsReady { - if status != true { + if !status { return false } } @@ -58,7 +58,7 @@ func (r *RunConfig) allPortsFound() bool { func (r *RunConfig) checkPorts() { wg := sync.WaitGroup{} for hostPort, status := range r.hostPortsReady { - if status == true { + if status { // already checked to be there, continue continue } @@ -69,7 +69,7 @@ func (r *RunConfig) checkPorts() { defer wg.Done() if isPortActive(hostPort.host, hostPort.port) { r.hostPortsReady[hostPort] = true - r.printDebugStatement(fmt.Sprintf("Found %s:%d to be available.\n", hostPort.host, hostPort.port)) + r.printDebugStatement(fmt.Sprintf("Found %s:%d to be available.", hostPort.host, hostPort.port)) } }(&wg, hostPort, r) } diff --git a/internal/ports_test.go b/internal/ports_test.go index 5ed1946..cb2e59f 100644 --- a/internal/ports_test.go +++ b/internal/ports_test.go @@ -14,21 +14,21 @@ const ( ) func TestExtractHostAndPortFromStringSuccess(t *testing.T) { - host, port, err := extractHostAndPortFromString("localhost:1234") + host, port, err := extractHostAndPortFromString("127.0.0.1:1234") assert.Nil(t, err) - assert.Equal(t, host, "localhost") + assert.Equal(t, host, "127.0.0.1") assert.Equal(t, port, 1234) } func TestExtractHostAndPortFromStringFailureBadInput(t *testing.T) { - host, port, err := extractHostAndPortFromString("localhost") + host, port, err := extractHostAndPortFromString("127.0.0.1") assert.Equal(t, err, ErrorHostPortBadFormat) assert.Equal(t, host, "") assert.Equal(t, port, 0) } func TestExtractHostAndPortFromStringFailureBadInt(t *testing.T) { - host, port, err := extractHostAndPortFromString("localhost:lol") + host, port, err := extractHostAndPortFromString("127.0.0.1:lol") assert.NotNil(t, err) assert.Equal(t, host, "") assert.Equal(t, port, 0) @@ -36,10 +36,10 @@ func TestExtractHostAndPortFromStringFailureBadInt(t *testing.T) { func TestIsPortActiveFalse(t *testing.T) { // potentially flaky test, expects nothing to be running on this port - assert.False(t, isPortActive("localhost", TestPort)) + assert.False(t, isPortActive("127.0.0.1", TestPort)) } func TestIsPortActiveTrue(t *testing.T) { defer startWebServer(TestPort).Close() - assert.True(t, isPortActive("localhost", TestPort)) + assert.True(t, isPortActive("127.0.0.1", TestPort)) } diff --git a/internal/run.go b/internal/run.go index b291374..d733509 100644 --- a/internal/run.go +++ b/internal/run.go @@ -25,6 +25,7 @@ func NewRunConfig(debug bool, portsToCheck cli.StringSlice, started time.Time, t } } return &RunConfig{ + debug: debug, hostPortsReady: portsOpen, started: started, timeout: time.Duration(timeout) * time.Second, @@ -48,7 +49,7 @@ func RunLoop(ctx *cli.Context) error { return err } - r.printDebugStatement(fmt.Sprintf("Starting ready checks (for up to %d seconds).\n", timeout)) + r.printDebugStatement(fmt.Sprintf("Starting ready checks (for up to %d seconds).", timeout)) go func(r *RunConfig) { for { if r.allPortsFound() { @@ -63,7 +64,7 @@ func RunLoop(ctx *cli.Context) error { go func(r *RunConfig) { for { time.Sleep(DebugLogInterval) - r.printDebugStatement(fmt.Sprintf("Still running ready checks (%d/%d)...\n", r.portsFoundCount(), len(r.hostPortsReady))) + r.printDebugStatement(fmt.Sprintf("Still running ready checks (%d/%d)...", r.portsFoundCount(), len(r.hostPortsReady))) } }(r) diff --git a/internal/run_test.go b/internal/run_test.go index 7aec971..6288244 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -12,7 +12,7 @@ func TestRunLoopSuccess(t *testing.T) { err := app.Run([]string{ "--debugfalse", "--timeout=1", - fmt.Sprintf("--host-ports=localhost:%d", TestPort), + fmt.Sprintf("--host-ports=127.0.0.1:%d", TestPort), "run", }) assert.Nil(t, err) @@ -24,7 +24,7 @@ func TestRunLoopPartialSuccess(t *testing.T) { err := app.Run([]string{ "--debugfalse", "--timeout=1", - fmt.Sprintf("--host-ports=localhost:%d,localhost:%d", TestPort, TestPortFailure), + fmt.Sprintf("--host-ports=127.0.0.1:%d,127.0.0.1:%d", TestPort, TestPortFailure), "run", }) assert.NotNil(t, err) @@ -36,7 +36,7 @@ func TestRunLoopFailure(t *testing.T) { err := app.Run([]string{ "--debugfalse", "--timeout=1", - fmt.Sprintf("--host-ports=localhost:%d", TestPortFailure), + fmt.Sprintf("--host-ports=127.0.0.1:%d", TestPortFailure), "run", }) assert.NotNil(t, err) diff --git a/internal/test_utils.go b/internal/test_utils.go index 0454782..2ecf4a8 100644 --- a/internal/test_utils.go +++ b/internal/test_utils.go @@ -2,21 +2,15 @@ package internal import ( "fmt" - "github.com/urfave/cli/v2" "net" "os" ) func startWebServer(port int) net.Listener { - l, err := net.Listen("tcp", fmt.Sprintf("localhost: %d", port)) + l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { fmt.Println("Error listening:", err.Error()) os.Exit(1) } return l } - -func setCommonContextTestValues(ctx *cli.Context) { - ctx.Set(TimeoutKey, "1") - ctx.Set(DebugKey, "false") -}