| 66 | } |
| 67 | |
| 68 | func TestAPIExprFinalize(t *testing.T) { |
| 69 | cases := map[string]struct { |
| 70 | api *APIExpr |
| 71 | expected []string |
| 72 | }{ |
| 73 | "empty name, empty server": { |
| 74 | api: &APIExpr{}, |
| 75 | expected: []string{"Default server for api"}, |
| 76 | }, |
| 77 | "empty server": { |
| 78 | api: &APIExpr{ |
| 79 | Name: "my api", |
| 80 | }, |
| 81 | expected: []string{"Default server for my api"}, |
| 82 | }, |
| 83 | "with server": { |
| 84 | api: &APIExpr{ |
| 85 | Name: "my api", |
| 86 | Servers: []*ServerExpr{{Description: "my server"}}, |
| 87 | }, |
| 88 | expected: []string{"my server"}, |
| 89 | }, |
| 90 | } |
| 91 | |
| 92 | for k, tc := range cases { |
| 93 | Root = &RootExpr{} |
| 94 | tc.api.Finalize() |
| 95 | |
| 96 | if actual := tc.api.Servers; len(tc.expected) != len(actual) { |
| 97 | t.Errorf("%s: expected the number of servers to match %d got %d ", k, len(tc.expected), len(actual)) |
| 98 | } else { |
| 99 | for i, v := range actual { |
| 100 | if v.Description != tc.expected[i] { |
| 101 | t.Errorf("%s: got %#v, expected %#v at index %d", k, v, tc.expected[i], i) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | func TestApiExpr_Hash(t *testing.T) { |
| 109 | cases := map[string]struct { |