blob: 74ac4617381a668523162c55d1409c9ac440ccdf [file] [log] [blame]
Jamie Hannafordf0cd1652014-11-04 10:54:11 +01001package vips
Jamie Hannaford2841a532014-11-04 11:05:42 +01002
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
11const (
Jamie Hannaford491ea5d2014-11-04 11:59:37 +010012 lbID = 12345
13 vipID = 67890
14 vipID2 = 67891
Jamie Hannaford2841a532014-11-04 11:05:42 +010015)
16
17func 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 Hannafordf7e8e1a2014-11-04 11:48:46 +010042
43func 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 Hannaford491ea5d2014-11-04 11:59:37 +010066
67func 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
79func 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}