diff --git a/.golangci.yml b/.golangci.yml index 1fd41b679c..06527ba840 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,6 +32,7 @@ linters: - staticcheck - stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false] - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] + - testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false] - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false] - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] diff --git a/internal/args/marshal_test.go b/internal/args/marshal_test.go index 95d8cb098a..818d7ee94a 100644 --- a/internal/args/marshal_test.go +++ b/internal/args/marshal_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/scaleway/scaleway-cli/v2/internal/args" "github.com/scaleway/scaleway-sdk-go/scw" @@ -25,7 +27,7 @@ func TestMarshal(t *testing.T) { args, err := args.MarshalStruct(testCase.data) if testCase.error == "" { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCase.expected, args) } else { assert.Equal(t, testCase.error, err.Error()) @@ -238,7 +240,7 @@ func TestMarshalValue(t *testing.T) { value, err := args.MarshalValue(testCase.data) if testCase.error == "" { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCase.expected, value) } else { assert.Equal(t, testCase.error, err.Error()) diff --git a/internal/args/unmarshal_test.go b/internal/args/unmarshal_test.go index d663cc366c..8f816e07a7 100644 --- a/internal/args/unmarshal_test.go +++ b/internal/args/unmarshal_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/scaleway/scaleway-cli/v2/internal/args" "github.com/scaleway/scaleway-sdk-go/scw" @@ -35,7 +37,7 @@ func TestUnmarshalStruct(t *testing.T) { err := args.UnmarshalStruct(testCase.args, testCase.data) if testCase.error == "" { - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testCase.expected, testCase.data) } else { assert.Equal(t, testCase.error, err.Error()) diff --git a/internal/core/cobra_utils_test.go b/internal/core/cobra_utils_test.go index 3cf8ba42cd..9d3dbcecf4 100644 --- a/internal/core/cobra_utils_test.go +++ b/internal/core/cobra_utils_test.go @@ -282,7 +282,7 @@ func Test_MultiPositionalArg(t *testing.T) { core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { res := ctx.Result.(*testAcceptMultiPositionalArgsType) - assert.Equal(t, 1, len(res.NameIDs)) + assert.Len(t, res.NameIDs, 1) assert.Equal(t, "pos1", res.NameIDs[0]) assert.Equal(t, "tag1", res.Tag) }, @@ -297,7 +297,7 @@ func Test_MultiPositionalArg(t *testing.T) { core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { res := ctx.Result.(*testAcceptMultiPositionalArgsType) - assert.Equal(t, 3, len(res.NameIDs)) + assert.Len(t, res.NameIDs, 3) assert.Equal(t, "pos1", res.NameIDs[0]) assert.Equal(t, "pos2", res.NameIDs[1]) assert.Equal(t, "pos3", res.NameIDs[2]) diff --git a/internal/core/result_test.go b/internal/core/result_test.go index 301ecf2f1b..0ed0ae218b 100644 --- a/internal/core/result_test.go +++ b/internal/core/result_test.go @@ -3,6 +3,8 @@ package core_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/scaleway/scaleway-cli/v2/internal/core" "github.com/stretchr/testify/assert" @@ -18,9 +20,9 @@ func TestResult(t *testing.T) { } humanOutput, err := result.MarshalHuman() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", humanOutput) jsonOutput, err := result.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []byte("{}"), jsonOutput) } diff --git a/internal/core/testing.go b/internal/core/testing.go index 666a5446c4..3e2cd03fd3 100644 --- a/internal/core/testing.go +++ b/internal/core/testing.go @@ -654,7 +654,7 @@ func TestCheckGoldenAndReplacePatterns(replacements ...GoldenReplacement) TestCh expected, err := os.ReadFile(goldenPath) require.NoError(t, err, "expected to find golden file %s", goldenPath) assert.Equal(t, string(expected), actual) - assert.Nil(t, actualReplaceErr, "failed to match test output with regexes") + assert.NoError(t, actualReplaceErr, "failed to match test output with regexes") } } diff --git a/internal/namespaces/instance/v1/instance_cli_test.go b/internal/namespaces/instance/v1/instance_cli_test.go index 13cb85dfa0..0b8c2415c1 100644 --- a/internal/namespaces/instance/v1/instance_cli_test.go +++ b/internal/namespaces/instance/v1/instance_cli_test.go @@ -184,7 +184,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { - assert.NoError(t, ctx.Err) + require.NoError(t, ctx.Err) assert.Equal(t, ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PlacementGroup.ID,