-
Notifications
You must be signed in to change notification settings - Fork 28
/
chef_organization_spec.rb
226 lines (201 loc) · 9.29 KB
/
chef_organization_spec.rb
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
require 'support/spec_support'
require 'cheffish/rspec/chef_run_support'
require 'chef/resource/chef_organization'
require 'chef/provider/chef_organization'
describe Chef::Resource::ChefOrganization do
extend Cheffish::RSpec::ChefRunSupport
when_the_chef_12_server 'is in multi-org mode' do
context 'and chef_server_url is pointed at the top level' do
user 'u', {}
user 'u2', {}
it 'chef_organization "x" creates the organization' do
expect_recipe {
chef_organization 'x'
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
end
end
context 'and chef_server_url is pointed at /organizations/foo' do
organization 'foo'
before :each do
Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo').to_s
end
context 'and is empty' do
user 'u', {}
user 'u2', {}
it 'chef_organization "x" creates the organization' do
expect_recipe {
chef_organization 'x'
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
end
it 'chef_organization "x" with full_name creates the organization' do
expect_recipe {
chef_organization 'x' do
full_name 'Hi'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('Hi')
end
it 'chef_organization "x" and inviting users creates the invites' do
expect_recipe {
chef_organization 'x' do
invites 'u', 'u2'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(u u2))
end
it 'chef_organization "x" adds members' do
expect_recipe {
chef_organization 'x' do
members 'u', 'u2'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(u u2))
end
end
context 'and already has an organization named x' do
user 'u', {}
user 'u2', {}
user 'u3', {}
user 'member', {}
user 'member2', {}
user 'invited', {}
user 'invited2', {}
organization 'x', { 'full_name' => 'Lo' } do
org_member 'member', 'member2'
org_invite 'invited', 'invited2'
end
it 'chef_organization "x" changes nothing' do
expect_recipe {
chef_organization 'x'
}.not_to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('Lo')
end
it 'chef_organization "x" with "complete true" reverts the full_name' do
expect_recipe {
chef_organization 'x' do
complete true
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
end
it 'chef_organization "x" with new full_name updates the organization' do
expect_recipe {
chef_organization 'x' do
full_name 'Hi'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('Hi')
end
context 'invites and membership tests' do
it 'chef_organization "x" and inviting users creates the invites' do
expect_recipe {
chef_organization 'x' do
invites 'u', 'u2'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited invited2 u u2))
end
it 'chef_organization "x" adds members' do
expect_recipe {
chef_organization 'x' do
members 'u', 'u2'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2 u u2))
end
it 'chef_organization "x" does nothing when inviting already-invited users and members' do
expect_recipe {
chef_organization 'x' do
invites 'invited', 'member'
end
}.not_to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited invited2))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2))
end
it 'chef_organization "x" does nothing when adding members who are already members' do
expect_recipe {
chef_organization 'x' do
members 'member'
end
}.not_to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited invited2))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2))
end
it 'chef_organization "x" upgrades invites to members when asked' do
expect_recipe {
chef_organization 'x' do
members 'invited'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(invited member member2))
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited2))
end
it 'chef_organization "x" removes members and invites when asked' do
expect_recipe {
chef_organization 'x' do
remove_members 'invited', 'member'
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited2))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member2))
end
it 'chef_organization "x" does nothing when asked to remove non-members' do
expect_recipe {
chef_organization 'x' do
remove_members 'u', 'u2'
end
}.not_to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited invited2))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2))
end
it 'chef_organization "x" with "complete true" reverts the full_name but does not remove invites or members' do
expect_recipe {
chef_organization 'x' do
complete true
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited invited2))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2))
end
it 'chef_organization "x" with members [] and "complete true" removes invites and members' do
expect_recipe {
chef_organization 'x' do
members []
complete true
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq([])
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq([])
end
it 'chef_organization "x" with members [] and "complete true" removes invites but not members' do
expect_recipe {
chef_organization 'x' do
invites []
complete true
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq([])
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member member2))
end
it 'chef_organization "x" with invites, members and "complete true" removes all non-specified invites and members' do
expect_recipe {
chef_organization 'x' do
invites 'invited', 'u'
members 'member', 'u2'
complete true
end
}.to have_updated('chef_organization[x]', :create)
expect(get('/organizations/x')['full_name']).to eq('x')
expect(get('/organizations/x/association_requests').map { |u| u['username'] }).to eq(%w(invited u))
expect(get('/organizations/x/users').map { |u| u['user']['username'] }).to eq(%w(member u2))
end
end
end
end
end
end