Skip to content

Commit

Permalink
ci(deps): enable require-error rule from testifylint linter (#6718)
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 committed May 20, 2024
1 parent 65b8a40 commit bbaf595
Show file tree
Hide file tree
Showing 103 changed files with 226 additions and 196 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ linters-settings:
enable-all: true
disable:
- float-compare
- require-error

linters:
disable-all: true
Expand Down Expand Up @@ -99,7 +98,7 @@ run:

issues:
exclude-files:
- ".*_mock.go$"
- "mock_*.go$"
- "examples/*"
exclude-dirs:
- "pkg/iac/scanners/terraform/parser/funcs" # copies of Terraform functions
Expand Down
2 changes: 1 addition & 1 deletion integration/aws_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestAwsCommandRun(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
}
assert.NoError(t, err)
require.NoError(t, err)
})
}

Expand Down
8 changes: 4 additions & 4 deletions integration/client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package integration
import (
"context"
"fmt"
"github.com/aquasecurity/trivy/pkg/types"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/aquasecurity/trivy/pkg/types"

dockercontainer "github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"

Expand Down Expand Up @@ -542,7 +542,7 @@ func setup(t *testing.T, options setupOptions) (string, string) {
t.Setenv("XDG_DATA_HOME", cacheDir)

port, err := getFreePort()
assert.NoError(t, err)
require.NoError(t, err)
addr := fmt.Sprintf("localhost:%d", port)

go func() {
Expand All @@ -554,7 +554,7 @@ func setup(t *testing.T, options setupOptions) (string, string) {

ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
err = waitPort(ctx, addr)
assert.NoError(t, err)
require.NoError(t, err)

return addr, cacheDir
}
Expand Down
6 changes: 3 additions & 3 deletions integration/docker_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ package integration

import (
"context"
"github.com/aquasecurity/trivy/pkg/types"
"io"
"os"
"strings"
"testing"

"github.com/aquasecurity/trivy/pkg/types"

api "github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -298,7 +298,7 @@ func TestDockerEngine(t *testing.T) {
if len(tt.ignoreIDs) != 0 {
trivyIgnore := ".trivyignore"
err = os.WriteFile(trivyIgnore, []byte(strings.Join(tt.ignoreIDs, "\n")), 0444)
assert.NoError(t, err, "failed to write .trivyignore")
require.NoError(t, err, "failed to write .trivyignore")
defer os.Remove(trivyIgnore)
}
osArgs = append(osArgs, tt.input)
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func compareSPDXJson(t *testing.T, wantFile, gotFile string) {
SPDXVersion, ok := strings.CutPrefix(want.SPDXVersion, "SPDX-")
assert.True(t, ok)

assert.NoError(t, spdxlib.ValidateDocument(got))
require.NoError(t, spdxlib.ValidateDocument(got))

// Validate SPDX output against the JSON schema
validateReport(t, fmt.Sprintf(SPDXSchema, SPDXVersion), got)
Expand Down
5 changes: 2 additions & 3 deletions integration/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/aquasecurity/trivy/pkg/fanal/artifact"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/stretchr/testify/require"
)

// TestRepository tests `trivy repo` with the local code repositories
Expand Down Expand Up @@ -460,7 +459,7 @@ func TestRepository(t *testing.T) {
if len(tt.args.ignoreIDs) != 0 {
trivyIgnore := ".trivyignore"
err := os.WriteFile(trivyIgnore, []byte(strings.Join(tt.args.ignoreIDs, "\n")), 0444)
assert.NoError(t, err, "failed to write .trivyignore")
require.NoError(t, err, "failed to write .trivyignore")
defer os.Remove(trivyIgnore)
}

Expand Down
6 changes: 3 additions & 3 deletions integration/standalone_tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
package integration

import (
"github.com/aquasecurity/trivy/pkg/types"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/types"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -384,7 +384,7 @@ func TestTar(t *testing.T) {
if len(tt.args.IgnoreIDs) != 0 {
trivyIgnore := ".trivyignore"
err := os.WriteFile(trivyIgnore, []byte(strings.Join(tt.args.IgnoreIDs, "\n")), 0444)
assert.NoError(t, err, "failed to write .trivyignore")
require.NoError(t, err, "failed to write .trivyignore")
defer os.Remove(trivyIgnore)
}
if tt.args.Input != "" {
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 @@ -150,7 +150,7 @@ func TestRemoteCache_PutArtifact(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
} else {
assert.NoError(t, err, tt.name)
require.NoError(t, err, tt.name)
}
})
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestRemoteCache_PutBlob(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
return
} else {
assert.NoError(t, err, tt.name)
require.NoError(t, err, tt.name)
}
})
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestRemoteCache_PutArtifactInsecure(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr)
return
}
assert.NoError(t, err, tt.name)
require.NoError(t, err, tt.name)
})
}
}
4 changes: 2 additions & 2 deletions pkg/cloud/aws/commands/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,10 +1275,10 @@ Summary Report for compliance: my-custom-spec

err := Run(ctx, test.options)
if test.expectErr {
assert.Error(t, err)
require.Error(t, err)
return
}
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, test.want, output.String())
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestClient_NeedsUpdate(t *testing.T) {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr, tt.name)
default:
assert.NoError(t, err, tt.name)
require.NoError(t, err, tt.name)
}

assert.Equal(t, tt.want, needsUpdate)
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestClient_Download(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr)
return
}
assert.NoError(t, err)
require.NoError(t, err)

meta := metadata.NewClient(cacheDir)
got, err := meta.Get()
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/conda/environment/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/conda/meta/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
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 @@ -144,7 +144,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/dependency/parser/gradle/lockfile/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParser_Parse(t *testing.T) {
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestParser_Parse(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
parser := NewParser()
f, err := os.Open(tt.inputFile)
assert.NoError(t, err)
require.NoError(t, err)

pkgs, _, _ := parser.Parse(f)
sort.Sort(ftypes.Packages(pkgs))
Expand Down
3 changes: 2 additions & 1 deletion pkg/dependency/parser/hex/mix/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParser_Parse(t *testing.T) {
Expand Down Expand Up @@ -76,7 +77,7 @@ func TestParser_Parse(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
parser := NewParser()
f, err := os.Open(tt.inputFile)
assert.NoError(t, err)
require.NoError(t, err)

pkgs, _, _ := parser.Parse(f)
sort.Sort(ftypes.Packages(pkgs))
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 @@ -51,7 +51,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, tt.want, got)
})
}
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 @@ -75,7 +75,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/python/poetry/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestParseDependency(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
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 @@ -82,7 +82,7 @@ func TestParse(t *testing.T) {
return
}

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantDeps, gotDeps)
})
Expand Down
10 changes: 6 additions & 4 deletions pkg/dependency/parser/swift/swift/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package swift

import (
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/stretchr/testify/assert"
"os"
"testing"

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParser_Parse(t *testing.T) {
Expand Down Expand Up @@ -90,10 +92,10 @@ func TestParser_Parse(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
parser := NewParser()
f, err := os.Open(tt.inputFile)
assert.NoError(t, err)
require.NoError(t, err)

gotPkgs, _, err := parser.Parse(f)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, gotPkgs)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/detector/library/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestDriver_Detect(t *testing.T) {
}

// Compare
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/detector/ospkg/alma/alma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package alma_test

import (
"context"
"github.com/aquasecurity/trivy/pkg/clock"
"testing"
"time"

"github.com/aquasecurity/trivy/pkg/clock"

"github.com/aquasecurity/trivy-db/pkg/db"
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestScanner_Detect(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr)
return
}
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/detector/ospkg/alpine/alpine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestScanner_Detect(t *testing.T) {
sort.Slice(got, func(i, j int) bool {
return got[i].VulnerabilityID < got[j].VulnerabilityID
})
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/detector/ospkg/amazon/amazon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package amazon_test

import (
"context"
"github.com/aquasecurity/trivy/pkg/clock"
"testing"
"time"

"github.com/aquasecurity/trivy/pkg/clock"

"github.com/aquasecurity/trivy-db/pkg/db"
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestScanner_Detect(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr)
return
}
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/detector/ospkg/chainguard/chainguard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestScanner_Detect(t *testing.T) {
sort.Slice(got, func(i, j int) bool {
return got[i].VulnerabilityID < got[j].VulnerabilityID
})
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Expand Down
Loading

0 comments on commit bbaf595

Please sign in to comment.