MCPcopy
hub / github.com/koderover/zadig / TestErrors

Function TestErrors

pkg/tool/errors/errors_test.go:25–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestErrors(t *testing.T) {
26 assert := assert.New(t)
27
28 httpErr := NewHTTPError(400, "testErr", "error description")
29 assert.Equal(400, httpErr.Code())
30 assert.Equal("testErr", httpErr.Error())
31 assert.Equal("error description", httpErr.Desc())
32
33 httpErr.AddDesc("error description updated")
34 assert.Equal("error description updated", httpErr.Desc())
35
36 err2 := NewWithDesc(httpErr, "new error with desc")
37 tmp2, ok := err2.(*HTTPError)
38 assert.True(ok)
39 assert.Equal("new error with desc", tmp2.Desc())
40
41 extras := map[string]interface{}{
42 "key": "extra",
43 }
44 err3 := NewWithExtras(httpErr, "new error with extras", extras)
45 tmp3, ok := err3.(*HTTPError)
46 assert.True(ok)
47 assert.Equal("new error with extras", tmp3.Desc())
48 assert.Equal(extras, tmp3.Extra())
49
50 code, message := ErrorMessage(httpErr)
51 assert.Equal(400, code)
52 assert.Equal(400, message["code"])
53 assert.Equal(httpErr.Error(), message["message"])
54 assert.Equal(httpErr.Desc(), message["description"])
55}

Callers

nothing calls this directly

Calls 11

CodeMethod · 0.95
ErrorMethod · 0.95
DescMethod · 0.95
AddDescMethod · 0.95
NewHTTPErrorFunction · 0.85
NewWithDescFunction · 0.85
NewWithExtrasFunction · 0.85
EqualMethod · 0.80
ErrorMessageFunction · 0.70
DescMethod · 0.65
ExtraMethod · 0.65

Tested by

no test coverage detected