blob: 9feff53154c6f83201b94920425bab2efe387b10 [file] [log] [blame]
ehdoub5066cd2016-11-10 22:15:42 +02001package testing
2
3import (
4 "testing"
ehdoub46ba5a2017-03-08 20:56:49 +02005 "time"
ehdoub5066cd2016-11-10 22:15:42 +02006
7 "github.com/gophercloud/gophercloud"
8 "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices"
9 th "github.com/gophercloud/gophercloud/testhelper"
10 "github.com/gophercloud/gophercloud/testhelper/client"
11)
12
13// Verifies that a security service can be created correctly
14func TestCreate(t *testing.T) {
15 th.SetupHTTP()
16 defer th.TeardownHTTP()
17
18 MockCreateResponse(t)
19
20 options := &securityservices.CreateOpts{
21 Name: "SecServ1",
22 Description: "Creating my first Security Service",
23 DNSIP: "10.0.0.0/24",
24 User: "demo",
25 Password: "***",
26 Type: "kerberos",
27 }
28
29 s, err := securityservices.Create(client.ServiceClient(), options).Extract()
30 th.AssertNoErr(t, err)
31
32 th.AssertEquals(t, s.Name, "SecServ1")
33 th.AssertEquals(t, s.Description, "Creating my first Security Service")
34 th.AssertEquals(t, s.User, "demo")
35 th.AssertEquals(t, s.DNSIP, "10.0.0.0/24")
36 th.AssertEquals(t, s.Password, "supersecret")
37 th.AssertEquals(t, s.Type, "kerberos")
38}
39
40// Verifies that a security service cannot be created without a type
41func TestCreateFails(t *testing.T) {
42 options := &securityservices.CreateOpts{
43 Name: "SecServ1",
44 Description: "Creating my first Security Service",
45 DNSIP: "10.0.0.0/24",
46 User: "demo",
47 Password: "***",
48 }
49
50 _, err := securityservices.Create(client.ServiceClient(), options).Extract()
51 if _, ok := err.(gophercloud.ErrMissingInput); !ok {
52 t.Fatal("ErrMissingInput was expected to occur")
53 }
54}
ehdou894b50d2017-01-07 00:38:03 +020055
56// Verifies that security service deletion works
57func TestDelete(t *testing.T) {
58 th.SetupHTTP()
59 defer th.TeardownHTTP()
60
61 MockDeleteResponse(t)
62
63 res := securityservices.Delete(client.ServiceClient(), "securityServiceID")
64 th.AssertNoErr(t, res.Err)
65}
ehdoub46ba5a2017-03-08 20:56:49 +020066
67// Verifies that security services can be listed correctly
68func TestList(t *testing.T) {
69 th.SetupHTTP()
70 defer th.TeardownHTTP()
71
72 MockListResponse(t)
73
74 allPages, err := securityservices.List(client.ServiceClient(), &securityservices.ListOpts{}).AllPages()
75 th.AssertNoErr(t, err)
76 actual, err := securityservices.ExtractSecurityServices(allPages)
77 th.AssertNoErr(t, err)
78 var nilTime time.Time
79 expected := []securityservices.SecurityService{
80 {
81 Status: "new",
82 Domain: "",
83 ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
84 Name: "SecServ1",
85 CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
86 Description: "Creating my first Security Service",
87 UpdatedAt: nilTime,
88 Server: "",
89 DNSIP: "10.0.0.0/24",
90 User: "demo",
91 Password: "supersecret",
92 Type: "kerberos",
93 ID: "3c829734-0679-4c17-9637-801da48c0d5f",
94 },
95 {
96 Status: "new",
97 Domain: "",
98 ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
99 Name: "SecServ2",
100 CreatedAt: time.Date(2015, 9, 7, 12, 25, 03, 0, time.UTC),
101 Description: "Creating my second Security Service",
102 UpdatedAt: nilTime,
103 Server: "",
104 DNSIP: "10.0.0.0/24",
105 User: "",
106 Password: "",
107 Type: "ldap",
108 ID: "5a1d3a12-34a7-4087-8983-50e9ed03509a",
109 },
110 }
111
112 th.CheckDeepEquals(t, expected, actual)
113}
114
115// Verifies that security services list can be called with query parameters
116func TestFilteredList(t *testing.T) {
117 th.SetupHTTP()
118 defer th.TeardownHTTP()
119
120 MockFilteredListResponse(t)
121
122 options := &securityservices.ListOpts{
123 Type: "kerberos",
124 }
125
126 allPages, err := securityservices.List(client.ServiceClient(), options).AllPages()
127 th.AssertNoErr(t, err)
128 actual, err := securityservices.ExtractSecurityServices(allPages)
129 th.AssertNoErr(t, err)
130 var nilTime time.Time
131 expected := []securityservices.SecurityService{
132 {
133 Status: "new",
134 Domain: "",
135 ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1",
136 Name: "SecServ1",
137 CreatedAt: time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
138 Description: "Creating my first Security Service",
139 UpdatedAt: nilTime,
140 Server: "",
141 DNSIP: "10.0.0.0/24",
142 User: "demo",
143 Password: "supersecret",
144 Type: "kerberos",
145 ID: "3c829734-0679-4c17-9637-801da48c0d5f",
146 },
147 }
148
149 th.CheckDeepEquals(t, expected, actual)
150}