Jamie Hannaford | b6927c1 | 2014-11-03 10:31:26 +0100 | [diff] [blame] | 1 | package nodes |
Jamie Hannaford | 3cfa00a | 2014-11-03 11:16:35 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | lbID = 12345 |
| 13 | nodeID = 67890 |
| 14 | ) |
| 15 | |
| 16 | func TestList(t *testing.T) { |
| 17 | th.SetupHTTP() |
| 18 | defer th.TeardownHTTP() |
| 19 | |
| 20 | mockListResponse(t, lbID) |
| 21 | |
| 22 | count := 0 |
| 23 | |
| 24 | err := List(client.ServiceClient(), lbID, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 25 | count++ |
| 26 | actual, err := ExtractNodes(page) |
| 27 | th.AssertNoErr(t, err) |
| 28 | |
| 29 | expected := []Node{ |
| 30 | Node{ |
| 31 | ID: 410, |
| 32 | Address: "10.1.1.1", |
| 33 | Port: 80, |
| 34 | Condition: ENABLED, |
| 35 | Status: ONLINE, |
| 36 | Weight: 3, |
| 37 | Type: PRIMARY, |
| 38 | }, |
| 39 | Node{ |
| 40 | ID: 411, |
| 41 | Address: "10.1.1.2", |
| 42 | Port: 80, |
| 43 | Condition: ENABLED, |
| 44 | Status: ONLINE, |
| 45 | Weight: 8, |
| 46 | Type: SECONDARY, |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | th.CheckDeepEquals(t, expected, actual) |
| 51 | |
| 52 | return true, nil |
| 53 | }) |
| 54 | |
| 55 | th.AssertNoErr(t, err) |
| 56 | th.AssertEquals(t, 1, count) |
| 57 | } |
Jamie Hannaford | ed8b89a | 2014-11-03 12:24:19 +0100 | [diff] [blame^] | 58 | |
| 59 | func TestCreate(t *testing.T) { |
| 60 | th.SetupHTTP() |
| 61 | defer th.TeardownHTTP() |
| 62 | |
| 63 | mockCreateResponse(t, lbID) |
| 64 | |
| 65 | opts := CreateOpts{ |
| 66 | CreateOpt{ |
| 67 | Address: "10.2.2.3", |
| 68 | Port: 80, |
| 69 | Condition: ENABLED, |
| 70 | Type: PRIMARY, |
| 71 | }, |
| 72 | CreateOpt{ |
| 73 | Address: "10.2.2.4", |
| 74 | Port: 81, |
| 75 | Condition: ENABLED, |
| 76 | Type: SECONDARY, |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | page := Create(client.ServiceClient(), lbID, opts) |
| 81 | |
| 82 | actual, err := page.ExtractNodes() |
| 83 | th.AssertNoErr(t, err) |
| 84 | |
| 85 | expected := []Node{ |
| 86 | Node{ |
| 87 | ID: 185, |
| 88 | Address: "10.2.2.3", |
| 89 | Port: 80, |
| 90 | Condition: ENABLED, |
| 91 | Status: ONLINE, |
| 92 | Weight: 1, |
| 93 | Type: PRIMARY, |
| 94 | }, |
| 95 | Node{ |
| 96 | ID: 186, |
| 97 | Address: "10.2.2.4", |
| 98 | Port: 81, |
| 99 | Condition: ENABLED, |
| 100 | Status: ONLINE, |
| 101 | Weight: 1, |
| 102 | Type: SECONDARY, |
| 103 | }, |
| 104 | } |
| 105 | |
| 106 | th.CheckDeepEquals(t, expected, actual) |
| 107 | } |