File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (209 lines) | stat: -rw-r--r-- 5,989 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package testing

import (
	"testing"
	"time"

	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

// Verifies that a security service can be created correctly
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockCreateResponse(t)

	options := &securityservices.CreateOpts{
		Name:        "SecServ1",
		Description: "Creating my first Security Service",
		DNSIP:       "10.0.0.0/24",
		User:        "demo",
		Password:    "***",
		Type:        "kerberos",
	}

	s, err := securityservices.Create(client.ServiceClient(), options).Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, s.Name, "SecServ1")
	th.AssertEquals(t, s.Description, "Creating my first Security Service")
	th.AssertEquals(t, s.User, "demo")
	th.AssertEquals(t, s.DNSIP, "10.0.0.0/24")
	th.AssertEquals(t, s.Password, "supersecret")
	th.AssertEquals(t, s.Type, "kerberos")
}

// Verifies that a security service cannot be created without a type
func TestCreateFails(t *testing.T) {
	options := &securityservices.CreateOpts{
		Name:        "SecServ1",
		Description: "Creating my first Security Service",
		DNSIP:       "10.0.0.0/24",
		User:        "demo",
		Password:    "***",
	}

	_, err := securityservices.Create(client.ServiceClient(), options).Extract()
	if _, ok := err.(gophercloud.ErrMissingInput); !ok {
		t.Fatal("ErrMissingInput was expected to occur")
	}
}

// Verifies that security service deletion works
func TestDelete(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockDeleteResponse(t)

	res := securityservices.Delete(client.ServiceClient(), "securityServiceID")
	th.AssertNoErr(t, res.Err)
}

// Verifies that security services can be listed correctly
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	allPages, err := securityservices.List(client.ServiceClient(), &securityservices.ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := securityservices.ExtractSecurityServices(allPages)
	th.AssertNoErr(t, err)
	var nilTime time.Time
	expected := []securityservices.SecurityService{
		{
			Status:      "new",
			Domain:      "",
			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
			Name:        "SecServ1",
			CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
			Description: "Creating my first Security Service",
			UpdatedAt:   nilTime,
			Server:      "",
			DNSIP:       "10.0.0.0/24",
			User:        "demo",
			Password:    "supersecret",
			Type:        "kerberos",
			ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
		},
		{
			Status:      "new",
			Domain:      "",
			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
			Name:        "SecServ2",
			CreatedAt:   time.Date(2015, 9, 7, 12, 25, 03, 0, time.UTC),
			Description: "Creating my second Security Service",
			UpdatedAt:   nilTime,
			Server:      "",
			DNSIP:       "10.0.0.0/24",
			User:        "",
			Password:    "",
			Type:        "ldap",
			ID:          "5a1d3a12-34a7-4087-8983-50e9ed03509a",
		},
	}

	th.CheckDeepEquals(t, expected, actual)
}

// Verifies that security services list can be called with query parameters
func TestFilteredList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockFilteredListResponse(t)

	options := &securityservices.ListOpts{
		Type: "kerberos",
	}

	allPages, err := securityservices.List(client.ServiceClient(), options).AllPages()
	th.AssertNoErr(t, err)
	actual, err := securityservices.ExtractSecurityServices(allPages)
	th.AssertNoErr(t, err)
	var nilTime time.Time
	expected := []securityservices.SecurityService{
		{
			Status:      "new",
			Domain:      "",
			ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
			Name:        "SecServ1",
			CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
			Description: "Creating my first Security Service",
			UpdatedAt:   nilTime,
			Server:      "",
			DNSIP:       "10.0.0.0/24",
			User:        "demo",
			Password:    "supersecret",
			Type:        "kerberos",
			ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
		},
	}

	th.CheckDeepEquals(t, expected, actual)
}

// Verifies that it is possible to get a security service
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockGetResponse(t)

	var nilTime time.Time
	expected := securityservices.SecurityService{
		ID:          "3c829734-0679-4c17-9637-801da48c0d5f",
		Name:        "SecServ1",
		CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
		Description: "Creating my first Security Service",
		Type:        "kerberos",
		UpdatedAt:   nilTime,
		ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
		Status:      "new",
		Domain:      "",
		Server:      "",
		DNSIP:       "10.0.0.0/24",
		User:        "demo",
		Password:    "supersecret",
	}

	n, err := securityservices.Get(client.ServiceClient(), "3c829734-0679-4c17-9637-801da48c0d5f").Extract()
	th.AssertNoErr(t, err)

	th.CheckDeepEquals(t, &expected, n)
}

// Verifies that it is possible to update a security service
func TestUpdate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockUpdateResponse(t)
	expected := securityservices.SecurityService{
		ID:          "securityServiceID",
		Name:        "SecServ2",
		CreatedAt:   time.Date(2015, 9, 7, 12, 19, 10, 0, time.UTC),
		Description: "Updating my first Security Service",
		Type:        "kerberos",
		UpdatedAt:   time.Date(2015, 9, 7, 12, 20, 10, 0, time.UTC),
		ProjectID:   "16e1ab15c35a457e9c2b2aa189f544e1",
		Status:      "new",
		Domain:      "",
		Server:      "",
		DNSIP:       "10.0.0.0/24",
		User:        "demo",
		Password:    "supersecret",
	}

	name := "SecServ2"
	options := securityservices.UpdateOpts{Name: &name}
	s, err := securityservices.Update(client.ServiceClient(), "securityServiceID", options).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, &expected, s)
}