diff --git a/pkg/probe/http/http_test.go b/pkg/probe/http/http_test.go index 55b070be922..16b5b1b0208 100644 --- a/pkg/probe/http/http_test.go +++ b/pkg/probe/http/http_test.go @@ -61,7 +61,13 @@ func unsetEnv(key string) func() { func TestHTTPProbeProxy(t *testing.T) { res := "welcome to http probe proxy" - localProxy := "http://127.0.0.1:9098/" + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, res) + })) + defer server.Close() + + localProxy := server.URL defer setEnv("http_proxy", localProxy)() defer setEnv("HTTP_PROXY", localProxy)() @@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) { followNonLocalRedirects := true prober := New(followNonLocalRedirects) - go func() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, res) - }) - err := http.ListenAndServe(":9098", nil) - if err != nil { - t.Errorf("Failed to start foo server: localhost:9098") - } - }() - // take some time to wait server boot time.Sleep(2 * time.Second) url, err := url.Parse("http://example.com")