blob: 8dc62703ba70b0a80c33e61dbed0d1030ecd3f20 [file] [log] [blame]
Jon Perritt07d11fe2015-03-17 23:09:04 -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/publicips"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func 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
21func 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
33func 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
40func 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}