| 5 | ) |
| 6 | |
| 7 | func TestAPIExprSchemes(t *testing.T) { |
| 8 | cases := map[string]struct { |
| 9 | expr APIExpr |
| 10 | expected []string |
| 11 | }{ |
| 12 | "default scheme": { |
| 13 | expr: APIExpr{ |
| 14 | Servers: []*ServerExpr{{}}, |
| 15 | }, |
| 16 | expected: nil, |
| 17 | }, |
| 18 | "single scheme": { |
| 19 | expr: APIExpr{ |
| 20 | Servers: []*ServerExpr{{ |
| 21 | Hosts: []*HostExpr{ |
| 22 | {URIs: []URIExpr{"http://example.com"}}, |
| 23 | }}, |
| 24 | }, |
| 25 | }, |
| 26 | expected: []string{"http"}, |
| 27 | }, |
| 28 | "multiple schemes": { |
| 29 | expr: APIExpr{ |
| 30 | Servers: []*ServerExpr{{ |
| 31 | Hosts: []*HostExpr{{URIs: []URIExpr{"http://example.com"}}}, |
| 32 | }, { |
| 33 | Hosts: []*HostExpr{{URIs: []URIExpr{"https://example.net"}}}, |
| 34 | }}, |
| 35 | }, |
| 36 | expected: []string{"http", "https"}, |
| 37 | }, |
| 38 | } |
| 39 | for k, tc := range cases { |
| 40 | if actual := tc.expr.Schemes(); len(tc.expected) != len(actual) { |
| 41 | t.Errorf("%s: expected the number of scheme values to match %d got %d ", k, len(tc.expected), len(actual)) |
| 42 | } else { |
| 43 | for i, v := range actual { |
| 44 | if v != tc.expected[i] { |
| 45 | t.Errorf("%s: got %#v, expected %#v at index %d", k, v, tc.expected[i], i) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestAPIExprEvalName(t *testing.T) { |
| 53 | cases := map[string]struct { |