blob: df979f8a6643975cc9367ccbbc5c32c347511a48 [file] [log] [blame]
Joe Topjiandee32222015-02-09 23:56:26 +00001package floatingip
2
3import (
4 "testing"
5
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud/pagination"
7 th "github.com/gophercloud/gophercloud/testhelper"
8 "github.com/gophercloud/gophercloud/testhelper/client"
Joe Topjiandee32222015-02-09 23:56:26 +00009)
10
11func 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
29func 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
41func 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
51func 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 Topjiand97fe9b2015-09-17 02:08:38 +000060func TestAssociateDeprecated(t *testing.T) {
Joe Topjiandee32222015-02-09 23:56:26 +000061 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 Topjiand97fe9b2015-09-17 02:08:38 +000071func 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 Topjian94e4cc52016-01-05 17:01:18 +000081 err := AssociateInstance(client.ServiceClient(), associateOpts).ExtractErr()
Joe Topjiand97fe9b2015-09-17 02:08:38 +000082 th.AssertNoErr(t, err)
83}
84
85func 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 Topjian94e4cc52016-01-05 17:01:18 +000096 err := AssociateInstance(client.ServiceClient(), associateOpts).ExtractErr()
Joe Topjiand97fe9b2015-09-17 02:08:38 +000097 th.AssertNoErr(t, err)
98}
99
100func TestDisassociateDeprecated(t *testing.T) {
Joe Topjiandee32222015-02-09 23:56:26 +0000101 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 Topjiand97fe9b2015-09-17 02:08:38 +0000110
Joe Topjian94e4cc52016-01-05 17:01:18 +0000111func TestDisassociateInstance(t *testing.T) {
Joe Topjiand97fe9b2015-09-17 02:08:38 +0000112 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 Topjian94e4cc52016-01-05 17:01:18 +0000121 err := DisassociateInstance(client.ServiceClient(), associateOpts).ExtractErr()
Joe Topjiand97fe9b2015-09-17 02:08:38 +0000122 th.AssertNoErr(t, err)
123}