Skip to content

Commit

Permalink
Minor test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmcconnell committed Dec 13, 2024
1 parent bc8525d commit ecfc1dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/server/health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions internal/server/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)

Expand All @@ -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,
Expand Down

0 comments on commit ecfc1dd

Please sign in to comment.