(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestHTTPEndpointPrepare(t *testing.T) { |
| 42 | cases := map[string]struct { |
| 43 | DSL func() |
| 44 | Headers []string |
| 45 | Params []string |
| 46 | Cookies []string |
| 47 | Error string |
| 48 | }{ |
| 49 | "valid": { |
| 50 | DSL: testdata.ValidRouteDSL, |
| 51 | Params: []string{"base_id", "id"}, |
| 52 | }, |
| 53 | "with parent": { |
| 54 | DSL: testdata.EndpointWithParentDSL, |
| 55 | Headers: []string{"pheader", "header"}, |
| 56 | Params: []string{"pparam", "param"}, |
| 57 | Cookies: []string{"pcookie", "cookie"}, |
| 58 | }, |
| 59 | "with parent revert": { |
| 60 | DSL: testdata.EndpointWithParentRevertDSL, |
| 61 | Headers: []string{"pheader", "header"}, |
| 62 | Params: []string{"pparam", "param"}, |
| 63 | Cookies: []string{"pcookie", "cookie"}, |
| 64 | }, |
| 65 | "error": { |
| 66 | DSL: testdata.EndpointRecursiveParentDSL, |
| 67 | Error: "service \"Parent\": Parent service Child is also child\nservice \"Child\": Parent service Parent is also child", |
| 68 | }, |
| 69 | } |
| 70 | for n, c := range cases { |
| 71 | t.Run(n, func(t *testing.T) { |
| 72 | if c.Error == "" { |
| 73 | root := expr.RunDSL(t, c.DSL) |
| 74 | e := root.API.HTTP.Services[len(root.API.HTTP.Services)-1].HTTPEndpoints[0] |
| 75 | |
| 76 | ht := expr.AsObject(e.Headers.Type) |
| 77 | if len(*ht) != len(c.Headers) { |
| 78 | t.Errorf("got %d headers, expected %d", len(*ht), len(c.Headers)) |
| 79 | } else { |
| 80 | for _, n := range c.Headers { |
| 81 | if ht.Attribute(n) == nil { |
| 82 | t.Errorf("header %q is missing", n) |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | ct := expr.AsObject(e.Cookies.Type) |
| 88 | if len(*ct) != len(c.Cookies) { |
| 89 | t.Errorf("got %d cookies, expected %d", len(*ct), len(c.Cookies)) |
| 90 | } else { |
| 91 | for _, n := range c.Cookies { |
| 92 | if ct.Attribute(n) == nil { |
| 93 | t.Errorf("cookie %q is missing", n) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | pt := expr.AsObject(e.Params.Type) |
nothing calls this directly
no test coverage detected