blob: 2c6287e9f773b7aec202762894967c58608fef2a [file] [log] [blame]
Jon Perritt0eeeb0c2015-03-17 22:38:31 -06001// +build acceptance
2
3package v3
4
5import (
6 "fmt"
7 "testing"
8
9 "github.com/rackspace/gophercloud"
10 "github.com/rackspace/gophercloud/rackspace/rackconnect/v3/cloudnetworks"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func TestCloudNetworks(t *testing.T) {
15 c := newClient(t)
Jon Perrittb7b39352015-03-17 23:00:24 -060016 cnID := testListNetworks(t, c)
17 testGetNetworks(t, c, cnID)
Jon Perritt0eeeb0c2015-03-17 22:38:31 -060018}
19
Jon Perrittb7b39352015-03-17 23:00:24 -060020func testListNetworks(t *testing.T, c *gophercloud.ServiceClient) string {
Jon Perritt0eeeb0c2015-03-17 22:38:31 -060021 allPages, err := cloudnetworks.List(c).AllPages()
22 th.AssertNoErr(t, err)
23 allcn, err := cloudnetworks.ExtractCloudNetworks(allPages)
Jon Perrittb7b39352015-03-17 23:00:24 -060024 fmt.Printf("Listing all cloud networks: %+v\n\n", allcn)
Jon Perritt0eeeb0c2015-03-17 22:38:31 -060025 var cnID string
26 if len(allcn) > 0 {
27 cnID = allcn[0].ID
28 }
29 return cnID
30}
31
Jon Perrittb7b39352015-03-17 23:00:24 -060032func testGetNetworks(t *testing.T, c *gophercloud.ServiceClient, id string) {
Jon Perritt0eeeb0c2015-03-17 22:38:31 -060033 cn, err := cloudnetworks.Get(c, id).Extract()
34 th.AssertNoErr(t, err)
Jon Perrittb7b39352015-03-17 23:00:24 -060035 fmt.Printf("Retrieved cloud network: %+v\n\n", cn)
Jon Perritt0eeeb0c2015-03-17 22:38:31 -060036}