diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3ea0ea4..199a02f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,8 +9,11 @@ on: pull_request: branches: [ "master" ] -jobs: +permissions: + contents: read + pull-requests: read +jobs: build: runs-on: ubuntu-latest steps: @@ -24,6 +27,23 @@ jobs: - name: Build run: go build -v ./... + - name: Go Format + run: gofmt -s -w . && git diff --exit-code + + - name: Go Tidy + run: go mod tidy && git diff --exit-code + + - name: Go mod verify + run: go mod verify + + - name: Run linter + uses: golangci/golangci-lint-action@v3 + with: + version: latest + skip-cache: true + skip-pkg-cache: true + skip-build-cache: true + - name: Test run: go test -v ./... diff --git a/.golangci.yml b/.golangci.yml index 925a543..6398ede 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,14 +30,10 @@ linters: disable-all: true enable: - unused - - deadcode - stylecheck - gosimple - govet - errcheck - - deadcode - - structcheck - - varcheck - ineffassign - typecheck - dupl diff --git a/bik/bik_test.go b/bik/bik_test.go index 43dd4b0..6c3a50d 100644 --- a/bik/bik_test.go +++ b/bik/bik_test.go @@ -35,13 +35,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.NoError(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.NoError(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -79,13 +81,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code, test.IsValid) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code, tc.IsValid) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) diff --git a/inn/inn_test.go b/inn/inn_test.go index 2629a2a..f4d6adf 100644 --- a/inn/inn_test.go +++ b/inn/inn_test.go @@ -36,13 +36,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -75,13 +77,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -155,10 +159,11 @@ func TestGenerate(t *testing.T) { } var digits int64 - for _, test := range tests { - digits = ru_doc_code.RandomDigits(test.len) + for _, tc := range tests { + tc := tc - assert.True(t, digits >= test.min && digits <= test.max) + digits = ru_doc_code.RandomDigits(tc.len) + assert.True(t, digits >= tc.min && digits <= tc.max) } }) } diff --git a/kpp/kpp_test.go b/kpp/kpp_test.go index bf2b466..aceb977 100644 --- a/kpp/kpp_test.go +++ b/kpp/kpp_test.go @@ -9,6 +9,7 @@ import ( ru_doc_code "github.com/sshaplygin/ru-doc-code" ) +//nolint:dupl func TestValidate(t *testing.T) { t.Parallel() @@ -35,13 +36,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -69,13 +72,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -93,13 +98,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, isValid, test.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) diff --git a/ogrn/ogrn_test.go b/ogrn/ogrn_test.go index 8804253..e8c9d60 100644 --- a/ogrn/ogrn_test.go +++ b/ogrn/ogrn_test.go @@ -36,13 +36,15 @@ func TestValidate(t *testing.T) { IsValid: false, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) diff --git a/ogrnip/ogrnip_test.go b/ogrnip/ogrnip_test.go index 01603cb..8519aa7 100644 --- a/ogrnip/ogrnip_test.go +++ b/ogrnip/ogrnip_test.go @@ -35,13 +35,15 @@ func TestValidate(t *testing.T) { IsValid: false, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -74,13 +76,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code, test.IsValid) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code, tc.IsValid) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) diff --git a/snils/snils_test.go b/snils/snils_test.go index cfd6dfd..1ce9af1 100644 --- a/snils/snils_test.go +++ b/snils/snils_test.go @@ -35,13 +35,15 @@ func TestValidate(t *testing.T) { IsValid: false, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } }) @@ -79,13 +81,15 @@ func TestValidate(t *testing.T) { IsValid: true, }, } - for i, test := range testCases { - isValid, err := Validate(test.Code) - assert.Equal(t, test.IsValid, isValid, test.Code, test.IsValid) + for i, tc := range testCases { + tc := tc + + isValid, err := Validate(tc.Code) + assert.Equal(t, tc.IsValid, isValid, tc.Code, tc.IsValid) if err != nil { - assert.ErrorAs(t, err, &test.Error, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } else { - assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, test.Code)) + assert.Empty(t, err, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code)) } } })