(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestSelectAlgorithm(t *testing.T) { |
| 16 | t.Run("not an LB route", func(t *testing.T) { |
| 17 | p := NewAlgorithmProvider() |
| 18 | r := &routing.Route{ |
| 19 | Route: eskip.Route{ |
| 20 | BackendType: eskip.NetworkBackend, |
| 21 | Backend: "https://www.example.org", |
| 22 | }, |
| 23 | } |
| 24 | |
| 25 | rr := p.Do([]*routing.Route{r}) |
| 26 | if len(rr) != 1 || len(rr[0].LBEndpoints) != 0 || rr[0].LBAlgorithm != nil { |
| 27 | t.Fatal("processed non-LB route") |
| 28 | } |
| 29 | }) |
| 30 | |
| 31 | t.Run("LB route with default algorithm", func(t *testing.T) { |
| 32 | p := NewAlgorithmProvider() |
| 33 | endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{}) |
| 34 | defer endpointRegistry.Close() |
| 35 | r := &routing.Route{ |
| 36 | Route: eskip.Route{ |
| 37 | BackendType: eskip.LBBackend, |
| 38 | LBEndpoints: []*eskip.LBEndpoint{{Address: "https://www.example.org"}}, |
| 39 | }, |
| 40 | } |
| 41 | |
| 42 | rr := p.Do([]*routing.Route{r}) |
| 43 | endpointRegistry.Do([]*routing.Route{r}) |
| 44 | if len(rr) != 1 { |
| 45 | t.Fatal("failed to process LB route") |
| 46 | } |
| 47 | |
| 48 | if len(rr[0].LBEndpoints) != 1 || |
| 49 | rr[0].LBEndpoints[0].Scheme != "https" || |
| 50 | rr[0].LBEndpoints[0].Host != "www.example.org:443" || |
| 51 | rr[0].LBEndpoints[0].Metrics == nil { |
| 52 | t.Fatal("failed to set the endpoints") |
| 53 | } |
| 54 | |
| 55 | if _, ok := rr[0].LBAlgorithm.(*roundRobin); !ok { |
| 56 | t.Fatal("failed to set the right algorithm") |
| 57 | } |
| 58 | }) |
| 59 | |
| 60 | t.Run("LB route with explicit round-robin algorithm", func(t *testing.T) { |
| 61 | p := NewAlgorithmProvider() |
| 62 | endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{}) |
| 63 | defer endpointRegistry.Close() |
| 64 | r := &routing.Route{ |
| 65 | Route: eskip.Route{ |
| 66 | BackendType: eskip.LBBackend, |
| 67 | LBAlgorithm: "roundRobin", |
| 68 | LBEndpoints: []*eskip.LBEndpoint{{Address: "https://www.example.org"}}, |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | rr := p.Do([]*routing.Route{r}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…