blob: c2a3e124e73fc08cb09803a0626933c79c1b52ea [file] [log] [blame]
Jamie Hannaford924c09d2014-11-19 12:05:38 +01001package secgroups
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
15 mockListGroupsResponse(t)
16
17 count := 0
18
19 err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
20 count++
21 actual, err := ExtractSecurityGroups(page)
22 if err != nil {
23 t.Errorf("Failed to extract users: %v", err)
24 return false, err
25 }
26
27 expected := []SecurityGroup{
28 SecurityGroup{
29 ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
30 Description: "default",
31 Name: "default",
32 Rules: []Rule{},
33 TenantID: "openstack",
34 },
35 }
36
37 th.CheckDeepEquals(t, expected, actual)
38
39 return true, nil
40 })
41
42 th.AssertNoErr(t, err)
43 th.AssertEquals(t, 1, count)
44}
Jamie Hannaforda493e642014-11-19 12:40:30 +010045
46func TestCreate(t *testing.T) {
47 th.SetupHTTP()
48 defer th.TeardownHTTP()
49
50 mockCreateGroupResponse(t)
51
52 opts := CreateOpts{
53 Name: "test",
54 Description: "something",
55 }
56
57 group, err := Create(client.ServiceClient(), opts).Extract()
58 th.AssertNoErr(t, err)
59
60 expected := &SecurityGroup{
61 ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
62 Name: "test",
63 Description: "something",
64 TenantID: "openstack",
65 Rules: []Rule{},
66 }
67 th.AssertDeepEquals(t, expected, group)
68}