Skip to content

Commit

Permalink
ci(deps): enable testifylint linter on .*_test.go$ (#6688)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 authored May 16, 2024
1 parent 88702cf commit 9d26ae8
Show file tree
Hide file tree
Showing 61 changed files with 168 additions and 148 deletions.
45 changes: 33 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,60 @@ linters-settings:
ruleguard:
failOn: all
rules: '${configDir}/misc/lint/rules.go'
testifylint:
enable-all: true
disable:
- bool-compare
- expected-actual
- float-compare
- len
- require-error

linters:
disable-all: true
enable:
- unused
- ineffassign
- typecheck
- govet
- revive
- gosec
- unconvert
- bodyclose
- gci
- goconst
- gocritic
- gocyclo
- gofmt
- misspell
- bodyclose
- gci
- gomodguard
- gosec
- govet
- ineffassign
- misspell
- revive
- tenv
- gocritic
- testifylint
- typecheck
- unconvert
- unused

run:
go: '1.22'

issues:
exclude-files:
- ".*_mock.go$"
- ".*_test.go$"
- "integration/*"
- "examples/*"
exclude-dirs:
- "pkg/iac/scanners/terraform/parser/funcs" # copies of Terraform functions
exclude-rules:
- path: ".*_test.go$"
linters:
- bodyclose
- gci
- gocritic
- goconst
- gofmt
- gosec
- govet
- ineffassign
- misspell
- tenv
- unused
- linters:
- gosec
text: "G304: Potential file inclusion"
Expand Down
6 changes: 3 additions & 3 deletions pkg/cache/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestRemoteCache_PutArtifact(t *testing.T) {
c := cache.NewRemoteCache(ts.URL, tt.args.customHeaders, false)
err := c.PutArtifact(tt.args.imageID, tt.args.imageInfo)
if tt.wantErr != "" {
require.NotNil(t, err, tt.name)
require.Error(t, err, tt.name)
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
} else {
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestRemoteCache_PutBlob(t *testing.T) {
c := cache.NewRemoteCache(ts.URL, tt.args.customHeaders, false)
err := c.PutBlob(tt.args.diffID, tt.args.layerInfo)
if tt.wantErr != "" {
require.NotNil(t, err, tt.name)
require.Error(t, err, tt.name)
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
} else {
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestRemoteCache_MissingBlobs(t *testing.T) {
c := cache.NewRemoteCache(ts.URL, tt.args.customHeaders, false)
gotMissingImage, gotMissingLayerIDs, err := c.MissingBlobs(tt.args.imageID, tt.args.layerIDs)
if tt.wantErr != "" {
require.NotNil(t, err, tt.name)
require.Error(t, err, tt.name)
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/dotnet/core_deps/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestParse(t *testing.T) {

got, _, err := NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
} else {
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/golang/binary/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestParse(t *testing.T) {

got, _, err := binary.NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/java/pom/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ func TestPom_Parse(t *testing.T) {

gotPkgs, gotDeps, err := p.Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/nuget/config/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestParse(t *testing.T) {

got, _, err := config.NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/nuget/packagesprops/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestParse(t *testing.T) {

got, _, err := config.NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/ruby/gemspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestParse(t *testing.T) {

got, _, err := gemspec.NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/rust/binary/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestParse(t *testing.T) {

got, gotDeps, err := binary.NewParser().Parse(f)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/detector/ospkg/oracle/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func TestScanner_Detect(t *testing.T) {
s := NewScanner()
got, err := s.Detect(nil, tt.args.osVer, nil, tt.args.pkgs)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/fanal/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {
DisabledAnalyzers: tt.args.disabledAnalyzers,
})
if err != nil && tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand All @@ -549,7 +549,7 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {

wg.Wait()
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestAnalyze(t *testing.T) {

got, err := language.Analyze(tt.args.fileType, tt.args.filePath, tt.args.content, mp)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/dotnet/deps/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test_depsLibraryAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/java/pom/pom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func Test_pomAnalyzer_Analyze(t *testing.T) {
},
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/nodejs/pkg/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_nodePkgLibraryAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/nodejs/pnpm/pnpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Test_pnpmPkgLibraryAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func Test_packagingAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/python/pip/pip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_pipAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/ruby/gemspec/gemspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Test_gemspecLibraryAnalyzer_Analyze(t *testing.T) {
})

if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/fanal/analyzer/os/alpine/alpine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestAlpineReleaseOSAnalyzer_Required(t *testing.T) {
res, err := a.Analyze(context.Background(), test.input)

if test.wantError != "" {
assert.NotNil(t, err)
assert.Error(t, err)
assert.Equal(t, test.wantError, err.Error())
} else {
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, test.wantResult, res)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/amazonlinux/amazonlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func Test_amazonlinuxOSAnalyzer_Analyze(t *testing.T) {
ctx := context.Background()
got, err := a.Analyze(ctx, tt.input)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/debian/debian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Test_debianOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/redhatbase/centos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_centosOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/redhatbase/fedora_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_fedoraOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/redhatbase/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_oracleOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/redhatbase/redhatbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_redhatOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/os/ubuntu/ubuntu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_ubuntuOSAnalyzer_Analyze(t *testing.T) {
Content: f,
})
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/pkg/rpm/rpmqa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ glibc 2.35-2.cm2 1653816591 1653628955 Microsoft Corporation (none) 10855265 x86
a := rpmqaPkgAnalyzer{}
result, err := a.parseRpmqaManifest(strings.NewReader(test.content))
if test.wantErr != "" {
assert.NotNil(t, err)
assert.Error(t, err)
assert.Equal(t, test.wantErr, err.Error())
} else {
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/applier/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ func TestApplier_ApplyLayers(t *testing.T) {

got, err := a.ApplyLayers(tt.args.imageID, tt.args.layerIDs)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
} else {
require.NoError(t, err, tt.name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/artifact/local/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestArtifact_Inspect(t *testing.T) {

got, err := a.Inspect(context.Background())
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/artifact/repo/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func Test_newURL(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got, err := newURL(tt.args.rawurl)
if tt.wantErr != "" {
require.NotNil(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/artifact/sbom/sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func TestArtifact_Inspect(t *testing.T) {

got, err := a.Inspect(context.Background())
if len(tt.wantErr) > 0 {
require.NotNil(t, err)
require.Error(t, err)
found := false
for _, wantErr := range tt.wantErr {
if strings.Contains(err.Error(), wantErr) {
Expand Down
Loading

0 comments on commit 9d26ae8

Please sign in to comment.