@@ -2286,3 +2286,49 @@ func TestVersion(t *testing.T) {
2286
2286
test .That (t , err , test .ShouldBeNil )
2287
2287
test .That (t , md , test .ShouldResemble , version )
2288
2288
}
2289
+
2290
+ func TestListTunnels (t * testing.T ) {
2291
+ logger := logging .NewTestLogger (t )
2292
+ listener , err := net .Listen ("tcp" , "localhost:0" )
2293
+ test .That (t , err , test .ShouldBeNil )
2294
+ gServer := grpc .NewServer ()
2295
+
2296
+ expectedTTEs := []config.TrafficTunnelEndpoint {
2297
+ {
2298
+ Port : 9090 ,
2299
+ ConnectionTimeout : 20 * time .Second ,
2300
+ },
2301
+ {
2302
+ Port : 27017 ,
2303
+ ConnectionTimeout : 40 * time .Millisecond ,
2304
+ },
2305
+ {
2306
+ Port : 23654 ,
2307
+ },
2308
+ }
2309
+ injectRobot := & inject.Robot {
2310
+ ResourceNamesFunc : func () []resource.Name { return nil },
2311
+ ResourceRPCAPIsFunc : func () []resource.RPCAPI { return nil },
2312
+ MachineStatusFunc : func (ctx context.Context ) (robot.MachineStatus , error ) {
2313
+ return robot.MachineStatus {State : robot .StateRunning }, nil
2314
+ },
2315
+ ListTunnelsFunc : func (ctx context.Context ) ([]config.TrafficTunnelEndpoint , error ) {
2316
+ return expectedTTEs , nil
2317
+ },
2318
+ }
2319
+
2320
+ pb .RegisterRobotServiceServer (gServer , server .New (injectRobot ))
2321
+
2322
+ go gServer .Serve (listener )
2323
+ defer gServer .Stop ()
2324
+
2325
+ client , err := New (context .Background (), listener .Addr ().String (), logger )
2326
+ test .That (t , err , test .ShouldBeNil )
2327
+ defer func () {
2328
+ test .That (t , client .Close (context .Background ()), test .ShouldBeNil )
2329
+ }()
2330
+
2331
+ ttes , err := client .ListTunnels (context .Background ())
2332
+ test .That (t , err , test .ShouldBeNil )
2333
+ test .That (t , ttes , test .ShouldResemble , expectedTTEs )
2334
+ }
0 commit comments