@@ -29,17 +29,17 @@ type fakeAgentServiceConnectServer struct {
29
29
}
30
30
31
31
func TestAddRemoveBackends (t * testing.T ) {
32
- conn1 := new (fakeAgentServiceConnectServer )
33
- conn12 := new (fakeAgentServiceConnectServer )
34
- conn2 := new (fakeAgentServiceConnectServer )
35
- conn22 := new (fakeAgentServiceConnectServer )
36
- conn3 := new (fakeAgentServiceConnectServer )
32
+ backend1 := NewBackend ( new (fakeAgentServiceConnectServer ) )
33
+ backend12 := NewBackend ( new (fakeAgentServiceConnectServer ) )
34
+ backend2 := NewBackend ( new (fakeAgentServiceConnectServer ) )
35
+ backend22 := NewBackend ( new (fakeAgentServiceConnectServer ) )
36
+ backend3 := NewBackend ( new (fakeAgentServiceConnectServer ) )
37
37
38
38
p := NewDefaultBackendManager ()
39
39
40
- p .AddBackend ("agent1" , header .UID , conn1 )
41
- p .RemoveBackend ("agent1" , header .UID , conn1 )
42
- expectedBackends := make (map [string ][]* backend )
40
+ p .AddBackend ("agent1" , header .UID , backend1 )
41
+ p .RemoveBackend ("agent1" , header .UID , backend1 )
42
+ expectedBackends := make (map [string ][]Backend )
43
43
expectedAgentIDs := []string {}
44
44
if e , a := expectedBackends , p .backends ; ! reflect .DeepEqual (e , a ) {
45
45
t .Errorf ("expected %v, got %v" , e , a )
@@ -49,21 +49,21 @@ func TestAddRemoveBackends(t *testing.T) {
49
49
}
50
50
51
51
p = NewDefaultBackendManager ()
52
- p .AddBackend ("agent1" , header .UID , conn1 )
53
- p .AddBackend ("agent1" , header .UID , conn12 )
52
+ p .AddBackend ("agent1" , header .UID , backend1 )
53
+ p .AddBackend ("agent1" , header .UID , backend12 )
54
54
// Adding the same connection again should be a no-op.
55
- p .AddBackend ("agent1" , header .UID , conn12 )
56
- p .AddBackend ("agent2" , header .UID , conn2 )
57
- p .AddBackend ("agent2" , header .UID , conn22 )
58
- p .AddBackend ("agent3" , header .UID , conn3 )
59
- p .RemoveBackend ("agent2" , header .UID , conn22 )
60
- p .RemoveBackend ("agent2" , header .UID , conn2 )
61
- p .RemoveBackend ("agent1" , header .UID , conn1 )
62
- // This is invalid. agent1 doesn't have conn3 . This should be a no-op.
63
- p .RemoveBackend ("agent1" , header .UID , conn3 )
64
- expectedBackends = map [string ][]* backend {
65
- "agent1" : {newBackend ( conn12 ) },
66
- "agent3" : {newBackend ( conn3 ) },
55
+ p .AddBackend ("agent1" , header .UID , backend12 )
56
+ p .AddBackend ("agent2" , header .UID , backend2 )
57
+ p .AddBackend ("agent2" , header .UID , backend22 )
58
+ p .AddBackend ("agent3" , header .UID , backend3 )
59
+ p .RemoveBackend ("agent2" , header .UID , backend22 )
60
+ p .RemoveBackend ("agent2" , header .UID , backend2 )
61
+ p .RemoveBackend ("agent1" , header .UID , backend1 )
62
+ // This is invalid. agent1 doesn't have backend3 . This should be a no-op.
63
+ p .RemoveBackend ("agent1" , header .UID , backend3 )
64
+ expectedBackends = map [string ][]Backend {
65
+ "agent1" : {backend12 },
66
+ "agent3" : {backend3 },
67
67
}
68
68
expectedAgentIDs = []string {"agent1" , "agent3" }
69
69
if e , a := expectedBackends , p .backends ; ! reflect .DeepEqual (e , a ) {
@@ -75,17 +75,17 @@ func TestAddRemoveBackends(t *testing.T) {
75
75
}
76
76
77
77
func TestAddRemoveBackendsWithDefaultRoute (t * testing.T ) {
78
- conn1 := new (fakeAgentServiceConnectServer )
79
- conn12 := new (fakeAgentServiceConnectServer )
80
- conn2 := new (fakeAgentServiceConnectServer )
81
- conn22 := new (fakeAgentServiceConnectServer )
82
- conn3 := new (fakeAgentServiceConnectServer )
78
+ backend1 := NewBackend ( new (fakeAgentServiceConnectServer ) )
79
+ backend12 := NewBackend ( new (fakeAgentServiceConnectServer ) )
80
+ backend2 := NewBackend ( new (fakeAgentServiceConnectServer ) )
81
+ backend22 := NewBackend ( new (fakeAgentServiceConnectServer ) )
82
+ backend3 := NewBackend ( new (fakeAgentServiceConnectServer ) )
83
83
84
84
p := NewDefaultRouteBackendManager ()
85
85
86
- p .AddBackend ("agent1" , header .DefaultRoute , conn1 )
87
- p .RemoveBackend ("agent1" , header .DefaultRoute , conn1 )
88
- expectedBackends := make (map [string ][]* backend )
86
+ p .AddBackend ("agent1" , header .DefaultRoute , backend1 )
87
+ p .RemoveBackend ("agent1" , header .DefaultRoute , backend1 )
88
+ expectedBackends := make (map [string ][]Backend )
89
89
expectedAgentIDs := []string {}
90
90
if e , a := expectedBackends , p .backends ; ! reflect .DeepEqual (e , a ) {
91
91
t .Errorf ("expected %v, got %v" , e , a )
@@ -98,22 +98,22 @@ func TestAddRemoveBackendsWithDefaultRoute(t *testing.T) {
98
98
}
99
99
100
100
p = NewDefaultRouteBackendManager ()
101
- p .AddBackend ("agent1" , header .DefaultRoute , conn1 )
102
- p .AddBackend ("agent1" , header .DefaultRoute , conn12 )
101
+ p .AddBackend ("agent1" , header .DefaultRoute , backend1 )
102
+ p .AddBackend ("agent1" , header .DefaultRoute , backend12 )
103
103
// Adding the same connection again should be a no-op.
104
- p .AddBackend ("agent1" , header .DefaultRoute , conn12 )
105
- p .AddBackend ("agent2" , header .DefaultRoute , conn2 )
106
- p .AddBackend ("agent2" , header .DefaultRoute , conn22 )
107
- p .AddBackend ("agent3" , header .DefaultRoute , conn3 )
108
- p .RemoveBackend ("agent2" , header .DefaultRoute , conn22 )
109
- p .RemoveBackend ("agent2" , header .DefaultRoute , conn2 )
110
- p .RemoveBackend ("agent1" , header .DefaultRoute , conn1 )
104
+ p .AddBackend ("agent1" , header .DefaultRoute , backend12 )
105
+ p .AddBackend ("agent2" , header .DefaultRoute , backend2 )
106
+ p .AddBackend ("agent2" , header .DefaultRoute , backend22 )
107
+ p .AddBackend ("agent3" , header .DefaultRoute , backend3 )
108
+ p .RemoveBackend ("agent2" , header .DefaultRoute , backend22 )
109
+ p .RemoveBackend ("agent2" , header .DefaultRoute , backend2 )
110
+ p .RemoveBackend ("agent1" , header .DefaultRoute , backend1 )
111
111
// This is invalid. agent1 doesn't have conn3. This should be a no-op.
112
- p .RemoveBackend ("agent1" , header .DefaultRoute , conn3 )
112
+ p .RemoveBackend ("agent1" , header .DefaultRoute , backend3 )
113
113
114
- expectedBackends = map [string ][]* backend {
115
- "agent1" : {newBackend ( conn12 ) },
116
- "agent3" : {newBackend ( conn3 ) },
114
+ expectedBackends = map [string ][]Backend {
115
+ "agent1" : {backend12 },
116
+ "agent3" : {backend3 },
117
117
}
118
118
expectedDefaultRouteAgentIDs := []string {"agent1" , "agent3" }
119
119
0 commit comments