MCPcopy Create free account
hub / github.com/goadesign/goa / TestHTTPErrorResponseValidation

Function TestHTTPErrorResponseValidation

expr/http_error_test.go:10–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestHTTPErrorResponseValidation(t *testing.T) {
11 cases := []struct {
12 Name string
13 DSL func()
14 Error string
15 }{
16 {"header string error", stringErrorResponseWithHeadersDSL, ""},
17 {"header object result", objectErrorResponseWithHeadersDSL, ""},
18 {"header array result", arrayErrorResponseWithHeadersDSL, ""},
19 {"header map result", mapErrorResponseWithHeadersDSL, `HTTP response of service "MapErrorResponseWithHeaders" HTTP endpoint "Method": attribute "foo" used in HTTP headers must be a primitive type or an array of primitive types.`},
20 {"implicit object in header", implicitObjectErrorResponseWithHeadersDSL, `HTTP response of service "ArrayObjectErrorResponseWithHeaders" HTTP endpoint "Method": attribute "foo" used in HTTP headers must be a primitive type or an array of primitive types.`},
21 {"array of object in header", arrayObjectErrorResponseWithHeadersDSL, `HTTP response of service "ArrayObjectErrorResponseWithHeaders" HTTP endpoint "Method": Array error type is mapped to an HTTP header but is not an array of primitive types.`},
22 {"map in header", mapErrorTypeResponseWithHeadersDSL, `HTTP response of service "MapErrorTypeResponseWithHeaders" HTTP endpoint "Method": error type must be a primitive type or an array of primitive types.`},
23 {"missing header result attribute", missingHeaderErrorAttributeDSL, `HTTP response of service "MissingHeaderErrorAttribute" HTTP endpoint "Method": header "bar" has no equivalent attribute in error type, use notation 'attribute_name:header_name' to identify corresponding error type attribute.`},
24 }
25 for _, c := range cases {
26 t.Run(c.Name, func(t *testing.T) {
27 if c.Error == "" {
28 expr.RunDSL(t, c.DSL)
29 } else {
30 err := expr.RunInvalidDSL(t, c.DSL)
31 if err.Error() != c.Error {
32 t.Errorf("\ngot error %q\nexpected %q", err.Error(), c.Error)
33 }
34 }
35 })
36 }
37}
38
39var stringErrorResponseWithHeadersDSL = func() {
40 Service("StringErrorResponseWithHeaders", func() {

Callers

nothing calls this directly

Calls 4

RunDSLFunction · 0.92
RunInvalidDSLFunction · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected