From cff2c2941f4392f7ef49e99992c486ca6af19d63 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Fri, 2 Dec 2022 08:30:53 +0000 Subject: [PATCH 1/4] Remove deprecated `ioutil` package --- tests/integration/api_packages_nuget_test.go | 3 +-- tests/integration/api_pull_test.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/integration/api_packages_nuget_test.go b/tests/integration/api_packages_nuget_test.go index bf4217ef26217..39e2389492ee1 100644 --- a/tests/integration/api_packages_nuget_test.go +++ b/tests/integration/api_packages_nuget_test.go @@ -11,7 +11,6 @@ import ( "encoding/xml" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -106,7 +105,7 @@ func TestPackageNuGet(t *testing.T) { return &buf } - content, _ := ioutil.ReadAll(createPackage(packageName, packageVersion)) + content, _ := io.ReadAll(createPackage(packageName, packageVersion)) url := fmt.Sprintf("/api/packages/%s/nuget", user.Name) diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index 8ce92f3d4a622..a6b5258ab5ccb 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -6,7 +6,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -41,7 +41,7 @@ func TestAPIViewPulls(t *testing.T) { pull := pulls[0] if assert.EqualValues(t, 5, pull.ID) { resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK) - _, err := ioutil.ReadAll(resp.Body) + _, err := io.ReadAll(resp.Body) assert.NoError(t, err) // TODO: use diff to generate stats to test against From 68e6bd1c2cf54e16b0192c0e11e2983a95387dbf Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Fri, 2 Dec 2022 09:03:25 +0000 Subject: [PATCH 2/4] Replace deprecated HeaderMap --- tests/integration/api_packages_vagrant_test.go | 2 +- tests/integration/download_test.go | 16 ++++++++-------- tests/integration/nonascii_branches_test.go | 2 +- tests/integration/rename_branch_test.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/integration/api_packages_vagrant_test.go b/tests/integration/api_packages_vagrant_test.go index 1d2952e1a201f..cae0e58841f01 100644 --- a/tests/integration/api_packages_vagrant_test.go +++ b/tests/integration/api_packages_vagrant_test.go @@ -88,7 +88,7 @@ func TestPackageVagrant(t *testing.T) { req = NewRequest(t, "HEAD", boxURL) resp := MakeRequest(t, req, http.StatusOK) - assert.True(t, strings.HasPrefix(resp.HeaderMap.Get("Content-Type"), "application/json")) + assert.True(t, strings.HasPrefix(resp.Header().Get("Content-Type"), "application/json")) pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeVagrant) assert.NoError(t, err) diff --git a/tests/integration/download_test.go b/tests/integration/download_test.go index 9d3b17d103636..c3966202da1ed 100644 --- a/tests/integration/download_test.go +++ b/tests/integration/download_test.go @@ -35,9 +35,9 @@ func TestDownloadByIDForSVGUsesSecureHeaders(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo2/raw/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b") resp := session.MakeRequest(t, req, http.StatusOK) - assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy")) - assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type")) - assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options")) + assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy")) + assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type")) + assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options")) } func TestDownloadByIDMedia(t *testing.T) { @@ -61,9 +61,9 @@ func TestDownloadByIDMediaForSVGUsesSecureHeaders(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo2/media/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b") resp := session.MakeRequest(t, req, http.StatusOK) - assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy")) - assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type")) - assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options")) + assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy")) + assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type")) + assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options")) } func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) { @@ -74,7 +74,7 @@ func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml") resp := session.MakeRequest(t, req, http.StatusOK) - assert.Equal(t, "text/plain; charset=utf-8", resp.HeaderMap.Get("Content-Type")) + assert.Equal(t, "text/plain; charset=utf-8", resp.Header().Get("Content-Type")) } func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) { @@ -87,7 +87,7 @@ func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml") resp := session.MakeRequest(t, req, http.StatusOK) - assert.Equal(t, "text/xml; charset=utf-8", resp.HeaderMap.Get("Content-Type")) + assert.Equal(t, "text/xml; charset=utf-8", resp.Header().Get("Content-Type")) delete(setting.MimeTypeMap.Map, ".xml") setting.MimeTypeMap.Enabled = false diff --git a/tests/integration/nonascii_branches_test.go b/tests/integration/nonascii_branches_test.go index 638b9a61643e9..40bdc2ab121f9 100644 --- a/tests/integration/nonascii_branches_test.go +++ b/tests/integration/nonascii_branches_test.go @@ -23,7 +23,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route, resp := session.MakeRequest(t, req, http.StatusSeeOther) // Check Location header - location := resp.HeaderMap.Get("Location") + location := resp.Header().Get("Location") assert.Equal(t, path.Join(prefix, expectedLocation), location) // Perform redirect diff --git a/tests/integration/rename_branch_test.go b/tests/integration/rename_branch_test.go index 9ea69702afab2..fd6cf4d94a1eb 100644 --- a/tests/integration/rename_branch_test.go +++ b/tests/integration/rename_branch_test.go @@ -36,7 +36,7 @@ func TestRenameBranch(t *testing.T) { // check old branch link req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData) resp = session.MakeRequest(t, req, http.StatusSeeOther) - location := resp.HeaderMap.Get("Location") + location := resp.Header().Get("Location") assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location) // check db From adaa2a75076dc0b99034080abcd9d28904427f25 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Fri, 2 Dec 2022 20:01:55 +0000 Subject: [PATCH 3/4] Fix printf without arguments --- modules/activitypub/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index 62068d53b3df1..c5e720a401a3b 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -36,7 +36,7 @@ func TestActivityPubSignedPost(t *testing.T) { body, err := io.ReadAll(r.Body) assert.NoError(t, err) assert.Equal(t, expected, string(body)) - fmt.Fprintf(w, expected) + fmt.Fprintln(w, expected) })) defer srv.Close() From c2a0b496f9c2157fa4280ad6dc40dfefee32807c Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Fri, 2 Dec 2022 20:38:52 +0000 Subject: [PATCH 4/4] Use Fprint to prevent breaking testings --- modules/activitypub/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index c5e720a401a3b..b012c0ac0cff1 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -36,7 +36,7 @@ func TestActivityPubSignedPost(t *testing.T) { body, err := io.ReadAll(r.Body) assert.NoError(t, err) assert.Equal(t, expected, string(body)) - fmt.Fprintln(w, expected) + fmt.Fprint(w, expected) })) defer srv.Close()