Jamie Hannaford | f0cd165 | 2014-11-04 10:54:11 +0100 | [diff] [blame] | 1 | package vips |
Jamie Hannaford | 2841a53 | 2014-11-04 11:05:42 +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 ( |
Jamie Hannaford | 491ea5d | 2014-11-04 11:59:37 +0100 | [diff] [blame] | 12 | lbID = 12345 |
| 13 | vipID = 67890 |
| 14 | vipID2 = 67891 |
Jamie Hannaford | 2841a53 | 2014-11-04 11:05:42 +0100 | [diff] [blame] | 15 | ) |
| 16 | |
| 17 | func TestList(t *testing.T) { |
| 18 | th.SetupHTTP() |
| 19 | defer th.TeardownHTTP() |
| 20 | |
| 21 | mockListResponse(t, lbID) |
| 22 | |
| 23 | count := 0 |
| 24 | |
| 25 | err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) { |
| 26 | count++ |
| 27 | actual, err := ExtractVIPs(page) |
| 28 | th.AssertNoErr(t, err) |
| 29 | |
| 30 | expected := []VIP{ |
| 31 | VIP{ID: 1000, Address: "206.10.10.210", Type: "PUBLIC"}, |
| 32 | } |
| 33 | |
| 34 | th.CheckDeepEquals(t, expected, actual) |
| 35 | |
| 36 | return true, nil |
| 37 | }) |
| 38 | |
| 39 | th.AssertNoErr(t, err) |
| 40 | th.AssertEquals(t, 1, count) |
| 41 | } |
Jamie Hannaford | f7e8e1a | 2014-11-04 11:48:46 +0100 | [diff] [blame] | 42 | |
| 43 | func TestCreate(t *testing.T) { |
| 44 | th.SetupHTTP() |
| 45 | defer th.TeardownHTTP() |
| 46 | |
| 47 | mockCreateResponse(t, lbID) |
| 48 | |
| 49 | opts := CreateOpts{ |
| 50 | Type: "PUBLIC", |
| 51 | Version: "IPV6", |
| 52 | } |
| 53 | |
| 54 | vip, err := Create(client.ServiceClient(), lbID, opts).Extract() |
| 55 | th.AssertNoErr(t, err) |
| 56 | |
| 57 | expected := &VIP{ |
| 58 | Address: "fd24:f480:ce44:91bc:1af2:15ff:0000:0002", |
| 59 | ID: 9000134, |
| 60 | Type: "PUBLIC", |
| 61 | Version: "IPV6", |
| 62 | } |
| 63 | |
| 64 | th.CheckDeepEquals(t, expected, vip) |
| 65 | } |
Jamie Hannaford | 491ea5d | 2014-11-04 11:59:37 +0100 | [diff] [blame] | 66 | |
| 67 | func TestBulkDelete(t *testing.T) { |
| 68 | th.SetupHTTP() |
| 69 | defer th.TeardownHTTP() |
| 70 | |
| 71 | ids := []int{vipID, vipID2} |
| 72 | |
| 73 | mockBatchDeleteResponse(t, lbID, ids) |
| 74 | |
| 75 | err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr() |
| 76 | th.AssertNoErr(t, err) |
| 77 | } |
| 78 | |
| 79 | func TestDelete(t *testing.T) { |
| 80 | th.SetupHTTP() |
| 81 | defer th.TeardownHTTP() |
| 82 | |
| 83 | mockDeleteResponse(t, lbID, vipID) |
| 84 | |
| 85 | err := Delete(client.ServiceClient(), lbID, vipID).ExtractErr() |
| 86 | th.AssertNoErr(t, err) |
| 87 | } |