@@ -16,8 +16,9 @@ import (
1616)
1717
1818func TestListRoutes (t * testing.T ) {
19- Options .VPCNames = "test"
19+ Options .VPCNames = "test,abc "
2020 vpcIDs ["test" ] = 1
21+ vpcIDs ["abc" ] = 2
2122 Options .EnableRouteController = true
2223
2324 nodeID := 123
@@ -36,7 +37,7 @@ func TestListRoutes(t *testing.T) {
3637 assert .NoError (t , err )
3738
3839 client .EXPECT ().ListInstances (gomock .Any (), gomock .Any ()).Times (1 ).Return ([]linodego.Instance {}, nil )
39- client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return ([]linodego.VPCIP {}, nil )
40+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return ([]linodego.VPCIP {}, nil )
4041 routes , err := routeController .ListRoutes (ctx , "test" )
4142 assert .NoError (t , err )
4243 assert .Empty (t , routes )
@@ -59,7 +60,7 @@ func TestListRoutes(t *testing.T) {
5960 assert .NoError (t , err )
6061
6162 client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
62- client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return ([]linodego.VPCIP {}, nil )
63+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return ([]linodego.VPCIP {}, nil )
6364 routes , err := routeController .ListRoutes (ctx , "test" )
6465 assert .NoError (t , err )
6566 assert .Empty (t , routes )
@@ -85,7 +86,7 @@ func TestListRoutes(t *testing.T) {
8586 assert .NoError (t , err )
8687
8788 client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
88- client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (noRoutesInVPC , nil )
89+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (4 ).Return (noRoutesInVPC , nil )
8990 routes , err := routeController .ListRoutes (ctx , "test" )
9091 assert .NoError (t , err )
9192 assert .Empty (t , routes )
@@ -126,7 +127,7 @@ func TestListRoutes(t *testing.T) {
126127 assert .NoError (t , err )
127128
128129 client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
129- client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (routesInVPC , nil )
130+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (4 ).Return (routesInVPC , nil )
130131 routes , err := routeController .ListRoutes (ctx , "test" )
131132 assert .NoError (t , err )
132133 assert .NotEmpty (t , routes )
@@ -167,11 +168,73 @@ func TestListRoutes(t *testing.T) {
167168 assert .NoError (t , err )
168169
169170 client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
170- client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (routesInDifferentVPC , nil )
171+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (4 ).Return (routesInDifferentVPC , nil )
171172 routes , err := routeController .ListRoutes (ctx , "test" )
172173 assert .NoError (t , err )
173174 assert .Empty (t , routes )
174175 })
176+
177+ t .Run ("should return routes if multiple instances exists, connected to VPCs and ip_ranges configured" , func (t * testing.T ) {
178+ ctx := context .Background ()
179+ ctrl := gomock .NewController (t )
180+ defer ctrl .Finish ()
181+ client := mocks .NewMockClient (ctrl )
182+ routeController , err := newRoutes (client )
183+ assert .NoError (t , err )
184+
185+ vpcIP2 := "10.0.0.3"
186+ addressRange3 := "10.192.40.0/24"
187+ addressRange4 := "10.192.50.0/24"
188+
189+ validInstance2 := linodego.Instance {
190+ ID : 124 ,
191+ Label : "mock-instance2" ,
192+ Type : linodeType ,
193+ Region : region ,
194+ IPv4 : []* net.IP {& publicIPv4 , & privateIPv4 },
195+ }
196+
197+ routesInVPC2 := []linodego.VPCIP {
198+ {
199+ Address : & vpcIP2 ,
200+ AddressRange : nil ,
201+ VPCID : vpcIDs ["abc" ],
202+ NAT1To1 : nil ,
203+ LinodeID : 124 ,
204+ },
205+ {
206+ Address : nil ,
207+ AddressRange : & addressRange3 ,
208+ VPCID : vpcIDs ["abc" ],
209+ NAT1To1 : nil ,
210+ LinodeID : 124 ,
211+ },
212+ {
213+ Address : nil ,
214+ AddressRange : & addressRange4 ,
215+ VPCID : vpcIDs ["abc" ],
216+ NAT1To1 : nil ,
217+ LinodeID : 124 ,
218+ },
219+ }
220+
221+ client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance , validInstance2 }, nil )
222+ c1 := client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return (routesInVPC , nil )
223+ c2 := client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).After (c1 ).Times (1 ).Return (routesInVPC2 , nil )
224+ c3 := client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).After (c2 ).Times (1 ).Return (routesInVPC , nil )
225+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).After (c3 ).Times (1 ).Return (routesInVPC2 , nil )
226+ routes , err := routeController .ListRoutes (ctx , "test" )
227+ assert .NoError (t , err )
228+ assert .NotEmpty (t , routes )
229+ cidrs := make ([]string , len (routes ))
230+ for _ , value := range routes {
231+ cidrs = append (cidrs , value .DestinationCIDR )
232+ }
233+ assert .Contains (t , cidrs , addressRange1 )
234+ assert .Contains (t , cidrs , addressRange2 )
235+ assert .Contains (t , cidrs , addressRange3 )
236+ assert .Contains (t , cidrs , addressRange4 )
237+ })
175238}
176239
177240func TestCreateRoute (t * testing.T ) {
0 commit comments