From 5a606b1157a9440132835f65c456f3ca273d521f Mon Sep 17 00:00:00 2001 From: Su Yang Date: Mon, 24 Jun 2024 23:26:11 +0800 Subject: [PATCH] chore: update linter --- .github/workflows/release.yml | 2 +- .golangci.yml | 8 ++------ embed_folder_test.go | 13 ++++++++----- local_file_test.go | 4 ++-- serve_test.go | 1 - 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79270b7..54331ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest diff --git a/.golangci.yml b/.golangci.yml index 65d35f1..bb939cf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,8 +4,6 @@ linters: fast: false enable: - bodyclose - - deadcode - - depguard - dogsled - dupl - errcheck @@ -29,13 +27,11 @@ linters: - nolintlint - rowserrcheck - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - unused - - varcheck - whitespace - gofumpt @@ -46,6 +42,7 @@ linters-settings: files: - $all - "!$test" + - "!*_test.go" allow: - github.com/gin-gonic/gin - embed @@ -57,5 +54,4 @@ linters-settings: - fmt run: - timeout: 3m - tests: false + timeout: 3m \ No newline at end of file diff --git a/embed_folder_test.go b/embed_folder_test.go index e0b71fb..fdfa4f7 100644 --- a/embed_folder_test.go +++ b/embed_folder_test.go @@ -16,7 +16,7 @@ import ( var testFS embed.FS func TestEmbedFolderWithRedir(t *testing.T) { - var tests = []struct { + tests := []struct { targetURL string // input httpCode int // expected http code httpBody string // expected http body @@ -50,7 +50,7 @@ func TestEmbedFolderWithRedir(t *testing.T) { } func TestEmbedFolderWithoutRedir(t *testing.T) { - var tests = []struct { + tests := []struct { targetURL string // input httpCode int // expected http code httpBody string // expected http body @@ -118,7 +118,7 @@ func TestCreateEmbed(t *testing.T) { } func TestServEmbed(t *testing.T) { - var tests = []struct { + tests := []struct { targetURL string // input httpCode int // expected http code httpBody string // expected http body @@ -162,6 +162,9 @@ func TestServEmbed(t *testing.T) { } func TestServEmbedErr(t *testing.T) { + embedDir := "111111test/data/server" + message := fmt.Sprintf("open %s: file does not exist", embedDir) + tests := []struct { name string URL string @@ -172,12 +175,12 @@ func TestServEmbedErr(t *testing.T) { name: "Invalid Path", URL: "/test/data/server/nonexistingdirectory/nonexistingdirectory", Code: http.StatusInternalServerError, - Result: "{\"error\":\"open 111111test/data/server: file does not exist\",\"message\":\"initialization of embed folder failed\"}", + Result: fmt.Sprintf("{\"error\":\"%s\",\"message\":\"initialization of embed folder failed\"}", message), }, } router := gin.New() - router.Use(static.ServeEmbed("111111test/data/server", testFS)) + router.Use(static.ServeEmbed(embedDir, testFS)) for _, tt := range tests { w := PerformRequest(router, "GET", tt.URL) assert.Equal(t, w.Code, tt.Code) diff --git a/local_file_test.go b/local_file_test.go index 5b769eb..045633a 100644 --- a/local_file_test.go +++ b/local_file_test.go @@ -18,8 +18,8 @@ func TestLocalFile(t *testing.T) { t.Error(err) } defer os.Remove(f.Name()) - f.WriteString("Gin Web Framework") - f.Close() + _, _ = f.WriteString("Gin Web Framework") + _ = f.Close() dir, filename := filepath.Split(f.Name()) router := gin.New() diff --git a/serve_test.go b/serve_test.go index 3b40918..59da71d 100644 --- a/serve_test.go +++ b/serve_test.go @@ -14,7 +14,6 @@ import ( "github.com/stretchr/testify/assert" ) -// nolint:unparam func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { req, _ := http.NewRequestWithContext(context.Background(), method, path, nil) w := httptest.NewRecorder()