(t *testing.T)
| 226 | } |
| 227 | |
| 228 | func TestApply(t *testing.T) { |
| 229 | const R = 1000 |
| 230 | const N = 10 |
| 231 | eps := make([]string, 0, N) |
| 232 | for i := 0; i < N; i++ { |
| 233 | ep := fmt.Sprintf("http://127.0.0.1:123%d/foo", i) |
| 234 | eps = append(eps, ep) |
| 235 | } |
| 236 | |
| 237 | for _, tt := range []struct { |
| 238 | name string |
| 239 | expected int |
| 240 | algorithm routing.LBAlgorithm |
| 241 | algorithmName string |
| 242 | }{ |
| 243 | { |
| 244 | name: "random algorithm", |
| 245 | expected: N, |
| 246 | algorithm: newRandom(eps), |
| 247 | algorithmName: "random", |
| 248 | }, { |
| 249 | name: "roundrobin algorithm", |
| 250 | expected: N, |
| 251 | algorithm: newRoundRobin(eps), |
| 252 | algorithmName: "roundRobin", |
| 253 | }, { |
| 254 | name: "consistentHash algorithm", |
| 255 | expected: 1, |
| 256 | algorithm: newConsistentHash(eps), |
| 257 | algorithmName: "consistentHash", |
| 258 | }, { |
| 259 | name: "powerOfRandomNChoices algorithm", |
| 260 | expected: N, |
| 261 | algorithm: newPowerOfRandomNChoices(eps), |
| 262 | algorithmName: "powerOfRandomNChoices", |
| 263 | }} { |
| 264 | t.Run(tt.name, func(t *testing.T) { |
| 265 | req, _ := http.NewRequest("GET", "http://127.0.0.1:1234/foo", nil) |
| 266 | p := NewAlgorithmProvider() |
| 267 | endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{}) |
| 268 | defer endpointRegistry.Close() |
| 269 | r := &routing.Route{ |
| 270 | Route: eskip.Route{ |
| 271 | BackendType: eskip.LBBackend, |
| 272 | LBAlgorithm: tt.algorithmName, |
| 273 | LBEndpoints: eskip.NewLBEndpoints(eps), |
| 274 | }, |
| 275 | } |
| 276 | rt := p.Do([]*routing.Route{r}) |
| 277 | endpointRegistry.Do([]*routing.Route{r}) |
| 278 | |
| 279 | lbctx := &routing.LBContext{ |
| 280 | Request: req, |
| 281 | Route: rt[0], |
| 282 | LBEndpoints: rt[0].LBEndpoints, |
| 283 | } |
| 284 | |
| 285 | h := make(map[string]int) |
nothing calls this directly
no test coverage detected
searching dependent graphs…