diff --git a/internal/server/health_check_test.go b/internal/server/health_check_test.go index 08cd338..e033fb9 100644 --- a/internal/server/health_check_test.go +++ b/internal/server/health_check_test.go @@ -23,7 +23,7 @@ func TestHealthCheck(t *testing.T) { serverURL.Path = path hc := NewHealthCheck(consumer, serverURL, shortTimeout, shortTimeout) - defer hc.Close() + t.Cleanup(hc.Close) for _, exp := range expected { result := <-consumer @@ -76,9 +76,9 @@ func testHealthCheckTarget(t testing.TB) *url.URL { } case "/slow": time.Sleep(longTimeout) - default: - w.WriteHeader(http.StatusOK) } + + w.WriteHeader(http.StatusOK) })) t.Cleanup(server.Close) diff --git a/internal/server/testing.go b/internal/server/testing.go index 13a54ca..27d6a1d 100644 --- a/internal/server/testing.go +++ b/internal/server/testing.go @@ -19,6 +19,7 @@ var ( func testTarget(t testing.TB, handler http.HandlerFunc) *Target { t.Helper() + _, targetURL := testBackendWithHandler(t, handler) target, err := NewTarget(targetURL, defaultTargetOptions) @@ -28,6 +29,7 @@ func testTarget(t testing.TB, handler http.HandlerFunc) *Target { func testTargetWithOptions(t testing.TB, targetOptions TargetOptions, handler http.HandlerFunc) *Target { t.Helper() + _, targetURL := testBackendWithHandler(t, handler) target, err := NewTarget(targetURL, targetOptions) @@ -37,6 +39,7 @@ func testTargetWithOptions(t testing.TB, targetOptions TargetOptions, handler ht func testBackend(t testing.TB, body string, statusCode int) (*httptest.Server, string) { t.Helper() + return testBackendWithHandler(t, func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(statusCode) w.Write([]byte(body)) @@ -45,6 +48,7 @@ func testBackend(t testing.TB, body string, statusCode int) (*httptest.Server, s func testBackendWithHandler(t testing.TB, handler http.HandlerFunc) (*httptest.Server, string) { t.Helper() + server := httptest.NewServer(handler) t.Cleanup(server.Close) @@ -56,6 +60,7 @@ func testBackendWithHandler(t testing.TB, handler http.HandlerFunc) (*httptest.S func testServer(t testing.TB) (*Server, string) { t.Helper() + config := &Config{ Bind: "127.0.0.1", HttpPort: 0,