MCPcopy Index your code
hub / github.com/zalando/skipper / TestSelectAlgorithm

Function TestSelectAlgorithm

loadbalancer/algorithm_test.go:15–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func 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})

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
DoMethod · 0.95
NewEndpointRegistryFunction · 0.92
NewAlgorithmProviderFunction · 0.85
DoMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…