hammer_cli_foreman 2.1.1 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +31 -1
  3. data/doc/testing.md +13 -0
  4. data/lib/hammer_cli_foreman.rb +1 -5
  5. data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
  6. data/lib/hammer_cli_foreman/audit.rb +7 -0
  7. data/lib/hammer_cli_foreman/auth.rb +4 -4
  8. data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
  9. data/lib/hammer_cli_foreman/commands.rb +3 -1
  10. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
  11. data/lib/hammer_cli_foreman/host.rb +3 -2
  12. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +16 -9
  13. data/lib/hammer_cli_foreman/id_resolver.rb +2 -2
  14. data/lib/hammer_cli_foreman/location.rb +2 -0
  15. data/lib/hammer_cli_foreman/option_builders.rb +1 -1
  16. data/lib/hammer_cli_foreman/organization.rb +2 -0
  17. data/lib/hammer_cli_foreman/output/fields.rb +1 -1
  18. data/lib/hammer_cli_foreman/output/formatters.rb +1 -1
  19. data/lib/hammer_cli_foreman/ping.rb +20 -11
  20. data/lib/hammer_cli_foreman/references.rb +16 -0
  21. data/lib/hammer_cli_foreman/settings.rb +14 -0
  22. data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -0
  23. data/lib/hammer_cli_foreman/version.rb +1 -1
  24. data/lib/minitest/coverage_reporter.rb +94 -0
  25. data/lib/minitest/hammer_coverage_plugin.rb +19 -0
  26. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  32. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/test/functional/audit_test.rb +86 -63
  40. data/test/functional/commands/list_test.rb +11 -11
  41. data/test/functional/compute_profile_test.rb +4 -2
  42. data/test/functional/host_test.rb +43 -18
  43. data/test/functional/location_test.rb +134 -0
  44. data/test/functional/media_test.rb +130 -0
  45. data/test/functional/organization_test.rb +52 -0
  46. data/test/functional/realm_test.rb +103 -0
  47. data/test/functional/role_test.rb +9 -12
  48. data/test/functional/settings_test.rb +57 -1
  49. data/test/functional/user_test.rb +39 -0
  50. data/test/reports/TEST-Minitest-Result.xml +4344 -0
  51. data/test/test_helper.rb +5 -2
  52. data/test/unit/api/interactive_basic_auth_test.rb +3 -1
  53. data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +2 -2
  54. data/test/unit/api/oauth/oauth_password_grant_test.rb +2 -2
  55. data/test/unit/api_test.rb +3 -4
  56. data/test/unit/apipie_resource_mock.rb +4 -4
  57. data/test/unit/audit_test.rb +1 -0
  58. data/test/unit/commands_test.rb +19 -19
  59. data/test/unit/common_parameter_test.rb +1 -1
  60. data/test/unit/dependency_resolver_test.rb +4 -4
  61. data/test/unit/exception_handler_test.rb +13 -13
  62. data/test/unit/helpers/command.rb +5 -5
  63. data/test/unit/helpers/resource_disabled.rb +2 -2
  64. data/test/unit/host_test.rb +1 -24
  65. data/test/unit/id_resolver_test.rb +23 -23
  66. data/test/unit/media_test.rb +1 -1
  67. data/test/unit/option_builders_test.rb +49 -49
  68. data/test/unit/option_sources/id_params_test.rb +2 -2
  69. data/test/unit/option_sources/ids_params_test.rb +2 -2
  70. data/test/unit/output/formatters_test.rb +21 -21
  71. data/test/unit/param_filters_test.rb +17 -17
  72. data/test/unit/partition_table_test.rb +2 -2
  73. data/test/unit/role_test.rb +2 -2
  74. data/test/unit/sessions_test.rb +24 -24
  75. data/test/unit/template_test.rb +1 -1
  76. metadata +108 -103
  77. data/lib/hammer_cli_foreman/trend.rb +0 -47
  78. data/test/functional/trend_test.rb +0 -22
@@ -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
@@ -40,9 +40,9 @@ describe 'role' do
40
40
  it 'should clone a role by id' do
41
41
  params = ['--id=1', '--new-name=zzz']
42
42
 
43
- api_expects(:roles, :clone, 'Clone role').with_params({
44
- 'id' => '1', 'role' => {'name' => 'zzz'}, 'name' => 'zzz'
45
- })
43
+ api_expects(:roles, :clone, 'Clone role').with_params(
44
+ { 'id' => '1', 'role' => { 'name' => 'zzz' } }
45
+ )
46
46
 
47
47
  result = run_cmd(@cmd + params)
48
48
  assert_cmd(success_result("User role cloned.\n"), result)
@@ -51,16 +51,13 @@ describe 'role' do
51
51
  it 'should clone a role by name' do
52
52
  params = ['--name=old', '--new-name=zzz']
53
53
 
54
- api_expects_search(:roles, { :name => 'old' }, 'Attempt find role').returns(
55
- index_response(
56
- [{
57
- 'name' => 'old',
58
- 'id' => 1
59
- }]))
54
+ api_expects_search(:roles, { name: 'old' }, 'Attempt find role').returns(
55
+ index_response([{ 'name' => 'old', 'id' => 1 }])
56
+ )
60
57
 
61
- api_expects(:roles, :clone, 'Clone role').with_params({
62
- 'id' => 1, 'role' => {'name' => 'zzz'}, 'name' => 'zzz'
63
- })
58
+ api_expects(:roles, :clone, 'Clone role').with_params(
59
+ { 'id' => 1, 'role' => { 'name' => 'zzz' } }
60
+ )
64
61
 
65
62
  result = run_cmd(@cmd + params)
66
63
  assert_cmd(success_result("User role cloned.\n"), result)