Jon Perritt | 07d11fe | 2015-03-17 23:09:04 -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/publicips" |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | ) |
| 13 | |
| 14 | func TestPublicIPs(t *testing.T) { |
| 15 | c := newClient(t) |
| 16 | ipID := testListIPs(t, c) |
| 17 | sID := testGetIP(t, c, ipID) |
| 18 | testListIPsForServer(t, c, sID) |
| 19 | } |
| 20 | |
| 21 | func testListIPs(t *testing.T, c *gophercloud.ServiceClient) string { |
| 22 | allPages, err := publicips.List(c).AllPages() |
| 23 | th.AssertNoErr(t, err) |
| 24 | allip, err := publicips.ExtractPublicIPs(allPages) |
| 25 | fmt.Printf("Listing all public IPs: %+v\n\n", allip) |
| 26 | var ipID string |
| 27 | if len(allip) > 0 { |
| 28 | ipID = allip[0].ID |
| 29 | } |
| 30 | return ipID |
| 31 | } |
| 32 | |
| 33 | func testGetIP(t *testing.T, c *gophercloud.ServiceClient, ipID string) string { |
| 34 | ip, err := publicips.Get(c, ipID).Extract() |
| 35 | th.AssertNoErr(t, err) |
| 36 | fmt.Printf("Retrieved public IP (%s): %+v\n\n", ipID, ip) |
| 37 | return ip.CloudServer.ID |
| 38 | } |
| 39 | |
| 40 | func testListIPsForServer(t *testing.T, c *gophercloud.ServiceClient, sID string) { |
| 41 | allPages, err := publicips.ListForServer(c, sID).AllPages() |
| 42 | th.AssertNoErr(t, err) |
| 43 | allip, err := publicips.ExtractPublicIPs(allPages) |
| 44 | fmt.Printf("Listing all public IPs for server (%s): %+v\n\n", sID, allip) |
| 45 | } |