From b7115183758af64409e30ee6d37831fca0eba744 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Tue, 18 Jun 2024 10:55:42 -0400 Subject: [PATCH] Remove unnecessary .nocover files (#5642) ## Which problem is this PR solving? - Part of #5068 - Looks like test were added but `.nocover` files not removed. ## Description of the changes - Remove unnecessary .nocover files. ## How was this change tested? - Check if this affects coverage in CI. --------- Signed-off-by: Yuri Shkuro --- cmd/all-in-one/.nocover | 1 - cmd/all-in-one/all_in_one_test.go | 66 ++++++++----------- cmd/all-in-one/package_test.go | 14 ++++ cmd/anonymizer/app/anonymizer/.nocover | 1 - cmd/anonymizer/app/anonymizer/package_test.go | 14 ++++ cmd/internal/flags/.nocover | 2 - cmd/internal/flags/admin.go | 6 +- cmd/internal/flags/admin_test.go | 14 ++-- cmd/internal/flags/package_test.go | 14 ++++ 9 files changed, 81 insertions(+), 51 deletions(-) delete mode 100644 cmd/all-in-one/.nocover create mode 100644 cmd/all-in-one/package_test.go delete mode 100644 cmd/anonymizer/app/anonymizer/.nocover create mode 100644 cmd/anonymizer/app/anonymizer/package_test.go delete mode 100644 cmd/internal/flags/.nocover create mode 100644 cmd/internal/flags/package_test.go diff --git a/cmd/all-in-one/.nocover b/cmd/all-in-one/.nocover deleted file mode 100644 index 8ab06f28b67..00000000000 --- a/cmd/all-in-one/.nocover +++ /dev/null @@ -1 +0,0 @@ -main is not testable diff --git a/cmd/all-in-one/all_in_one_test.go b/cmd/all-in-one/all_in_one_test.go index f5186001976..95b7ea9bac8 100644 --- a/cmd/all-in-one/all_in_one_test.go +++ b/cmd/all-in-one/all_in_one_test.go @@ -75,7 +75,10 @@ func healthCheck(t *testing.T) { require.Eventuallyf( t, func() bool { - _, err := http.Get(queryAddr + "/") + resp, err := http.Get(queryAddr + "/") + if err == nil { + resp.Body.Close() + } return err == nil }, 10*time.Second, @@ -85,14 +88,23 @@ func healthCheck(t *testing.T) { t.Logf("Server detected at %s", queryAddr) } -func checkWebUI(t *testing.T) { - resp, err := http.Get(queryAddr + "/") +func httpGet(t *testing.T, url string) (*http.Response, []byte) { + req, err := http.NewRequest(http.MethodGet, url, nil) + require.NoError(t, err) + req.Close = true // avoid persistent connections which leak goroutines + + resp, err := httpClient.Do(req) require.NoError(t, err) - require.NotNil(t, resp) defer resp.Body.Close() - assert.Equal(t, http.StatusOK, resp.StatusCode) + bodyBytes, err := io.ReadAll(resp.Body) require.NoError(t, err) + + return resp, bodyBytes +} + +func checkWebUI(t *testing.T) { + _, bodyBytes := httpGet(t, queryAddr+"/") body := string(bodyBytes) t.Run("Static_files", func(t *testing.T) { pattern := regexp.MustCompile(`