Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): relinted tests #50

Merged
merged 1 commit into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions api_test.go
Expand Up @@ -15,6 +15,7 @@
package errors

import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 8 additions & 9 deletions schema_test.go
Expand Up @@ -16,7 +16,6 @@ package errors

import (
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -294,27 +293,27 @@ 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) {
err := ReadOnly("something", "query", nil)
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) {
Expand Down Expand Up @@ -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())
Expand Down