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

Function TestHTTPAuthorizationMapping

expr/http_endpoint_test.go:271–304  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestHTTPAuthorizationMapping(t *testing.T) {
272 cases := []struct {
273 Name string
274 DSL func()
275 ExpectedHeader string
276 }{{
277 Name: "explicit",
278 DSL: testdata.ExplicitAuthHeaderDSL,
279 ExpectedHeader: "token",
280 }, {
281 Name: "implicit",
282 DSL: testdata.ImplicitAuthHeaderDSL,
283 ExpectedHeader: "Authorization",
284 },
285 }
286 for _, tc := range cases {
287 t.Run(tc.Name, func(t *testing.T) {
288 root := expr.RunDSL(t, tc.DSL)
289 e := root.API.HTTP.Services[0].HTTPEndpoints[0]
290 if e.Headers == nil {
291 t.Errorf("got endpoint without header, expected endpoint with HTTP header")
292 return
293 }
294 if len(*expr.AsObject(e.Headers.Type)) != 1 {
295 t.Errorf("got %d, expected 1 attribute in endpoint headers", len(*expr.AsObject(e.Headers.Type)))
296 return
297 }
298 n := e.Headers.ElemName("token")
299 if n != tc.ExpectedHeader {
300 t.Errorf("got %q, expected %q attribute in endpoint headers", n, tc.ExpectedHeader)
301 }
302 })
303 }
304}

Callers

nothing calls this directly

Calls 4

RunDSLFunction · 0.92
AsObjectFunction · 0.92
ElemNameMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected