TestErrorSlice() — gin Function Reference
Architecture documentation for the TestErrorSlice() function in errors_test.go from the gin codebase.
Entity Profile
Dependency Diagram
graph TD 8b556fe6_5501_5955_11c7_651f666b8c97["TestErrorSlice()"] 3582eb3f_bdf6_8b25_a7d8_18e77eefb341["Error()"] 8b556fe6_5501_5955_11c7_651f666b8c97 -->|calls| 3582eb3f_bdf6_8b25_a7d8_18e77eefb341 style 8b556fe6_5501_5955_11c7_651f666b8c97 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
Calls
Source
Frequently Asked Questions
What does TestErrorSlice() do?
TestErrorSlice() is a function in the gin codebase.
What does TestErrorSlice() call?
TestErrorSlice() calls 1 function(s): Error.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free