(t *testing.T)
| 1118 | } |
| 1119 | |
| 1120 | func TestAPIHostForHost(t *testing.T) { |
| 1121 | tests := []struct { |
| 1122 | name string |
| 1123 | apiHost string |
| 1124 | lookup string |
| 1125 | wantAPIHost string |
| 1126 | wantFound bool |
| 1127 | }{ |
| 1128 | { |
| 1129 | name: "the host has no api_host set", |
| 1130 | lookup: "github.com", |
| 1131 | wantFound: false, |
| 1132 | }, |
| 1133 | { |
| 1134 | name: "the host configures an api_host", |
| 1135 | apiHost: "api-gateway.example.com", |
| 1136 | lookup: "github.com", |
| 1137 | wantAPIHost: "api-gateway.example.com", |
| 1138 | wantFound: true, |
| 1139 | }, |
| 1140 | { |
| 1141 | name: "an empty host matches nothing", |
| 1142 | apiHost: "api-gateway.example.com", |
| 1143 | lookup: "", |
| 1144 | wantFound: false, |
| 1145 | }, |
| 1146 | { |
| 1147 | name: "an unknown host matches nothing", |
| 1148 | apiHost: "api-gateway.example.com", |
| 1149 | lookup: "ghe.io", |
| 1150 | wantFound: false, |
| 1151 | }, |
| 1152 | } |
| 1153 | |
| 1154 | for _, tt := range tests { |
| 1155 | t.Run(tt.name, func(t *testing.T) { |
| 1156 | authCfg := newTestAuthConfig(t) |
| 1157 | _, err := authCfg.Login("github.com", "test-user", "test-token", "https", false) |
| 1158 | require.NoError(t, err) |
| 1159 | if tt.apiHost != "" { |
| 1160 | authCfg.cfg.Set([]string{hostsKey, "github.com", apiHostKey}, tt.apiHost) |
| 1161 | } |
| 1162 | |
| 1163 | apiHost, found := authCfg.APIHostForHost(tt.lookup) |
| 1164 | |
| 1165 | require.Equal(t, tt.wantFound, found) |
| 1166 | require.Equal(t, tt.wantAPIHost, apiHost) |
| 1167 | }) |
| 1168 | } |
| 1169 | } |
nothing calls this directly
no test coverage detected