File: publicips_test.go

package info (click to toggle)
golang-github-rackspace-gophercloud 1.0.0%2Bgit20161013.1012.e00690e8-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,148 kB
  • ctags: 6,414
  • sloc: sh: 16; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// +build acceptance

package v3

import (
	"fmt"
	"testing"

	"github.com/rackspace/gophercloud"
	"github.com/rackspace/gophercloud/rackspace/rackconnect/v3/publicips"
	th "github.com/rackspace/gophercloud/testhelper"
)

func TestPublicIPs(t *testing.T) {
	c := newClient(t)
	ipID := testListIPs(t, c)
	sID := testGetIP(t, c, ipID)
	testListIPsForServer(t, c, sID)
}

func testListIPs(t *testing.T, c *gophercloud.ServiceClient) string {
	allPages, err := publicips.List(c).AllPages()
	th.AssertNoErr(t, err)
	allip, err := publicips.ExtractPublicIPs(allPages)
	fmt.Printf("Listing all public IPs: %+v\n\n", allip)
	var ipID string
	if len(allip) > 0 {
		ipID = allip[0].ID
	}
	return ipID
}

func testGetIP(t *testing.T, c *gophercloud.ServiceClient, ipID string) string {
	ip, err := publicips.Get(c, ipID).Extract()
	th.AssertNoErr(t, err)
	fmt.Printf("Retrieved public IP (%s): %+v\n\n", ipID, ip)
	return ip.CloudServer.ID
}

func testListIPsForServer(t *testing.T, c *gophercloud.ServiceClient, sID string) {
	allPages, err := publicips.ListForServer(c, sID).AllPages()
	th.AssertNoErr(t, err)
	allip, err := publicips.ExtractPublicIPs(allPages)
	fmt.Printf("Listing all public IPs for server (%s): %+v\n\n", sID, allip)
}