(t *testing.T)
| 1024 | } |
| 1025 | |
| 1026 | func TestHostForAPIHost(t *testing.T) { |
| 1027 | tests := []struct { |
| 1028 | name string |
| 1029 | apiHosts map[string]string |
| 1030 | lookup string |
| 1031 | wantHost string |
| 1032 | wantFound bool |
| 1033 | }{ |
| 1034 | { |
| 1035 | name: "no hosts configure an api_host", |
| 1036 | lookup: "api-gateway.example.com", |
| 1037 | wantFound: false, |
| 1038 | }, |
| 1039 | { |
| 1040 | name: "a host configures the api_host", |
| 1041 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 1042 | lookup: "api-gateway.example.com", |
| 1043 | wantHost: "github.com", |
| 1044 | wantFound: true, |
| 1045 | }, |
| 1046 | { |
| 1047 | name: "matching is case insensitive", |
| 1048 | apiHosts: map[string]string{"github.com": "API-gateway.example.com"}, |
| 1049 | lookup: "api-gateway.example.com", |
| 1050 | wantHost: "github.com", |
| 1051 | wantFound: true, |
| 1052 | }, |
| 1053 | { |
| 1054 | name: "an unrelated api_host does not match", |
| 1055 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 1056 | lookup: "api.other.com", |
| 1057 | wantFound: false, |
| 1058 | }, |
| 1059 | { |
| 1060 | name: "an empty lookup matches nothing", |
| 1061 | apiHosts: map[string]string{"github.com": "api-gateway.example.com"}, |
| 1062 | lookup: "", |
| 1063 | wantFound: false, |
| 1064 | }, |
| 1065 | { |
| 1066 | name: "the right host is chosen when several configure an api_host", |
| 1067 | apiHosts: map[string]string{"github.com": "api-gateway.example.com", "ghe.io": "api.ghe.io"}, |
| 1068 | lookup: "api.ghe.io", |
| 1069 | wantHost: "ghe.io", |
| 1070 | wantFound: true, |
| 1071 | }, |
| 1072 | { |
| 1073 | // Best effort: map iteration order is randomized, so this case |
| 1074 | // only hopes to catch an ordering regression rather than |
| 1075 | // guaranteeing it on every run. |
| 1076 | name: "the first lexical match is returned when several matches found", |
| 1077 | apiHosts: map[string]string{"A.github.com": "api-gateway.example.com", "a.github.com": "api-gateway.example.com"}, |
| 1078 | lookup: "api-gateway.example.com", |
| 1079 | wantHost: "A.github.com", |
| 1080 | wantFound: true, |
| 1081 | }, |
| 1082 | } |
| 1083 |
nothing calls this directly
no test coverage detected