hammer_cli_foreman 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/release_notes.md +33 -0
- data/doc/testing.md +13 -0
- data/lib/hammer_cli_foreman.rb +1 -5
- data/lib/hammer_cli_foreman/api/connection.rb +1 -18
- data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +0 -1
- data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
- data/lib/hammer_cli_foreman/audit.rb +7 -0
- data/lib/hammer_cli_foreman/auth.rb +4 -4
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
- data/lib/hammer_cli_foreman/commands.rb +3 -1
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +16 -9
- data/lib/hammer_cli_foreman/id_resolver.rb +2 -2
- data/lib/hammer_cli_foreman/location.rb +2 -0
- data/lib/hammer_cli_foreman/option_builders.rb +1 -1
- data/lib/hammer_cli_foreman/organization.rb +2 -0
- data/lib/hammer_cli_foreman/output/fields.rb +1 -1
- data/lib/hammer_cli_foreman/output/formatters.rb +1 -1
- data/lib/hammer_cli_foreman/ping.rb +20 -11
- data/lib/hammer_cli_foreman/references.rb +16 -0
- data/lib/hammer_cli_foreman/sessions.rb +1 -3
- data/lib/hammer_cli_foreman/settings.rb +14 -0
- data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -0
- data/lib/hammer_cli_foreman/user.rb +4 -0
- data/lib/hammer_cli_foreman/user_mail_notification.rb +51 -0
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/lib/minitest/coverage_reporter.rb +94 -0
- data/lib/minitest/hammer_coverage_plugin.rb +19 -0
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/2.1/foreman_api.json +1 -1
- data/test/functional/audit_test.rb +86 -63
- data/test/functional/commands/list_test.rb +11 -11
- data/test/functional/compute_profile_test.rb +4 -2
- data/test/functional/host_test.rb +29 -18
- data/test/functional/http_proxy_test.rb +1 -4
- data/test/functional/location_test.rb +134 -0
- data/test/functional/media_test.rb +130 -0
- data/test/functional/organization_test.rb +52 -0
- data/test/functional/realm_test.rb +103 -0
- data/test/functional/role_test.rb +9 -12
- data/test/functional/settings_test.rb +57 -1
- data/test/functional/user_mail_notification_test.rb +89 -0
- data/test/functional/user_test.rb +39 -0
- data/test/reports/TEST-Minitest-Result.xml +4344 -0
- data/test/test_helper.rb +5 -2
- data/test/unit/api/interactive_basic_auth_test.rb +3 -1
- data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +2 -2
- data/test/unit/api/oauth/oauth_password_grant_test.rb +2 -2
- data/test/unit/api_test.rb +3 -4
- data/test/unit/apipie_resource_mock.rb +4 -4
- data/test/unit/audit_test.rb +1 -0
- data/test/unit/commands_test.rb +19 -19
- data/test/unit/common_parameter_test.rb +1 -1
- data/test/unit/dependency_resolver_test.rb +4 -4
- data/test/unit/exception_handler_test.rb +13 -13
- data/test/unit/helpers/command.rb +5 -5
- data/test/unit/helpers/resource_disabled.rb +2 -2
- data/test/unit/host_test.rb +2 -2
- data/test/unit/id_resolver_test.rb +23 -23
- data/test/unit/media_test.rb +1 -1
- data/test/unit/option_builders_test.rb +49 -49
- data/test/unit/option_sources/id_params_test.rb +2 -2
- data/test/unit/option_sources/ids_params_test.rb +2 -2
- data/test/unit/output/formatters_test.rb +21 -21
- data/test/unit/param_filters_test.rb +17 -17
- data/test/unit/partition_table_test.rb +2 -2
- data/test/unit/role_test.rb +2 -2
- data/test/unit/sessions_test.rb +26 -37
- data/test/unit/template_test.rb +1 -1
- metadata +15 -7
- data/lib/hammer_cli_foreman/trend.rb +0 -47
- data/test/functional/trend_test.rb +0 -22
@@ -33,8 +33,10 @@ describe "parameters" do
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
it 'update compute profile name' do
|
36
|
-
params = ['--id=1'
|
37
|
-
api_expects(:compute_profiles, :update, 'Update the compute profile').with_params(
|
36
|
+
params = ['--id=1', '--new-name=profile2']
|
37
|
+
api_expects(:compute_profiles, :update, 'Update the compute profile').with_params(
|
38
|
+
{ 'compute_profile' => { 'name' => 'profile2' } }
|
39
|
+
).returns(@compute_profile)
|
38
40
|
result = run_cmd(@cmd + params)
|
39
41
|
assert_cmd(success_result("Compute profile updated.\n"), result)
|
40
42
|
end
|
@@ -315,6 +315,26 @@ describe 'host update' do
|
|
315
315
|
}
|
316
316
|
end
|
317
317
|
|
318
|
+
it 'updates with passed options only' do
|
319
|
+
params = ['--new-name=new-name']
|
320
|
+
expected_result = success_result("Host updated.\n")
|
321
|
+
|
322
|
+
api_expects(:hosts, :update, 'Update host name only').with_params(
|
323
|
+
'id' => '1', 'organization_id' => 1, 'location_id' => 1,
|
324
|
+
'host' => { 'name' => 'new-name' }
|
325
|
+
).returns(
|
326
|
+
{
|
327
|
+
'id' => '1',
|
328
|
+
'name' => 'new-name',
|
329
|
+
'organization_id' => '1',
|
330
|
+
'location_id' => '1'
|
331
|
+
}
|
332
|
+
)
|
333
|
+
|
334
|
+
result = run_cmd(cmd + minimal_params + params)
|
335
|
+
assert_cmd(expected_result, result)
|
336
|
+
end
|
337
|
+
|
318
338
|
it 'ensures helper methods are invoked' do
|
319
339
|
params = ['--image-id=1']
|
320
340
|
expected_result = success_result("Host updated.\n")
|
@@ -350,12 +370,9 @@ describe 'host update' do
|
|
350
370
|
)
|
351
371
|
api_expects(:hosts, :update, 'Update host with new org').with_params(
|
352
372
|
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
353
|
-
'organization_id' => '5'
|
354
|
-
}
|
373
|
+
'organization_id' => '5' }
|
355
374
|
) do |par|
|
356
|
-
par['id'] == '1' &&
|
357
|
-
par['host']['organization_id'] == '5' &&
|
358
|
-
par['host']['compute_attributes'] == {}
|
375
|
+
par['id'] == '1' && par['host']['organization_id'] == '5'
|
359
376
|
end.returns(updated_host)
|
360
377
|
|
361
378
|
expected_result = success_result("Host updated.\n")
|
@@ -373,12 +390,9 @@ describe 'host update' do
|
|
373
390
|
)
|
374
391
|
api_expects(:hosts, :update, 'Update host with new loc').with_params(
|
375
392
|
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
376
|
-
'location_id' => '5'
|
377
|
-
}
|
393
|
+
'location_id' => '5' }
|
378
394
|
) do |par|
|
379
|
-
par['id'] == '1' &&
|
380
|
-
par['host']['location_id'] == '5' &&
|
381
|
-
par['host']['compute_attributes'] == {}
|
395
|
+
par['id'] == '1' && par['host']['location_id'] == '5'
|
382
396
|
end.returns(updated_host)
|
383
397
|
|
384
398
|
expected_result = success_result("Host updated.\n")
|
@@ -396,12 +410,9 @@ describe 'host update' do
|
|
396
410
|
)
|
397
411
|
api_expects(:hosts, :update, 'Update host with new owner').with_params(
|
398
412
|
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
399
|
-
'owner_id' => '1'
|
400
|
-
}
|
413
|
+
'owner_id' => '1' }
|
401
414
|
) do |par|
|
402
|
-
par['id'] == '1' &&
|
403
|
-
par['host']['owner_id'] == '1' &&
|
404
|
-
par['host']['compute_attributes'] == {}
|
415
|
+
par['id'] == '1' && par['host']['owner_id'] == '1'
|
405
416
|
end.returns(updated_host)
|
406
417
|
|
407
418
|
expected_result = success_result("Host updated.\n")
|
@@ -428,7 +439,7 @@ describe 'host config reports' do
|
|
428
439
|
end.returns(index_response([report15]))
|
429
440
|
|
430
441
|
result = run_cmd(['host', 'config-reports', '--id=1'])
|
431
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
442
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
432
443
|
end
|
433
444
|
|
434
445
|
it 'filters reports by --name' do
|
@@ -437,7 +448,7 @@ describe 'host config reports' do
|
|
437
448
|
end.returns(index_response([report15]))
|
438
449
|
|
439
450
|
result = run_cmd(['host', 'config-reports', '--name=host.example.com'])
|
440
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
451
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
441
452
|
end
|
442
453
|
|
443
454
|
it 'prints error or missing --id and --name' do
|
@@ -462,7 +473,7 @@ describe 'host config reports' do
|
|
462
473
|
end.returns(index_response([report15]))
|
463
474
|
|
464
475
|
result = run_cmd(['host', 'config-reports', '--name=host.example.com', '--search=reported > "2 hour ago"'])
|
465
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
476
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
466
477
|
end
|
467
478
|
end
|
468
479
|
describe 'disassociate host from vm' do
|
@@ -64,9 +64,6 @@ describe 'httpproxy' do
|
|
64
64
|
expected_result = success_result("Http proxy deleted.\n")
|
65
65
|
|
66
66
|
result = run_cmd(%w(http-proxy delete --id 1))
|
67
|
-
|
68
|
-
if RUBY_VERSION < '2.7'
|
69
|
-
assert_cmd(expected_result, result)
|
70
|
-
end
|
67
|
+
assert_cmd(expected_result, result)
|
71
68
|
end
|
72
69
|
end
|
@@ -139,3 +139,137 @@ describe "parameters" do
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
|
+
|
143
|
+
describe 'create' do
|
144
|
+
before do
|
145
|
+
@cmd = %w(location create)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should print error missing argument name' do
|
149
|
+
expected_result = "Could not create the location:\n Missing arguments for '--name'.\n"
|
150
|
+
|
151
|
+
api_expects(:locations, :index)
|
152
|
+
|
153
|
+
result = run_cmd(@cmd)
|
154
|
+
assert_match(expected_result, result.err)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should create a location' do
|
158
|
+
params = ['--name=test-location']
|
159
|
+
|
160
|
+
api_expects(:locations, :index)
|
161
|
+
api_expects(:locations, :create, 'Create a locations') do |params|
|
162
|
+
(params['location']['name'] == 'test-location')
|
163
|
+
end
|
164
|
+
|
165
|
+
result = run_cmd(@cmd + params)
|
166
|
+
assert_cmd(success_result("Location created.\n"), result)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'delete' do
|
171
|
+
before do
|
172
|
+
@cmd = %w(location delete)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should print error missing argument id' do
|
176
|
+
expected_result = "Could not delete the location:\n Missing arguments for '--id'.\n"
|
177
|
+
|
178
|
+
api_expects(:locations, :index)
|
179
|
+
|
180
|
+
result = run_cmd(@cmd)
|
181
|
+
assert_match(expected_result, result.err)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should delete a location' do
|
185
|
+
params = ['--id=1']
|
186
|
+
|
187
|
+
api_expects(:locations, :index)
|
188
|
+
api_expects(:locations, :destroy, 'Delete a location').with_params(id: '1')
|
189
|
+
|
190
|
+
result = run_cmd(@cmd + params)
|
191
|
+
assert_cmd(success_result("Location deleted.\n"), result)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'info' do
|
196
|
+
before do
|
197
|
+
@cmd = ['location', 'info']
|
198
|
+
@location = {
|
199
|
+
id: 1,
|
200
|
+
title: 'Default Location',
|
201
|
+
name: 'Default Location',
|
202
|
+
users: [],
|
203
|
+
smart_proxies: [],
|
204
|
+
subnets: [],
|
205
|
+
compute_resources: [],
|
206
|
+
media: [],
|
207
|
+
ptables: [],
|
208
|
+
provisioning_templates: [],
|
209
|
+
domains: [],
|
210
|
+
realms: [],
|
211
|
+
environments: [],
|
212
|
+
hostgroups: [],
|
213
|
+
organizations: [],
|
214
|
+
parameters: []
|
215
|
+
}
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should return the info of a location' do
|
219
|
+
params = ['--id', 1]
|
220
|
+
api_expects(:locations, :index)
|
221
|
+
api_expects(:locations, :show, 'Info location').returns(@location)
|
222
|
+
|
223
|
+
output = OutputMatcher.new([
|
224
|
+
'Id: 1',
|
225
|
+
'Title: Default Location',
|
226
|
+
'Name: Default Location',
|
227
|
+
'Users:',
|
228
|
+
'',
|
229
|
+
'Smart proxies:',
|
230
|
+
'',
|
231
|
+
'Subnets:',
|
232
|
+
'',
|
233
|
+
'Compute resources:',
|
234
|
+
'',
|
235
|
+
'Installation media:',
|
236
|
+
'',
|
237
|
+
'Templates:',
|
238
|
+
'',
|
239
|
+
'Partition Tables:',
|
240
|
+
'',
|
241
|
+
'Domains:',
|
242
|
+
'',
|
243
|
+
'Realms:',
|
244
|
+
'',
|
245
|
+
'Environments:',
|
246
|
+
'',
|
247
|
+
'Hostgroups:',
|
248
|
+
'',
|
249
|
+
'Parameters:',
|
250
|
+
])
|
251
|
+
|
252
|
+
expected_result = success_result(output)
|
253
|
+
result = run_cmd(@cmd + params)
|
254
|
+
assert_cmd(expected_result, result)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe 'update' do
|
259
|
+
before do
|
260
|
+
@cmd = ['location', 'update']
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should update a location' do
|
264
|
+
params = ['--id=1', '--new-name=Default Location test']
|
265
|
+
|
266
|
+
api_expects(:locations, :index)
|
267
|
+
api_expects(:locations, :update, 'Update a location') do |params|
|
268
|
+
(params['location']['id'] == '1')
|
269
|
+
(params['location']['name'] == 'Default Location test')
|
270
|
+
end
|
271
|
+
|
272
|
+
result = run_cmd(@cmd + params)
|
273
|
+
assert_cmd(success_result("Location updated.\n"), result)
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'medium' do
|
4
|
+
describe 'list' do
|
5
|
+
before do
|
6
|
+
@cmd = %w[medium list]
|
7
|
+
@media = [{
|
8
|
+
id: 1,
|
9
|
+
name: 'CentOS mirror',
|
10
|
+
path: 'http://mirror.centos.org/centos/$major/os/$arch',
|
11
|
+
os_family: 'Redhat',
|
12
|
+
operating_systems: [],
|
13
|
+
locations: [],
|
14
|
+
organizations: []
|
15
|
+
}]
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return a list of media' do
|
19
|
+
api_expects(:media, :index, 'List media').returns(@media)
|
20
|
+
|
21
|
+
output = IndexMatcher.new([
|
22
|
+
['ID', 'NAME', 'PATH'],
|
23
|
+
['1', 'CentOS mirror', 'http://mirror.centos.org/centos/$major/os/$arch']
|
24
|
+
])
|
25
|
+
expected_result = success_result(output)
|
26
|
+
|
27
|
+
result = run_cmd(@cmd)
|
28
|
+
assert_cmd(expected_result, result)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'info' do
|
33
|
+
before do
|
34
|
+
@cmd = ['medium', 'info']
|
35
|
+
@medium = {
|
36
|
+
id: 1,
|
37
|
+
name: 'CentOS mirror',
|
38
|
+
path: 'http://mirror.centos.org/centos/$major/os/$arch',
|
39
|
+
os_family: 'Redhat',
|
40
|
+
operating_systems: [],
|
41
|
+
locations: [],
|
42
|
+
organizations: []
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return the info of a medium' do
|
47
|
+
params = ['--id', 1]
|
48
|
+
api_expects(:media, :show, 'Info medium').returns(@medium)
|
49
|
+
|
50
|
+
output = OutputMatcher.new([
|
51
|
+
'Id: 1',
|
52
|
+
'Name: CentOS mirror',
|
53
|
+
'Path: http://mirror.centos.org/centos/$major/os/$arch',
|
54
|
+
'OS Family: Redhat'
|
55
|
+
])
|
56
|
+
|
57
|
+
expected_result = success_result(output)
|
58
|
+
result = run_cmd(@cmd + params)
|
59
|
+
assert_cmd(expected_result, result)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'create' do
|
64
|
+
before do
|
65
|
+
@cmd = %w(medium create)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should print error missing argument name and path' do
|
69
|
+
expected_result = "Could not create the installation medium:\n Missing arguments for '--name', '--path'.\n"
|
70
|
+
|
71
|
+
|
72
|
+
result = run_cmd(@cmd)
|
73
|
+
assert_match(expected_result, result.err)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should create a media' do
|
77
|
+
params = ['--name=CentOS mirror', '--path=http://mirror.centos.org/centos/$major/os/$arch']
|
78
|
+
|
79
|
+
api_expects(:media, :create) do |params|
|
80
|
+
(params['medium']['name'] == 'CentOS mirror')
|
81
|
+
(params['medium']['path'] == 'http://mirror.centos.org/centos/$major/os/$arch')
|
82
|
+
end
|
83
|
+
|
84
|
+
result = run_cmd(@cmd + params)
|
85
|
+
assert_cmd(success_result("Installation medium created.\n"), result)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'delete' do
|
90
|
+
before do
|
91
|
+
@cmd = %w(medium delete)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should print error missing argument id' do
|
95
|
+
expected_result = "Could not delete the installation media:\n Missing arguments for '--id'.\n"
|
96
|
+
|
97
|
+
api_expects_no_call
|
98
|
+
|
99
|
+
result = run_cmd(@cmd)
|
100
|
+
assert_match(expected_result, result.err)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should delete a media' do
|
104
|
+
params = ['--id=1']
|
105
|
+
|
106
|
+
api_expects(:media, :destroy, 'Delete a media').with_params(id: '1')
|
107
|
+
|
108
|
+
result = run_cmd(@cmd + params)
|
109
|
+
assert_cmd(success_result("Installation medium deleted.\n"), result)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'update' do
|
114
|
+
before do
|
115
|
+
@cmd = ['medium', 'update']
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should update a media' do
|
119
|
+
params = ['--id=1', '--new-name=CentOS mirror test']
|
120
|
+
|
121
|
+
api_expects(:media, :update, 'Update a media') do |params|
|
122
|
+
(params['medium']['id'] == '1')
|
123
|
+
(params['medium']['name'] == 'CentOS mirror test')
|
124
|
+
end
|
125
|
+
|
126
|
+
result = run_cmd(@cmd + params)
|
127
|
+
assert_cmd(success_result("Installation medium updated.\n"), result)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -210,3 +210,55 @@ describe 'associating commands' do
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
describe 'create' do
|
215
|
+
before do
|
216
|
+
@cmd = %w(organization create)
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should print error missing argument name' do
|
220
|
+
expected_result = "Could not create the organization:\n Missing arguments for '--name'.\n"
|
221
|
+
|
222
|
+
api_expects(:organizations, :index)
|
223
|
+
|
224
|
+
result = run_cmd(@cmd)
|
225
|
+
assert_match(expected_result, result.err)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should create an organization' do
|
229
|
+
params = ['--name=test-organization']
|
230
|
+
|
231
|
+
api_expects(:organizations, :index)
|
232
|
+
api_expects(:organizations, :create, 'Create an organization') do |params|
|
233
|
+
(params['organization']['name'] == 'test-organization')
|
234
|
+
end
|
235
|
+
|
236
|
+
result = run_cmd(@cmd + params)
|
237
|
+
assert_cmd(success_result("Organization created.\n"), result)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'delete' do
|
242
|
+
before do
|
243
|
+
@cmd = %w(organization delete)
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'should print error missing argument id' do
|
247
|
+
expected_result = "Could not delete the organization:\n Missing arguments for '--id'.\n"
|
248
|
+
|
249
|
+
api_expects(:organizations, :index)
|
250
|
+
|
251
|
+
result = run_cmd(@cmd)
|
252
|
+
assert_match(expected_result, result.err)
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should delete an organization' do
|
256
|
+
params = ['--id=1']
|
257
|
+
|
258
|
+
api_expects(:organizations, :index)
|
259
|
+
api_expects(:organizations, :destroy, 'Delete an organization').with_params(id: '1')
|
260
|
+
|
261
|
+
result = run_cmd(@cmd + params)
|
262
|
+
assert_cmd(success_result("Organization deleted.\n"), result)
|
263
|
+
end
|
264
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'realm' do
|
4
|
+
describe 'list' do
|
5
|
+
before do
|
6
|
+
@cmd = %w[realm list]
|
7
|
+
@realms =
|
8
|
+
[{
|
9
|
+
id: 1,
|
10
|
+
name: 'test-realm' }]
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return a list of realms' do
|
14
|
+
api_expects(:realms, :index, 'List realms').returns(@realms)
|
15
|
+
|
16
|
+
result = run_cmd(@cmd)
|
17
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'info' do
|
22
|
+
before do
|
23
|
+
@cmd = %w[realm info]
|
24
|
+
@realm = {
|
25
|
+
id: 1,
|
26
|
+
name: 'test-realm'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return a realm' do
|
31
|
+
params = ['--id=1']
|
32
|
+
api_expects(:realms, :show, 'Show realm').returns(@realm)
|
33
|
+
|
34
|
+
result = run_cmd(@cmd + params)
|
35
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'create' do
|
40
|
+
before do
|
41
|
+
@cmd = %w[realm create]
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should print error on missing --name, --realm-proxy-id, --realm-type' do
|
45
|
+
expected_result = "Could not create the realm:\n Missing arguments for '--name', '--realm-proxy-id', '--realm-type'.\n"
|
46
|
+
|
47
|
+
api_expects_no_call
|
48
|
+
result = run_cmd(@cmd)
|
49
|
+
assert_match(expected_result, result.err)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should create a realm' do
|
53
|
+
params = %w[--name=test-realm --realm-proxy-id=12345 --realm-type=FreeIPA]
|
54
|
+
|
55
|
+
api_expects(:realms, :create, 'Create a realm') do |params|
|
56
|
+
(params['realm']['name'] == 'test-realm' &&
|
57
|
+
params['realm']['realm_proxy_id'] == 12345 &&
|
58
|
+
params['realm']['realm_type'] == 'FreeIPA')
|
59
|
+
end
|
60
|
+
|
61
|
+
result = run_cmd(@cmd + params)
|
62
|
+
|
63
|
+
assert_cmd(success_result("Realm [%{name}] created.\n"), result)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'delete' do
|
68
|
+
before do
|
69
|
+
@cmd = %w[realm delete]
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should delete a realm' do
|
73
|
+
params = ['--id=1']
|
74
|
+
|
75
|
+
api_expects(:realms, :destroy, 'Delete realm').with_params(id: '1')
|
76
|
+
|
77
|
+
result = run_cmd(@cmd + params)
|
78
|
+
assert_cmd(success_result("Realm [%{name}] deleted.\n"), result)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'update' do
|
83
|
+
before do
|
84
|
+
@cmd = %w[realm update]
|
85
|
+
@realm = {
|
86
|
+
id: 1,
|
87
|
+
name: 'test-realm-update'
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should update a realm' do
|
92
|
+
params = %w[--id=1 --new-name=test-realm-update]
|
93
|
+
|
94
|
+
api_expects(:realms, :update, 'Update a realm') do |params|
|
95
|
+
(params['id'] == '1' &&
|
96
|
+
params['realm']['name'] == 'test-realm-update')
|
97
|
+
end
|
98
|
+
|
99
|
+
result = run_cmd(@cmd + params)
|
100
|
+
assert_cmd(success_result("Realm [%{name}] updated.\n"), result)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|