dev: refactor some test assertions (#4081)
This commit is contained in:
parent
615a52b9e3
commit
0704271d8d
@ -2,7 +2,6 @@ package golinters
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -16,9 +15,7 @@ func Test_intersectStringSlice(t *testing.T) {
|
||||
|
||||
s3 := intersectStringSlice(s1, s2)
|
||||
|
||||
sort.Strings(s3)
|
||||
|
||||
assert.Equal(t, s3, []string{"experimental", "opinionated"})
|
||||
assert.ElementsMatch(t, []string{"experimental", "opinionated"}, s3)
|
||||
}
|
||||
|
||||
func Test_filterByDisableTags(t *testing.T) {
|
||||
@ -29,9 +26,7 @@ func Test_filterByDisableTags(t *testing.T) {
|
||||
|
||||
filterEnabledChecks := settingsWrapper.filterByDisableTags(enabledChecks, disabledTags)
|
||||
|
||||
sort.Strings(filterEnabledChecks)
|
||||
|
||||
assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
|
||||
assert.ElementsMatch(t, filterEnabledChecks, []string{"appendAssign", "caseOrder"})
|
||||
}
|
||||
|
||||
type tLog struct{}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
diffpkg "github.com/sourcegraph/go-diff/diff"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
@ -14,10 +15,10 @@ import (
|
||||
func testDiffProducesChanges(t *testing.T, log logutils.Log, diff string, expectedChanges ...Change) {
|
||||
diffs, err := diffpkg.ParseMultiFileDiff([]byte(diff))
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Len(t, diffs, 1)
|
||||
require.Len(t, diffs, 1)
|
||||
hunks := diffs[0].Hunks
|
||||
assert.NotEmpty(t, hunks)
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsAutogeneratedDetection(t *testing.T) {
|
||||
@ -99,7 +100,7 @@ this one line comment also`,
|
||||
|
||||
for _, tc := range testCases {
|
||||
doc, err := getDoc(tc.fpath)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.doc, doc)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
@ -50,7 +51,7 @@ func TestIdentifierMarker(t *testing.T) {
|
||||
|
||||
for _, c := range cases {
|
||||
out, err := p.Process([]result.Issue{{Text: c.in}})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []result.Issue{{Text: c.out}}, out)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/golinters"
|
||||
@ -173,9 +174,8 @@ func TestNolintInvalidLinterNameWithViolationOnTheSameLine(t *testing.T) {
|
||||
processedIssues, err := p.Process(issues)
|
||||
p.Finish()
|
||||
|
||||
assert.Len(t, processedIssues, 1)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, issues, processedIssues)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestNolintAliases(t *testing.T) {
|
||||
@ -288,7 +288,7 @@ func TestNolintUnused(t *testing.T) {
|
||||
enabledLintersSet := lintersdb.NewEnabledSet(dbManager, lintersdb.NewValidator(dbManager), enabledSetLog, cfg)
|
||||
|
||||
enabledLintersMap, err := enabledLintersSet.GetEnabledLintersMap()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
return NewNolint(log, dbManager, enabledLintersMap)
|
||||
}
|
||||
@ -351,7 +351,7 @@ func TestNolintUnused(t *testing.T) {
|
||||
enabledLintersSet := lintersdb.NewEnabledSet(dbManager, lintersdb.NewValidator(dbManager), enabledSetLog, cfg)
|
||||
|
||||
enabledLintersMap, err := enabledLintersSet.GetEnabledLintersMap()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
p := NewNolint(log, dbManager, enabledLintersMap)
|
||||
defer p.Finish()
|
||||
|
||||
|
@ -47,7 +47,7 @@ func TestPathPrefixer_Process(t *testing.T) {
|
||||
got, err := p.Process(tt.issues)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, got, tt.want)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
@ -38,7 +39,7 @@ func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue {
|
||||
t.Helper()
|
||||
|
||||
processedIssues, err := p.Process(issues)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return processedIssues
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
@ -21,7 +22,7 @@ func newFileIssue(file string) result.Issue {
|
||||
|
||||
func newTestSkipFiles(t *testing.T, patterns ...string) *SkipFiles {
|
||||
p, err := NewSkipFiles(patterns, "")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
return p
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
@ -158,25 +159,19 @@ func TestNoSorting(t *testing.T) {
|
||||
var sr = NewSortResults(&config.Config{})
|
||||
|
||||
results, err := sr.Process(tests)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tests, results)
|
||||
assert.Nil(t, err, nil)
|
||||
}
|
||||
|
||||
func TestSorting(t *testing.T) {
|
||||
var tests = make([]result.Issue, len(issues))
|
||||
copy(tests, issues)
|
||||
|
||||
var expected = make([]result.Issue, len(issues))
|
||||
expected[0] = issues[3]
|
||||
expected[1] = issues[2]
|
||||
expected[2] = issues[1]
|
||||
expected[3] = issues[0]
|
||||
|
||||
var cfg = config.Config{}
|
||||
cfg.Output.SortResults = true
|
||||
var sr = NewSortResults(&cfg)
|
||||
|
||||
results, err := sr.Process(tests)
|
||||
assert.Equal(t, results, expected)
|
||||
assert.Nil(t, err, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []result.Issue{issues[3], issues[2], issues[1], issues[0]}, results)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
_ "github.com/valyala/quicktemplate"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||
@ -536,7 +536,7 @@ func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
|
||||
func TestAbsPathDirAnalysis(t *testing.T) {
|
||||
dir := filepath.Join("testdata_etc", "abspath") // abs paths don't work with testdata dir
|
||||
absDir, err := filepath.Abs(dir)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewRunnerBuilder(t).
|
||||
WithNoConfig().
|
||||
@ -555,7 +555,7 @@ func TestAbsPathDirAnalysis(t *testing.T) {
|
||||
func TestAbsPathFileAnalysis(t *testing.T) {
|
||||
dir := filepath.Join("testdata_etc", "abspath", "with_issue.go") // abs paths don't work with testdata dir
|
||||
absDir, err := filepath.Abs(dir)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewRunnerBuilder(t).
|
||||
WithNoConfig().
|
||||
|
@ -349,7 +349,7 @@ func InstallGolangciLint(tb testing.TB) string {
|
||||
tb.Log(string(output))
|
||||
}
|
||||
|
||||
assert.NoError(tb, err, "Can't go install golangci-lint %s", string(output))
|
||||
require.NoError(tb, err, "Can't go install golangci-lint %s", string(output))
|
||||
}
|
||||
|
||||
abs, err := filepath.Abs(defaultBinaryName())
|
||||
|
Loading…
x
Reference in New Issue
Block a user