github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/balancer/balancer_test.go (about) 1 package balancer 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/conn" 9 "github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint" 10 "github.com/ydb-platform/ydb-go-sdk/v3/internal/mock" 11 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" 12 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 13 ) 14 15 func TestEndpointsDiff(t *testing.T) { 16 for _, tt := range []struct { 17 newestEndpoints []endpoint.Endpoint 18 previousConns []conn.Conn 19 nodes []trace.EndpointInfo 20 added []trace.EndpointInfo 21 dropped []trace.EndpointInfo 22 }{ 23 { 24 newestEndpoints: []endpoint.Endpoint{ 25 &mock.Endpoint{AddrField: "1"}, 26 &mock.Endpoint{AddrField: "3"}, 27 &mock.Endpoint{AddrField: "2"}, 28 &mock.Endpoint{AddrField: "0"}, 29 }, 30 previousConns: []conn.Conn{ 31 &mock.Conn{AddrField: "2"}, 32 &mock.Conn{AddrField: "1"}, 33 &mock.Conn{AddrField: "0"}, 34 &mock.Conn{AddrField: "3"}, 35 }, 36 nodes: []trace.EndpointInfo{ 37 &mock.Endpoint{AddrField: "0"}, 38 &mock.Endpoint{AddrField: "1"}, 39 &mock.Endpoint{AddrField: "2"}, 40 &mock.Endpoint{AddrField: "3"}, 41 }, 42 added: []trace.EndpointInfo{}, 43 dropped: []trace.EndpointInfo{}, 44 }, 45 { 46 newestEndpoints: []endpoint.Endpoint{ 47 &mock.Endpoint{AddrField: "1"}, 48 &mock.Endpoint{AddrField: "3"}, 49 &mock.Endpoint{AddrField: "2"}, 50 &mock.Endpoint{AddrField: "0"}, 51 }, 52 previousConns: []conn.Conn{ 53 &mock.Conn{AddrField: "1"}, 54 &mock.Conn{AddrField: "0"}, 55 &mock.Conn{AddrField: "3"}, 56 }, 57 nodes: []trace.EndpointInfo{ 58 &mock.Endpoint{AddrField: "0"}, 59 &mock.Endpoint{AddrField: "1"}, 60 &mock.Endpoint{AddrField: "2"}, 61 &mock.Endpoint{AddrField: "3"}, 62 }, 63 added: []trace.EndpointInfo{ 64 &mock.Endpoint{AddrField: "2"}, 65 }, 66 dropped: []trace.EndpointInfo{}, 67 }, 68 { 69 newestEndpoints: []endpoint.Endpoint{ 70 &mock.Endpoint{AddrField: "1"}, 71 &mock.Endpoint{AddrField: "3"}, 72 &mock.Endpoint{AddrField: "0"}, 73 }, 74 previousConns: []conn.Conn{ 75 &mock.Conn{AddrField: "1"}, 76 &mock.Conn{AddrField: "2"}, 77 &mock.Conn{AddrField: "0"}, 78 &mock.Conn{AddrField: "3"}, 79 }, 80 nodes: []trace.EndpointInfo{ 81 &mock.Endpoint{AddrField: "0"}, 82 &mock.Endpoint{AddrField: "1"}, 83 &mock.Endpoint{AddrField: "3"}, 84 }, 85 added: []trace.EndpointInfo{}, 86 dropped: []trace.EndpointInfo{ 87 &mock.Endpoint{AddrField: "2"}, 88 }, 89 }, 90 { 91 newestEndpoints: []endpoint.Endpoint{ 92 &mock.Endpoint{AddrField: "1"}, 93 &mock.Endpoint{AddrField: "3"}, 94 &mock.Endpoint{AddrField: "0"}, 95 }, 96 previousConns: []conn.Conn{ 97 &mock.Conn{AddrField: "4"}, 98 &mock.Conn{AddrField: "7"}, 99 &mock.Conn{AddrField: "8"}, 100 }, 101 nodes: []trace.EndpointInfo{ 102 &mock.Endpoint{AddrField: "0"}, 103 &mock.Endpoint{AddrField: "1"}, 104 &mock.Endpoint{AddrField: "3"}, 105 }, 106 added: []trace.EndpointInfo{ 107 &mock.Endpoint{AddrField: "0"}, 108 &mock.Endpoint{AddrField: "1"}, 109 &mock.Endpoint{AddrField: "3"}, 110 }, 111 dropped: []trace.EndpointInfo{ 112 &mock.Endpoint{AddrField: "4"}, 113 &mock.Endpoint{AddrField: "7"}, 114 &mock.Endpoint{AddrField: "8"}, 115 }, 116 }, 117 } { 118 t.Run(xtest.CurrentFileLine(), func(t *testing.T) { 119 nodes, added, dropped := endpointsDiff(tt.newestEndpoints, tt.previousConns) 120 require.Equal(t, tt.nodes, nodes) 121 require.Equal(t, tt.added, added) 122 require.Equal(t, tt.dropped, dropped) 123 }) 124 } 125 }