Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ on:
pull_request:
branches: [ "master" ]

jobs:
permissions:
contents: read
pull-requests: read

jobs:
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -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 ./...

Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ linters:
disable-all: true
enable:
- unused
- deadcode
- stylecheck
- gosimple
- govet
- errcheck
- deadcode
- structcheck
- varcheck
- ineffassign
- typecheck
- dupl
Expand Down
24 changes: 14 additions & 10 deletions bik/bik_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
})
Expand Down Expand Up @@ -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))
}
}
})
Expand Down
31 changes: 18 additions & 13 deletions inn/inn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
})
Expand Down Expand Up @@ -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))
}
}
})
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
37 changes: 22 additions & 15 deletions kpp/kpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ru_doc_code "github.com/sshaplygin/ru-doc-code"
)

//nolint:dupl
func TestValidate(t *testing.T) {
t.Parallel()

Expand All @@ -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))
}
}
})
Expand Down Expand Up @@ -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))
}
}
})
Expand All @@ -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))
}
}
})
Expand Down
12 changes: 7 additions & 5 deletions ogrn/ogrn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
})
Expand Down
24 changes: 14 additions & 10 deletions ogrnip/ogrnip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
})
Expand Down Expand Up @@ -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))
}
}
})
Expand Down
24 changes: 14 additions & 10 deletions snils/snils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
})
Expand Down Expand Up @@ -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))
}
}
})
Expand Down