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