TestErrorSlice() — gin Function Reference
Architecture documentation for the TestErrorSlice() function in errors_test.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD 1fcac52d_1e1a_2e1e_248a_7095185a3d24["TestErrorSlice()"] bd4678df_f6bd_26e2_4f83_00536939b6d9["errors_test.go"] 1fcac52d_1e1a_2e1e_248a_7095185a3d24 -->|defined in| bd4678df_f6bd_26e2_4f83_00536939b6d9 style 1fcac52d_1e1a_2e1e_248a_7095185a3d24 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
errors_test.go lines 68–108
func TestErrorSlice(t *testing.T) {
errs := errorMsgs{
{Err: errors.New("first"), Type: ErrorTypePrivate},
{Err: errors.New("second"), Type: ErrorTypePrivate, Meta: "some data"},
{Err: errors.New("third"), Type: ErrorTypePublic, Meta: H{"status": "400"}},
}
assert.Equal(t, errs, errs.ByType(ErrorTypeAny))
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, `Error #01: first
Error #02: second
Meta: some data
Error #03: third
Meta: map[status:400]
`, errs.String())
assert.Equal(t, []any{
H{"error": "first"},
H{"error": "second", "meta": "some data"},
H{"error": "third", "status": "400"},
}, errs.JSON())
jsonBytes, _ := json.API.Marshal(errs)
assert.JSONEq(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, H{"error": "first"}, errs.JSON())
jsonBytes, _ = json.API.Marshal(errs)
assert.JSONEq(t, "{\"error\":\"first\"}", string(jsonBytes))
errs = errorMsgs{}
assert.Nil(t, errs.Last())
assert.Nil(t, errs.JSON())
assert.Empty(t, errs.String())
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestErrorSlice() do?
TestErrorSlice() is a function in the gin codebase, defined in errors_test.go.
Where is TestErrorSlice() defined?
TestErrorSlice() is defined in errors_test.go at line 68.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free