forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tenant_test.go
181 lines (143 loc) · 4.98 KB
/
tenant_test.go
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
package stormpath_test
import (
. "github.com/jarias/stormpath-sdk-go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Tenant", func() {
Describe("CurrentTentant", func() {
It("should retrive the current tenant", func() {
tenant, err := CurrentTenant()
Expect(err).NotTo(HaveOccurred())
Expect(tenant.Href).NotTo(BeEmpty())
Expect(tenant.Name).NotTo(BeEmpty())
Expect(tenant.Key).NotTo(BeEmpty())
Expect(tenant.Applications.Href).NotTo(BeEmpty())
Expect(tenant.Directories.Href).NotTo(BeEmpty())
})
})
Describe("CreateApplication", func() {
It("should create a new application", func() {
application := newTestApplication()
err := tenant.CreateApplication(application)
application.Purge()
Expect(err).NotTo(HaveOccurred())
Expect(application.Href).NotTo(BeEmpty())
})
})
Describe("Custom Data", func() {
It("UpdateCustomData should update the given tenant custom data", func() {
customData := map[string]interface{}{
"testIntField": 1,
"testStringField": "test",
}
updatedCustomData, err := tenant.UpdateCustomData(customData)
Expect(err).NotTo(HaveOccurred())
Expect(updatedCustomData["testIntField"]).To(Equal(float64(1)))
tenant.DeleteCustomData()
})
It("GetCustomData should update the given tenant custom data", func() {
customData := map[string]interface{}{
"testIntField": 1,
"testStringField": "test",
}
tenant.UpdateCustomData(customData)
customData, err := tenant.GetCustomData()
Expect(err).NotTo(HaveOccurred())
Expect(customData["testIntField"]).To(Equal(float64(1)))
})
It("DeleteCustomData should update the given tenant custom data", func() {
customData := map[string]interface{}{
"testIntField": 1,
"testStringField": "test",
}
tenant.UpdateCustomData(customData)
err := tenant.DeleteCustomData()
customData, _ = tenant.GetCustomData()
Expect(err).NotTo(HaveOccurred())
Expect(customData).To(HaveLen(3))
})
//Describe("concurrent access", func() {
// It("should allow current access and be consistent at the end", func() {
// for i := 0; i < 8; i++ {
// go func() {
// defer GinkgoRecover()
//
// customData := map[string]interface{}{
// "testIntField": i,
// "testStringField": "test",
// }
//
// data, err := tenant.UpdateCustomData(customData)
// Expect(err).NotTo(HaveOccurred())
// Expect(data["testIntField"]).To(Equal(float64(i)))
// tenant.DeleteCustomData()
// }()
// }
// })
//})
})
Describe("CreateDirectory", func() {
It("should create a new directory", func() {
dir := newTestDirectory()
err := tenant.CreateDirectory(dir)
dir.Delete()
Expect(err).NotTo(HaveOccurred())
Expect(dir.Href).NotTo(BeEmpty())
})
})
Describe("GetDirectories", func() {
It("should retrive all the tenant directories", func() {
tenant, _ := CurrentTenant()
directories, err := tenant.GetDirectories(MakeDirectoriesCriteria())
Expect(err).NotTo(HaveOccurred())
Expect(directories.Href).NotTo(BeEmpty())
Expect(directories.Offset).To(Equal(0))
Expect(directories.Limit).To(Equal(25))
Expect(directories.Items).NotTo(BeEmpty())
})
It("should retrive all the tenant directories by page", func() {
tenant, _ := CurrentTenant()
directories, err := tenant.GetDirectories(MakeDirectoriesCriteria().Limit(1))
Expect(err).NotTo(HaveOccurred())
Expect(directories.Href).NotTo(BeEmpty())
Expect(directories.Offset).To(Equal(0))
Expect(directories.Limit).To(Equal(1))
Expect(directories.Items).To(HaveLen(1))
})
It("should retrive all the tenant directories by page and filter", func() {
tenant, _ := CurrentTenant()
directories, err := tenant.GetDirectories(MakeDirectoriesCriteria().NameEq("Stormpath Administrators"))
Expect(err).NotTo(HaveOccurred())
Expect(directories.Href).NotTo(BeEmpty())
Expect(directories.Items).To(HaveLen(1))
})
})
Describe("GetApplications", func() {
It("should retrive all the tenant applications", func() {
tenant, _ := CurrentTenant()
apps, err := tenant.GetApplications(MakeApplicationCriteria())
Expect(err).NotTo(HaveOccurred())
Expect(apps.Href).NotTo(BeEmpty())
Expect(apps.Offset).To(Equal(0))
Expect(apps.Limit).To(Equal(25))
Expect(apps.Items).NotTo(BeEmpty())
})
It("should retrive all the tenant applications by page", func() {
tenant, _ := CurrentTenant()
apps, err := tenant.GetApplications(MakeApplicationCriteria().Offset(0).Limit(1))
Expect(err).NotTo(HaveOccurred())
Expect(apps.Href).NotTo(BeEmpty())
Expect(apps.Offset).To(Equal(0))
Expect(apps.Limit).To(Equal(1))
Expect(apps.Items).To(HaveLen(1))
})
It("should retrive all the tenant applications by page and filter", func() {
tenant, _ := CurrentTenant()
apps, err := tenant.GetApplications(MakeApplicationCriteria().NameEq("stormpath"))
Expect(err).NotTo(HaveOccurred())
Expect(apps.Href).NotTo(BeEmpty())
Expect(apps.Items).To(HaveLen(1))
})
})
})