blob: 85ac931b9ca6fce4a404a914656b1a449f915105 [file] [log] [blame]
Jon Perritt63b3ec02015-03-17 23:00:52 -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/lbpools"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func TestLBPools(t *testing.T) {
15 c := newClient(t)
16 pID := testListPools(t, c)
17 testGetPools(t, c, pID)
18 nID := testListNodes(t, c, pID)
19 testListNodeDetails(t, c, pID)
20 testGetNode(t, c, pID, nID)
21 testGetNodeDetails(t, c, pID, nID)
22}
23
24func testListPools(t *testing.T, c *gophercloud.ServiceClient) string {
25 allPages, err := lbpools.List(c).AllPages()
26 th.AssertNoErr(t, err)
27 allp, err := lbpools.ExtractPools(allPages)
28 fmt.Printf("Listing all LB pools: %+v\n\n", allp)
29 var pID string
30 if len(allp) > 0 {
31 pID = allp[0].ID
32 }
33 return pID
34}
35
36func testGetPools(t *testing.T, c *gophercloud.ServiceClient, pID string) {
37 p, err := lbpools.Get(c, pID).Extract()
38 th.AssertNoErr(t, err)
39 fmt.Printf("Retrieved LB pool: %+v\n\n", p)
40}
41
42func testListNodes(t *testing.T, c *gophercloud.ServiceClient, pID string) string {
43 allPages, err := lbpools.ListNodes(c, pID).AllPages()
44 th.AssertNoErr(t, err)
45 alln, err := lbpools.ExtractNodes(allPages)
46 fmt.Printf("Listing all LB pool nodes for pool (%s): %+v\n\n", pID, alln)
47 var nID string
48 if len(alln) > 0 {
49 nID = alln[0].ID
50 }
51 return nID
52}
53
54func testListNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID string) {
55 allPages, err := lbpools.ListNodesDetails(c, pID).AllPages()
56 th.AssertNoErr(t, err)
57 alln, err := lbpools.ExtractNodesDetails(allPages)
58 fmt.Printf("Listing all LB pool nodes details for pool (%s): %+v\n\n", pID, alln)
59}
60
61func testGetNode(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
62 n, err := lbpools.GetNode(c, pID, nID).Extract()
63 th.AssertNoErr(t, err)
64 fmt.Printf("Retrieved LB node: %+v\n\n", n)
65}
66
67func testGetNodeDetails(t *testing.T, c *gophercloud.ServiceClient, pID, nID string) {
68 n, err := lbpools.GetNodeDetails(c, pID, nID).Extract()
69 th.AssertNoErr(t, err)
70 fmt.Printf("Retrieved LB node details: %+v\n\n", n)
71}