diff --git a/main_test.go b/main_test.go index 53a0e48..18b5488 100644 --- a/main_test.go +++ b/main_test.go @@ -1,7 +1,7 @@ package main import ( - "net/http" + "net" "os" "testing" "time" @@ -14,9 +14,10 @@ func TestInitShortener(t *testing.T) { if err != nil { t.Fatalf("could not init shortener: %v", err) } - time.Sleep(1) // Give the http server a second to boot up - if err := http.ListenAndServe(viper.GetString("listen_addr"), nil); err == nil { - t.Fatal("port is not in use") + time.Sleep(time.Second) // Give the http server a second to boot up + // We expect there a port is in use error + if _, err := net.Listen("tcp", viper.GetString("listen_addr")); err == nil { + t.Fatalf("port is not in use: %v", err) } close() os.Exit(0)