From b771a1363b90930619dcb85e6cf154566d286722 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Mon, 11 Jan 2021 06:22:35 -0800 Subject: [PATCH] logtail: start a local server for TestFastShutdown Right now TestFastShutdown tries to upload logs to localhost:1234, which will most likely respond with an error. However if one has an actual service running on port 1234, it would receive a connection attempting to POST every time the unit test runs. Start a local server and direct the upload there instead. Signed-off-by: Denton Gentry --- logtail/logtail_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/logtail/logtail_test.go b/logtail/logtail_test.go index 5e3083cc3..576cc1888 100644 --- a/logtail/logtail_test.go +++ b/logtail/logtail_test.go @@ -16,8 +16,12 @@ func TestFastShutdown(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() + testServ := httptest.NewServer(http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) {})) + defer testServ.Close() + l := NewLogger(Config{ - BaseURL: "http://localhost:1234", + BaseURL: testServ.URL, }, t.Logf) l.Shutdown(ctx) } @@ -30,6 +34,7 @@ func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") uploads += 1 })) + defer testServ.Close() l := NewLogger(Config{BaseURL: testServ.URL}, t.Logf) for i := 1; i < 10; i++ {