blob: ed2460edc67436f2d145f5c1c3d0eb16217f183c [file] [log] [blame]
Joe Topjiandee32222015-02-09 23:56:26 +00001package floatingip
2
3import (
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
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
60func TestAssociate(t *testing.T) {
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
71func TestDisassociate(t *testing.T) {
72 th.SetupHTTP()
73 defer th.TeardownHTTP()
74 HandleDisassociateSuccessfully(t)
75 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
76 fip := "10.10.10.2"
77
78 err := Disassociate(client.ServiceClient(), serverId, fip).ExtractErr()
79 th.AssertNoErr(t, err)
80}