Skip to content

Commit 8698458

Browse files
authored
Remove deprecated packages & staticcheck fixes (#22012)
`ioutil` is deprecated and should use `io` instead
1 parent 21bcb92 commit 8698458

7 files changed

+15
-16
lines changed

modules/activitypub/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestActivityPubSignedPost(t *testing.T) {
3535
body, err := io.ReadAll(r.Body)
3636
assert.NoError(t, err)
3737
assert.Equal(t, expected, string(body))
38-
fmt.Fprintf(w, expected)
38+
fmt.Fprint(w, expected)
3939
}))
4040
defer srv.Close()
4141

tests/integration/api_packages_nuget_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/xml"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"net/http"
1514
"net/http/httptest"
1615
"testing"
@@ -105,7 +104,7 @@ func TestPackageNuGet(t *testing.T) {
105104
return &buf
106105
}
107106

108-
content, _ := ioutil.ReadAll(createPackage(packageName, packageVersion))
107+
content, _ := io.ReadAll(createPackage(packageName, packageVersion))
109108

110109
url := fmt.Sprintf("/api/packages/%s/nuget", user.Name)
111110

tests/integration/api_packages_vagrant_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestPackageVagrant(t *testing.T) {
8787

8888
req = NewRequest(t, "HEAD", boxURL)
8989
resp := MakeRequest(t, req, http.StatusOK)
90-
assert.True(t, strings.HasPrefix(resp.HeaderMap.Get("Content-Type"), "application/json"))
90+
assert.True(t, strings.HasPrefix(resp.Header().Get("Content-Type"), "application/json"))
9191

9292
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeVagrant)
9393
assert.NoError(t, err)

tests/integration/api_pull_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package integration
55

66
import (
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"testing"
1111

@@ -41,7 +41,7 @@ func TestAPIViewPulls(t *testing.T) {
4141
pull := pulls[0]
4242
if assert.EqualValues(t, 5, pull.ID) {
4343
resp = ctx.Session.MakeRequest(t, NewRequest(t, "GET", pull.DiffURL), http.StatusOK)
44-
_, err := ioutil.ReadAll(resp.Body)
44+
_, err := io.ReadAll(resp.Body)
4545
assert.NoError(t, err)
4646
// TODO: use diff to generate stats to test against
4747

tests/integration/download_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func TestDownloadByIDForSVGUsesSecureHeaders(t *testing.T) {
3434
req := NewRequest(t, "GET", "/user2/repo2/raw/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b")
3535
resp := session.MakeRequest(t, req, http.StatusOK)
3636

37-
assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy"))
38-
assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type"))
39-
assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options"))
37+
assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy"))
38+
assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type"))
39+
assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options"))
4040
}
4141

4242
func TestDownloadByIDMedia(t *testing.T) {
@@ -60,9 +60,9 @@ func TestDownloadByIDMediaForSVGUsesSecureHeaders(t *testing.T) {
6060
req := NewRequest(t, "GET", "/user2/repo2/media/blob/6395b68e1feebb1e4c657b4f9f6ba2676a283c0b")
6161
resp := session.MakeRequest(t, req, http.StatusOK)
6262

63-
assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.HeaderMap.Get("Content-Security-Policy"))
64-
assert.Equal(t, "image/svg+xml", resp.HeaderMap.Get("Content-Type"))
65-
assert.Equal(t, "nosniff", resp.HeaderMap.Get("X-Content-Type-Options"))
63+
assert.Equal(t, "default-src 'none'; style-src 'unsafe-inline'; sandbox", resp.Header().Get("Content-Security-Policy"))
64+
assert.Equal(t, "image/svg+xml", resp.Header().Get("Content-Type"))
65+
assert.Equal(t, "nosniff", resp.Header().Get("X-Content-Type-Options"))
6666
}
6767

6868
func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) {
@@ -73,7 +73,7 @@ func TestDownloadRawTextFileWithoutMimeTypeMapping(t *testing.T) {
7373
req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
7474
resp := session.MakeRequest(t, req, http.StatusOK)
7575

76-
assert.Equal(t, "text/plain; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
76+
assert.Equal(t, "text/plain; charset=utf-8", resp.Header().Get("Content-Type"))
7777
}
7878

7979
func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) {
@@ -86,7 +86,7 @@ func TestDownloadRawTextFileWithMimeTypeMapping(t *testing.T) {
8686
req := NewRequest(t, "GET", "/user2/repo2/raw/branch/master/test.xml")
8787
resp := session.MakeRequest(t, req, http.StatusOK)
8888

89-
assert.Equal(t, "text/xml; charset=utf-8", resp.HeaderMap.Get("Content-Type"))
89+
assert.Equal(t, "text/xml; charset=utf-8", resp.Header().Get("Content-Type"))
9090

9191
delete(setting.MimeTypeMap.Map, ".xml")
9292
setting.MimeTypeMap.Enabled = false

tests/integration/nonascii_branches_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route,
2222
resp := session.MakeRequest(t, req, http.StatusSeeOther)
2323

2424
// Check Location header
25-
location := resp.HeaderMap.Get("Location")
25+
location := resp.Header().Get("Location")
2626
assert.Equal(t, path.Join(prefix, expectedLocation), location)
2727

2828
// Perform redirect

tests/integration/rename_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestRenameBranch(t *testing.T) {
3535
// check old branch link
3636
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
3737
resp = session.MakeRequest(t, req, http.StatusSeeOther)
38-
location := resp.HeaderMap.Get("Location")
38+
location := resp.Header().Get("Location")
3939
assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
4040

4141
// check db

0 commit comments

Comments
 (0)