Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 1 | package floatingip |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/pagination" |
| 7 | th "github.com/gophercloud/gophercloud/testhelper" |
| 8 | "github.com/gophercloud/gophercloud/testhelper/client" |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | func TestList(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | HandleListSuccessfully(t) |
| 15 | |
| 16 | count := 0 |
| 17 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 18 | count++ |
| 19 | actual, err := ExtractFloatingIPs(page) |
| 20 | th.AssertNoErr(t, err) |
| 21 | th.CheckDeepEquals(t, ExpectedFloatingIPsSlice, actual) |
| 22 | |
| 23 | return true, nil |
| 24 | }) |
| 25 | th.AssertNoErr(t, err) |
| 26 | th.CheckEquals(t, 1, count) |
| 27 | } |
| 28 | |
| 29 | func TestCreate(t *testing.T) { |
| 30 | th.SetupHTTP() |
| 31 | defer th.TeardownHTTP() |
| 32 | HandleCreateSuccessfully(t) |
| 33 | |
| 34 | actual, err := Create(client.ServiceClient(), CreateOpts{ |
| 35 | Pool: "nova", |
| 36 | }).Extract() |
| 37 | th.AssertNoErr(t, err) |
| 38 | th.CheckDeepEquals(t, &CreatedFloatingIP, actual) |
| 39 | } |
| 40 | |
| 41 | func TestGet(t *testing.T) { |
| 42 | th.SetupHTTP() |
| 43 | defer th.TeardownHTTP() |
| 44 | HandleGetSuccessfully(t) |
| 45 | |
| 46 | actual, err := Get(client.ServiceClient(), "2").Extract() |
| 47 | th.AssertNoErr(t, err) |
| 48 | th.CheckDeepEquals(t, &SecondFloatingIP, actual) |
| 49 | } |
| 50 | |
| 51 | func TestDelete(t *testing.T) { |
| 52 | th.SetupHTTP() |
| 53 | defer th.TeardownHTTP() |
| 54 | HandleDeleteSuccessfully(t) |
| 55 | |
| 56 | err := Delete(client.ServiceClient(), "1").ExtractErr() |
| 57 | th.AssertNoErr(t, err) |
| 58 | } |
| 59 | |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 60 | func TestAssociateDeprecated(t *testing.T) { |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 61 | th.SetupHTTP() |
| 62 | defer th.TeardownHTTP() |
| 63 | HandleAssociateSuccessfully(t) |
| 64 | serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" |
| 65 | fip := "10.10.10.2" |
| 66 | |
| 67 | err := Associate(client.ServiceClient(), serverId, fip).ExtractErr() |
| 68 | th.AssertNoErr(t, err) |
| 69 | } |
| 70 | |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 71 | func TestAssociate(t *testing.T) { |
| 72 | th.SetupHTTP() |
| 73 | defer th.TeardownHTTP() |
| 74 | HandleAssociateSuccessfully(t) |
| 75 | |
| 76 | associateOpts := AssociateOpts{ |
| 77 | ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", |
| 78 | FloatingIP: "10.10.10.2", |
| 79 | } |
| 80 | |
Joe Topjian | 94e4cc5 | 2016-01-05 17:01:18 +0000 | [diff] [blame] | 81 | err := AssociateInstance(client.ServiceClient(), associateOpts).ExtractErr() |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 82 | th.AssertNoErr(t, err) |
| 83 | } |
| 84 | |
| 85 | func TestAssociateFixed(t *testing.T) { |
| 86 | th.SetupHTTP() |
| 87 | defer th.TeardownHTTP() |
| 88 | HandleAssociateFixedSuccessfully(t) |
| 89 | |
| 90 | associateOpts := AssociateOpts{ |
| 91 | ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", |
| 92 | FloatingIP: "10.10.10.2", |
| 93 | FixedIP: "166.78.185.201", |
| 94 | } |
| 95 | |
Joe Topjian | 94e4cc5 | 2016-01-05 17:01:18 +0000 | [diff] [blame] | 96 | err := AssociateInstance(client.ServiceClient(), associateOpts).ExtractErr() |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 97 | th.AssertNoErr(t, err) |
| 98 | } |
| 99 | |
| 100 | func TestDisassociateDeprecated(t *testing.T) { |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 101 | th.SetupHTTP() |
| 102 | defer th.TeardownHTTP() |
| 103 | HandleDisassociateSuccessfully(t) |
| 104 | serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" |
| 105 | fip := "10.10.10.2" |
| 106 | |
| 107 | err := Disassociate(client.ServiceClient(), serverId, fip).ExtractErr() |
| 108 | th.AssertNoErr(t, err) |
| 109 | } |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 110 | |
Joe Topjian | 94e4cc5 | 2016-01-05 17:01:18 +0000 | [diff] [blame] | 111 | func TestDisassociateInstance(t *testing.T) { |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 112 | th.SetupHTTP() |
| 113 | defer th.TeardownHTTP() |
| 114 | HandleDisassociateSuccessfully(t) |
| 115 | |
| 116 | associateOpts := AssociateOpts{ |
| 117 | ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0", |
| 118 | FloatingIP: "10.10.10.2", |
| 119 | } |
| 120 | |
Joe Topjian | 94e4cc5 | 2016-01-05 17:01:18 +0000 | [diff] [blame] | 121 | err := DisassociateInstance(client.ServiceClient(), associateOpts).ExtractErr() |
Joe Topjian | d97fe9b | 2015-09-17 02:08:38 +0000 | [diff] [blame] | 122 | th.AssertNoErr(t, err) |
| 123 | } |