File: lbpools_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 (71 lines) | stat: -rw-r--r-- 2,045 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// +build acceptance

package v3

import (
	"fmt"
	"testing"

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

func TestLBPools(t *testing.T) {
	c := newClient(t)
	pID := testListPools(t, c)
	testGetPools(t, c, pID)
	nID := testListNodes(t, c, pID)
	testListNodeDetails(t, c, pID)
	testGetNode(t, c, pID, nID)
	testGetNodeDetails(t, c, pID, nID)
}

func testListPools(t *testing.T, c *gophercloud.ServiceClient) string {
	allPages, err := lbpools.List(c).AllPages()
	th.AssertNoErr(t, err)
	allp, err := lbpools.ExtractPools(allPages)
	fmt.Printf("Listing all LB pools: %+v\n\n", allp)
	var pID string
	if len(allp) > 0 {
		pID = allp[0].ID
	}
	return pID
}

func testGetPools(t *testing.T, c *gophercloud.ServiceClient, pID string) {
	p, err := lbpools.Get(c, pID).Extract()
	th.AssertNoErr(t, err)
	fmt.Printf("Retrieved LB pool: %+v\n\n", p)
}

func testListNodes(t *testing.T, c *gophercloud.ServiceClient, pID string) string {
	allPages, err := lbpools.ListNodes(c, pID).AllPages()
	th.AssertNoErr(t, err)
	alln, err := lbpools.ExtractNodes(allPages)
	fmt.Printf("Listing all LB pool nodes for pool (%s): %+v\n\n", pID, alln)
	var nID string
	if len(alln) > 0 {
		nID = alln[0].ID
	}
	return nID
}

func testListNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID string) {
	allPages, err := lbpools.ListNodesDetails(c, pID).AllPages()
	th.AssertNoErr(t, err)
	alln, err := lbpools.ExtractNodesDetails(allPages)
	fmt.Printf("Listing all LB pool nodes details for pool (%s): %+v\n\n", pID, alln)
}

func testGetNode(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
	n, err := lbpools.GetNode(c, pID, nID).Extract()
	th.AssertNoErr(t, err)
	fmt.Printf("Retrieved LB node: %+v\n\n", n)
}

func testGetNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
	n, err := lbpools.GetNodeDetails(c, pID, nID).Extract()
	th.AssertNoErr(t, err)
	fmt.Printf("Retrieved LB node details: %+v\n\n", n)
}