Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | func TestCloudNetworks(t *testing.T) { |
| 15 | c := newClient(t) |
Jon Perritt | b7b3935 | 2015-03-17 23:00:24 -0600 | [diff] [blame] | 16 | cnID := testListNetworks(t, c) |
| 17 | testGetNetworks(t, c, cnID) |
Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 18 | } |
| 19 | |
Jon Perritt | b7b3935 | 2015-03-17 23:00:24 -0600 | [diff] [blame] | 20 | func testListNetworks(t *testing.T, c *gophercloud.ServiceClient) string { |
Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 21 | allPages, err := cloudnetworks.List(c).AllPages() |
| 22 | th.AssertNoErr(t, err) |
| 23 | allcn, err := cloudnetworks.ExtractCloudNetworks(allPages) |
Jon Perritt | b7b3935 | 2015-03-17 23:00:24 -0600 | [diff] [blame] | 24 | fmt.Printf("Listing all cloud networks: %+v\n\n", allcn) |
Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 25 | var cnID string |
| 26 | if len(allcn) > 0 { |
| 27 | cnID = allcn[0].ID |
| 28 | } |
| 29 | return cnID |
| 30 | } |
| 31 | |
Jon Perritt | b7b3935 | 2015-03-17 23:00:24 -0600 | [diff] [blame] | 32 | func testGetNetworks(t *testing.T, c *gophercloud.ServiceClient, id string) { |
Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 33 | cn, err := cloudnetworks.Get(c, id).Extract() |
| 34 | th.AssertNoErr(t, err) |
Jon Perritt | b7b3935 | 2015-03-17 23:00:24 -0600 | [diff] [blame] | 35 | fmt.Printf("Retrieved cloud network: %+v\n\n", cn) |
Jon Perritt | 0eeeb0c | 2015-03-17 22:38:31 -0600 | [diff] [blame] | 36 | } |