@@ -380,3 +380,132 @@ func assertRestCall(s *NetTestSuite, method, path, body string) {
380380 assert .JSONEq (s .T (), body , s .LastRequestBody )
381381 }
382382}
383+
384+ func (s * NetTestSuite ) TestTunnels () {
385+ s .ResponseFunc = func (w http.ResponseWriter , r * http.Request ) {
386+ w .Write ([]byte (`{
387+ "kind": "tm:net:tunnels:tunnel:tunnelcollectionstate",
388+ "selfLink": "https://localhost/mgmt/tm/net/tunnels/tunnel?ver=13.1.1.2",
389+ "items": [
390+ {
391+ "kind": "tm:net:tunnels:tunnel:tunnelstate",
392+ "name": "http-tunnel",
393+ "partition": "Common",
394+ "fullPath": "/Common/http-tunnel",
395+ "generation": 1,
396+ "selfLink": "https://localhost/mgmt/tm/net/tunnels/tunnel/~Common~http-tunnel?ver=13.1.1.2",
397+ "autoLasthop": "default",
398+ "description": "Tunnel for http-explicit profile",
399+ "idleTimeout": 300,
400+ "ifIndex": 912,
401+ "key": 0,
402+ "localAddress": "any6",
403+ "mode": "bidirectional",
404+ "mtu": 0,
405+ "profile": "/Common/tcp-forward",
406+ "profileReference": {
407+ "link": "https://localhost/mgmt/tm/net/tunnels/tcp-forward/~Common~tcp-forward?ver=13.1.1.2"
408+ },
409+ "remoteAddress": "any6",
410+ "secondaryAddress": "any6",
411+ "tos": "preserve",
412+ "transparent": "disabled",
413+ "usePmtu": "enabled"
414+ },
415+ {
416+ "kind": "tm:net:tunnels:tunnel:tunnelstate",
417+ "name": "socks-tunnel",
418+ "partition": "Common",
419+ "fullPath": "/Common/socks-tunnel",
420+ "generation": 1,
421+ "selfLink": "https://localhost/mgmt/tm/net/tunnels/tunnel/~Common~socks-tunnel?ver=13.1.1.2",
422+ "autoLasthop": "default",
423+ "description": "Tunnel for socks profile",
424+ "idleTimeout": 300,
425+ "ifIndex": 928,
426+ "key": 0,
427+ "localAddress": "any6",
428+ "mode": "bidirectional",
429+ "mtu": 0,
430+ "profile": "/Common/tcp-forward",
431+ "profileReference": {
432+ "link": "https://localhost/mgmt/tm/net/tunnels/tcp-forward/~Common~tcp-forward?ver=13.1.1.2"
433+ },
434+ "remoteAddress": "any6",
435+ "secondaryAddress": "any6",
436+ "tos": "preserve",
437+ "transparent": "disabled",
438+ "usePmtu": "enabled"
439+ }
440+ ]
441+ }` ))
442+ }
443+
444+ tunnels , err := s .Client .Tunnels ()
445+
446+ assert .Nil (s .T (), err )
447+ assertRestCall (s , "GET" , "/mgmt/tm/net/tunnels/tunnel" , "" )
448+ assert .Equal (s .T (), 2 , len (tunnels .Tunnels ))
449+ assert .Equal (s .T (), "http-tunnel" , tunnels .Tunnels [0 ].Name )
450+ assert .Equal (s .T (), "socks-tunnel" , tunnels .Tunnels [1 ].Name )
451+ }
452+
453+ func (s * NetTestSuite ) TestGetTunnel () {
454+ s .ResponseFunc = func (w http.ResponseWriter , r * http.Request ) {
455+ w .Write ([]byte (`{
456+ "autoLasthop": "default",
457+ "description": "Tunnel for http-explicit profile",
458+ "fullPath": "/Common/http-tunnel",
459+ "generation": 1,
460+ "idleTimeout": 300,
461+ "ifIndex": 112,
462+ "key": 0,
463+ "kind": "tm:net:tunnels:tunnel:tunnelstate",
464+ "localAddress": "any6",
465+ "mode": "bidirectional",
466+ "mtu": 0,
467+ "name": "http-tunnel",
468+ "partition": "Common",
469+ "profile": "/Common/tcp-forward",
470+ "profileReference": {
471+ "link": "https://localhost/mgmt/tm/net/tunnels/tcp-forward/~Common~tcp-forward?ver=14.1.0.3"
472+ },
473+ "remoteAddress": "any6",
474+ "secondaryAddress": "any6",
475+ "selfLink": "https://localhost/mgmt/tm/net/tunnels/tunnel/~Common~http-tunnel?ver=14.1.0.3",
476+ "tos": "preserve",
477+ "transparent": "disabled",
478+ "usePmtu": "enabled"
479+ }` ))
480+ }
481+
482+ tunnel , err := s .Client .GetTunnel ("http-tunnel" )
483+
484+ assert .Nil (s .T (), err )
485+ assertRestCall (s , "GET" , "/mgmt/tm/net/tunnels/tunnel/~Common~http-tunnel" , "" )
486+ assert .Equal (s .T (), "http-tunnel" , tunnel .Name )
487+ assert .Equal (s .T (), "/Common/tcp-forward" , tunnel .Profile )
488+ }
489+
490+ func (s * NetTestSuite ) TestCreateTunnel () {
491+ err := s .Client .CreateTunnel ("some-foo-tunnel" , "/Common/some-foo-profile" )
492+
493+ assert .Nil (s .T (), err )
494+ assertRestCall (s , "POST" , "/mgmt/tm/net/tunnels/tunnel" , `{"name":"some-foo-tunnel", "profile":"/Common/some-foo-profile"}` )
495+ }
496+
497+ func (s * NetTestSuite ) TestDeleteTunnel () {
498+ err := s .Client .DeleteTunnel ("some-foo-tunnel" )
499+
500+ assert .Nil (s .T (), err )
501+ assertRestCall (s , "DELETE" , "/mgmt/tm/net/tunnels/tunnel/some-foo-tunnel" , "" )
502+ }
503+
504+ func (s * NetTestSuite ) TestModifyTunnel () {
505+ tunnel := & Tunnel {Transparent : "enabled" }
506+
507+ err := s .Client .ModifyTunnel ("some-foo-tunnel" , tunnel )
508+
509+ assert .Nil (s .T (), err )
510+ assertRestCall (s , "PUT" , "/mgmt/tm/net/tunnels/tunnel/some-foo-tunnel" , `{"transparent":"enabled"}` )
511+ }
0 commit comments