github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/acceptance/openstack/networking/v2/routes/route_test.go (about) 1 package routes 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/acceptance/clients" 7 "github.com/huaweicloud/golangsdk/acceptance/openstack/networking/v2/peering" 8 "github.com/huaweicloud/golangsdk/acceptance/tools" 9 "github.com/huaweicloud/golangsdk/openstack/networking/v2/peerings" 10 "github.com/huaweicloud/golangsdk/openstack/networking/v2/routes" 11 ) 12 13 func TestRouteList(t *testing.T) { 14 client, err := clients.NewNetworkV2Client() 15 if err != nil { 16 t.Fatalf("Unable to create a route client: %v", err) 17 } 18 19 listOpts := routes.ListOpts{} 20 pages, err := routes.List(client, listOpts).AllPages() 21 if err != nil { 22 t.Fatalf("Unable to list routers: %v", err) 23 } 24 25 allRoutes, err := routes.ExtractRoutes(pages) 26 if err != nil { 27 t.Errorf("Failed to extract routes: %v", err) 28 } 29 30 for _, router := range allRoutes { 31 tools.PrintResource(t, router) 32 } 33 } 34 35 func TestRoutesCRUD(t *testing.T) { 36 37 clientV2, peerClientV2, clientV1, peerClientV1, peeringConn := peering.InitiatePeeringConnCommonTasks(t) 38 39 _, err := peerings.Accept(peerClientV2, peeringConn.ID).ExtractResult() 40 if err != nil { 41 t.Fatalf("Unable to accept peering request: %v", err) 42 } 43 44 // Create a Route 45 route, err := CreateRoute(t, clientV2, peeringConn) 46 47 if err != nil { 48 t.Fatalf("Unable to create route: %v", err) 49 } 50 51 defer peering.DeletePeeringConnNResources(t, clientV2, clientV1, peerClientV1, peeringConn) 52 defer DeleteRoute(t, clientV2, route.RouteID) 53 54 tools.PrintResource(t, route) 55 56 newRoute, err := routes.Get(clientV2, route.RouteID).Extract() 57 if err != nil { 58 t.Fatalf("Unable to retrieve route: %v", err) 59 } 60 61 tools.PrintResource(t, newRoute) 62 }