From a4c2691c5b548a4361e0379ad0e77702f6ceceb5 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Mon, 4 Mar 2024 08:20:26 +0100 Subject: [PATCH] chore(lint): relinted tests Signed-off-by: Frederic BIDON --- api_test.go | 9 +++++---- schema_test.go | 17 ++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api_test.go b/api_test.go index d0f0bf4..0442ff6 100644 --- a/api_test.go +++ b/api_test.go @@ -15,6 +15,7 @@ package errors import ( + "errors" "fmt" "net/http" "net/http/httptest" @@ -71,7 +72,7 @@ func TestServeError(t *testing.T) { }() // defaults to internal server error - simpleErr := fmt.Errorf("some error") + simpleErr := errors.New("some error") recorder = httptest.NewRecorder() ServeError(recorder, nil, simpleErr) assert.Equal(t, http.StatusInternalServerError, recorder.Code) @@ -83,8 +84,8 @@ func TestServeError(t *testing.T) { // unrecognized: return internal error with first error only - the second error is ignored compositeErr := &CompositeError{ Errors: []error{ - fmt.Errorf("firstError"), - fmt.Errorf("anotherError"), + errors.New("firstError"), + errors.New("anotherError"), }, } recorder = httptest.NewRecorder() @@ -245,7 +246,7 @@ func TestMarshalJSON(t *testing.T) { require.NoError(t, err) assert.JSONEq(t, fmt.Sprintf(`{"code":1,"message":"a","errors":[%s]}`, expectedJSON), string(jazon)) - p := ParseError{code: 1, message: "x", Name: "a", In: "b", Value: "c", Reason: fmt.Errorf("d")} + p := ParseError{code: 1, message: "x", Name: "a", In: "b", Value: "c", Reason: errors.New("d")} jazon, err = p.MarshalJSON() require.NoError(t, err) assert.JSONEq(t, `{"code":1,"message":"x","name":"a","in":"b","value":"c","reason":"d"}`, string(jazon)) diff --git a/schema_test.go b/schema_test.go index 93de758..0d7e9c4 100644 --- a/schema_test.go +++ b/schema_test.go @@ -16,7 +16,6 @@ package errors import ( "errors" - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -248,7 +247,7 @@ func TestSchemaErrors(t *testing.T) { require.Error(t, err) assert.EqualValues(t, MultipleOfFailCode, err.Code()) assert.Equal(t, "something in query should be a multiple of 5", err.Error()) - assert.Equal(t, float64(1), err.Value) + assert.InDelta(t, float64(1), err.Value, 1e-6) err = NotMultipleOf("something", "query", uint64(5), uint64(1)) require.Error(t, err) @@ -266,7 +265,7 @@ func TestSchemaErrors(t *testing.T) { require.Error(t, err) assert.EqualValues(t, MultipleOfMustBePositiveCode, err.Code()) assert.Equal(t, `factor MultipleOf declared for path must be positive: -10`, err.Error()) - assert.Equal(t, float64(-10), err.Value) + assert.InDelta(t, float64(-10), err.Value, 1e-6) err = MultipleOfMustBePositive("path", "body", int64(-10)) require.Error(t, err) @@ -294,13 +293,13 @@ func TestSchemaErrors(t *testing.T) { require.Error(t, err) assert.EqualValues(t, RequiredFailCode, err.Code()) assert.Equal(t, "something in query is required", err.Error()) - assert.Equal(t, nil, err.Value) + assert.Nil(t, err.Value) err = Required("something", "", nil) require.Error(t, err) assert.EqualValues(t, RequiredFailCode, err.Code()) assert.Equal(t, "something is required", err.Error()) - assert.Equal(t, nil, err.Value) + assert.Nil(t, err.Value) }) t.Run("with ReadOnly", func(t *testing.T) { @@ -308,13 +307,13 @@ func TestSchemaErrors(t *testing.T) { require.Error(t, err) assert.EqualValues(t, ReadOnlyFailCode, err.Code()) assert.Equal(t, "something in query is readOnly", err.Error()) - assert.Equal(t, nil, err.Value) + assert.Nil(t, err.Value) err = ReadOnly("something", "", nil) require.Error(t, err) assert.EqualValues(t, ReadOnlyFailCode, err.Code()) assert.Equal(t, "something is readOnly", err.Error()) - assert.Equal(t, nil, err.Value) + assert.Nil(t, err.Value) }) t.Run("with TooLong/TooShort", func(t *testing.T) { @@ -387,8 +386,8 @@ func TestSchemaErrors(t *testing.T) { assert.EqualValues(t, CompositeErrorCode, err.Code()) assert.Equal(t, "validation failure list", err.Error()) - testErr1 := fmt.Errorf("first error") - testErr2 := fmt.Errorf("second error") + testErr1 := errors.New("first error") + testErr2 := errors.New("second error") err = CompositeValidationError(testErr1, testErr2) require.Error(t, err) assert.EqualValues(t, CompositeErrorCode, err.Code())