refactor(test): unify assert.Equal usage (#1054)
This commit is contained in:
@ -60,7 +60,7 @@ func TestError(t *testing.T) {
|
||||
data string
|
||||
}
|
||||
err.SetMeta(customError{status: "200", data: "other data"})
|
||||
assert.Equal(t, err.JSON(), customError{status: "200", data: "other data"})
|
||||
assert.Equal(t, customError{status: "200", data: "other data"}, err.JSON())
|
||||
}
|
||||
|
||||
func TestErrorSlice(t *testing.T) {
|
||||
@ -71,33 +71,33 @@ func TestErrorSlice(t *testing.T) {
|
||||
}
|
||||
|
||||
assert.Equal(t, errs, errs.ByType(ErrorTypeAny))
|
||||
assert.Equal(t, errs.Last().Error(), "third")
|
||||
assert.Equal(t, errs.Errors(), []string{"first", "second", "third"})
|
||||
assert.Equal(t, errs.ByType(ErrorTypePublic).Errors(), []string{"third"})
|
||||
assert.Equal(t, errs.ByType(ErrorTypePrivate).Errors(), []string{"first", "second"})
|
||||
assert.Equal(t, errs.ByType(ErrorTypePublic|ErrorTypePrivate).Errors(), []string{"first", "second", "third"})
|
||||
assert.Equal(t, "third", errs.Last().Error())
|
||||
assert.Equal(t, []string{"first", "second", "third"}, errs.Errors())
|
||||
assert.Equal(t, []string{"third"}, errs.ByType(ErrorTypePublic).Errors())
|
||||
assert.Equal(t, []string{"first", "second"}, errs.ByType(ErrorTypePrivate).Errors())
|
||||
assert.Equal(t, []string{"first", "second", "third"}, errs.ByType(ErrorTypePublic|ErrorTypePrivate).Errors())
|
||||
assert.Empty(t, errs.ByType(ErrorTypeBind))
|
||||
assert.Empty(t, errs.ByType(ErrorTypeBind).String())
|
||||
|
||||
assert.Equal(t, errs.String(), `Error #01: first
|
||||
assert.Equal(t, `Error #01: first
|
||||
Error #02: second
|
||||
Meta: some data
|
||||
Error #03: third
|
||||
Meta: map[status:400]
|
||||
`)
|
||||
assert.Equal(t, errs.JSON(), []interface{}{
|
||||
`, errs.String())
|
||||
assert.Equal(t, []interface{}{
|
||||
H{"error": "first"},
|
||||
H{"error": "second", "meta": "some data"},
|
||||
H{"error": "third", "status": "400"},
|
||||
})
|
||||
}, errs.JSON())
|
||||
jsonBytes, _ := json.Marshal(errs)
|
||||
assert.Equal(t, "[{\"error\":\"first\"},{\"error\":\"second\",\"meta\":\"some data\"},{\"error\":\"third\",\"status\":\"400\"}]", string(jsonBytes))
|
||||
errs = errorMsgs{
|
||||
{Err: errors.New("first"), Type: ErrorTypePrivate},
|
||||
}
|
||||
assert.Equal(t, errs.JSON(), H{"error": "first"})
|
||||
assert.Equal(t, H{"error": "first"}, errs.JSON())
|
||||
jsonBytes, _ = json.Marshal(errs)
|
||||
assert.Equal(t, string(jsonBytes), "{\"error\":\"first\"}")
|
||||
assert.Equal(t, "{\"error\":\"first\"}", string(jsonBytes))
|
||||
|
||||
errs = errorMsgs{}
|
||||
assert.Nil(t, errs.Last())
|
||||
|
||||
Reference in New Issue
Block a user