MCPcopy
hub / github.com/labstack/echo / TestStatusCode

Function TestStatusCode

httperror_test.go:71–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestStatusCode(t *testing.T) {
72 var testCases = []struct {
73 name string
74 err error
75 expect int
76 }{
77 {
78 name: "ok, HTTPError",
79 err: &HTTPError{Code: http.StatusNotFound},
80 expect: http.StatusNotFound,
81 },
82 {
83 name: "ok, sentinel error",
84 err: ErrNotFound,
85 expect: http.StatusNotFound,
86 },
87 {
88 name: "ok, wrapped HTTPError",
89 err: fmt.Errorf("wrapped: %w", &HTTPError{Code: http.StatusTeapot}),
90 expect: http.StatusTeapot,
91 },
92 {
93 name: "nok, normal error",
94 err: errors.New("error"),
95 expect: 0,
96 },
97 {
98 name: "nok, nil",
99 err: nil,
100 expect: 0,
101 },
102 }
103
104 for _, tc := range testCases {
105 t.Run(tc.name, func(t *testing.T) {
106 assert.Equal(t, tc.expect, StatusCode(tc.err))
107 })
108 }
109}
110
111func TestResolveResponseStatus(t *testing.T) {
112 someErr := errors.New("some error")

Callers

nothing calls this directly

Calls 1

StatusCodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…