(t *testing.T)
| 978 | } |
| 979 | |
| 980 | func TestHostForAPIHost(t *testing.T) { |
| 981 | tests := []struct { |
| 982 | name string |
| 983 | apiHosts map[string]string |
| 984 | lookup string |
| 985 | wantHost string |
| 986 | wantFound bool |
| 987 | }{ |
| 988 | { |
| 989 | name: "no hosts configure an api_host", |
| 990 | lookup: "api-gateway.example.com", |
| 991 | wantFound: false, |
| 992 | }, |
| 993 | { |
| 994 | name: "a host configures the api_host", |
| 995 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 996 | lookup: "api-gateway.example.com", |
| 997 | wantHost: "github.com", |
| 998 | wantFound: true, |
| 999 | }, |
| 1000 | { |
| 1001 | name: "matching is case insensitive", |
| 1002 | apiHosts: map[string]string{"github.com": "API-gateway.example.com"}, |
| 1003 | lookup: "api-gateway.example.com", |
| 1004 | wantHost: "github.com", |
| 1005 | wantFound: true, |
| 1006 | }, |
| 1007 | { |
| 1008 | name: "an unrelated api_host does not match", |
| 1009 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 1010 | lookup: "api.other.com", |
| 1011 | wantFound: false, |
| 1012 | }, |
| 1013 | { |
| 1014 | name: "an empty lookup matches nothing", |
| 1015 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 1016 | lookup: "", |
| 1017 | wantFound: false, |
| 1018 | }, |
| 1019 | { |
| 1020 | name: "the right host is chosen when several configure an api_host", |
| 1021 | apiHosts: map[string]string{"github.com": "api-gateway.example.com", "ghe.io": "api.ghe.io"}, |
| 1022 | lookup: "api.ghe.io", |
| 1023 | wantHost: "ghe.io", |
| 1024 | wantFound: true, |
| 1025 | }, |
| 1026 | { |
| 1027 | // Best effort: map iteration order is randomized, so this case |
| 1028 | // only hopes to catch an ordering regression rather than |
| 1029 | // guaranteeing it on every run. |
| 1030 | name: "the first lexical match is returned when several matches found", |
| 1031 | apiHosts: map[string]string{"A.github.com": "api-gateway.example.com", "a.github.com": "api-gateway.example.com"}, |
| 1032 | lookup: "api-gateway.example.com", |
| 1033 | wantHost: "A.github.com", |
| 1034 | wantFound: true, |
| 1035 | }, |
| 1036 | } |
| 1037 |
nothing calls this directly
no test coverage detected