hammer_cli_foreman 2.1.2 → 2.3.2
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 +32 -4
- data/doc/testing.md +13 -0
- data/lib/hammer_cli_foreman.rb +0 -4
- data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
- 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/host.rb +3 -2
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +16 -9
- data/lib/hammer_cli_foreman/location.rb +2 -0
- data/lib/hammer_cli_foreman/option_builders.rb +21 -2
- 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/settings.rb +14 -0
- data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -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/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 +43 -18
- 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_test.rb +39 -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/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 +1 -24
- 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 +24 -24
- data/test/unit/template_test.rb +1 -1
- metadata +105 -104
- data/lib/hammer_cli_foreman/trend.rb +0 -47
- data/test/functional/trend_test.rb +0 -22
- data/test/reports/TEST-Minitest-Result.xml +0 -4344
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
3
|
describe 'Settings' do
|
4
4
|
let(:setting) do
|
@@ -33,5 +33,61 @@ describe 'Settings' do
|
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
+
describe 'info' do
|
37
|
+
before do
|
38
|
+
@cmd = ['setting', 'info']
|
39
|
+
@setting = {
|
40
|
+
description: 'Fix DB cache on next Foreman restart',
|
41
|
+
category: 'Setting::General',
|
42
|
+
settings_type: 'boolean',
|
43
|
+
default: false,
|
44
|
+
created_at: "2020-05-24 09:02:11 UTC",
|
45
|
+
updated_at: "2020-07-01 07:42:14 UTC",
|
46
|
+
id: 1,
|
47
|
+
name: "fix_db_cache",
|
48
|
+
full_name: "Fix DB cache",
|
49
|
+
value: false,
|
50
|
+
category_name: "General"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return a setting' do
|
55
|
+
params = ['--id=1']
|
56
|
+
api_expects(:settings, :show, 'Show a setting').returns(@setting)
|
57
|
+
|
58
|
+
output = OutputMatcher.new([
|
59
|
+
'Id: 1',
|
60
|
+
'Name: fix_db_cache',
|
61
|
+
'Description: Fix DB cache on next Foreman restart',
|
62
|
+
'Category: General',
|
63
|
+
'Settings type: boolean',
|
64
|
+
'Value: false'
|
65
|
+
])
|
66
|
+
|
67
|
+
expected_result = success_result(output)
|
68
|
+
|
69
|
+
result = run_cmd(@cmd + params)
|
70
|
+
assert_cmd(expected_result, result)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'update' do
|
75
|
+
before do
|
76
|
+
@cmd = ['setting', 'set']
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should update a setting' do
|
80
|
+
params = ['--id=1', '--value=true']
|
81
|
+
|
82
|
+
api_expects(:settings, :update, 'Update a setting') do |params|
|
83
|
+
(params['setting']['id'] == '1')
|
84
|
+
(params['setting']['value'] == 'true')
|
85
|
+
end
|
86
|
+
|
87
|
+
result = run_cmd(@cmd + params)
|
88
|
+
assert_cmd(success_result("Setting [%{name}] updated to [%{value}].\n"), result)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
36
92
|
end
|
37
93
|
|
@@ -162,4 +162,43 @@ describe "user" do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
|
+
|
166
|
+
describe 'list' do
|
167
|
+
let(:cmd) { ['user', 'list'] }
|
168
|
+
let(:users) do
|
169
|
+
[{
|
170
|
+
id: 1,
|
171
|
+
login: 'admin',
|
172
|
+
full_name: 'Admin User',
|
173
|
+
mail: 'root@localadmin.net',
|
174
|
+
admin: true,
|
175
|
+
disabled: false
|
176
|
+
}] end
|
177
|
+
|
178
|
+
it "should show index list" do
|
179
|
+
api_expects(:users, :index).returns(users)
|
180
|
+
|
181
|
+
output = IndexMatcher.new([
|
182
|
+
['ID', 'LOGIN', 'NAME', 'EMAIL', 'ADMIN', 'DISABLED', 'AUTHORIZED BY'],
|
183
|
+
['1', 'admin', 'Admin User', 'root@localadmin.net', 'yes', 'no', ''],
|
184
|
+
])
|
185
|
+
|
186
|
+
result = run_cmd(cmd)
|
187
|
+
assert_cmd(success_result(output), result)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe 'delete' do
|
192
|
+
let(:cmd) { ['user', 'delete'] }
|
193
|
+
|
194
|
+
it 'deletes a user' do
|
195
|
+
params = ['--id', user['id']]
|
196
|
+
api_expects(:users, :destroy).returns(user)
|
197
|
+
|
198
|
+
expected_result = success_result("User [#{user['login']}] deleted.\n")
|
199
|
+
|
200
|
+
result = run_cmd(cmd + params)
|
201
|
+
assert_cmd(expected_result, result)
|
202
|
+
end
|
203
|
+
end
|
165
204
|
end
|
data/test/test_helper.rb
CHANGED
@@ -17,11 +17,14 @@ require "mocha/minitest"
|
|
17
17
|
require 'hammer_cli'
|
18
18
|
require 'hammer_cli_foreman/testing/api_expectations'
|
19
19
|
|
20
|
-
FOREMAN_VERSION =
|
20
|
+
FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '2.1'
|
21
|
+
unless Dir.entries('test/data').include? FOREMAN_VERSION
|
22
|
+
raise StandardError.new "Version is not correct"
|
23
|
+
end
|
21
24
|
|
22
25
|
include HammerCLIForeman::Testing::APIExpectations
|
23
26
|
HammerCLI.context[:api_connection].create('foreman') do
|
24
|
-
api_connection({}, FOREMAN_VERSION)
|
27
|
+
api_connection({}, Gem::Version.new(FOREMAN_VERSION))
|
25
28
|
end
|
26
29
|
|
27
30
|
require 'hammer_cli_foreman'
|
@@ -44,11 +44,13 @@ describe HammerCLIForeman::Api::InteractiveBasicAuth do
|
|
44
44
|
|
45
45
|
context "non-interactive mode" do
|
46
46
|
it "doesn't ask for credentials when they're not provided" do
|
47
|
+
HammerCLI.stubs(:interactive?).returns false
|
47
48
|
auth = HammerCLIForeman::Api::InteractiveBasicAuth.new(nil, nil)
|
48
49
|
auth.expects(:ask_user).never
|
49
|
-
|
50
50
|
request.expects(:basic_auth).with(nil, nil)
|
51
51
|
auth.authenticate(request, args)
|
52
|
+
HammerCLI.unstub(:interactive?)
|
53
|
+
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
@@ -23,13 +23,13 @@ describe HammerCLIForeman::Api::Oauth::AuthenticationCodeGrant do
|
|
23
23
|
it 'sets token as nil when all input parameter are missing' do
|
24
24
|
auth.stubs(:get_code).returns('code')
|
25
25
|
auth.set_token(nil, nil, nil, nil)
|
26
|
-
|
26
|
+
assert_nil auth.token
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sets token as nil when any input parameter is missing' do
|
30
30
|
auth.stubs(:get_code).returns('code')
|
31
31
|
auth.set_token(nil, params[:oidc_authorization_endpoint], params[:oidc_client_id], params[:oidc_redirect_uri])
|
32
|
-
|
32
|
+
assert_nil auth.token
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -22,12 +22,12 @@ describe HammerCLIForeman::Api::Oauth::PasswordGrant do
|
|
22
22
|
|
23
23
|
it 'sets token as nil when all input parameter are missing' do
|
24
24
|
auth.set_token(nil, nil, nil, nil)
|
25
|
-
|
25
|
+
assert_nil auth.token
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'sets token as nil when any input parameter is missing' do
|
29
29
|
auth.set_token(nil, params[:oidc_client_id], params[:username], params[:password])
|
30
|
-
|
30
|
+
assert_nil auth.token
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/test/unit/api_test.rb
CHANGED
@@ -9,17 +9,16 @@ describe HammerCLIForeman do
|
|
9
9
|
let(:expected_resource) { HammerCLIForeman.foreman_resource!(:architectures) }
|
10
10
|
|
11
11
|
it "finds resource for params with _id" do
|
12
|
-
HammerCLIForeman.param_to_resource("architecture_id").name.must_equal expected_resource.name
|
12
|
+
_(HammerCLIForeman.param_to_resource("architecture_id").name).must_equal expected_resource.name
|
13
13
|
end
|
14
14
|
|
15
15
|
it "finds resource for params without _id" do
|
16
|
-
HammerCLIForeman.param_to_resource("architecture").name.must_equal expected_resource.name
|
16
|
+
_(HammerCLIForeman.param_to_resource("architecture").name).must_equal expected_resource.name
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns nil for unknown resource" do
|
20
|
-
HammerCLIForeman.param_to_resource("unknown")
|
20
|
+
assert_nil HammerCLIForeman.param_to_resource("unknown")
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
|
25
24
|
end
|
@@ -308,11 +308,11 @@ module ResourceMocks
|
|
308
308
|
)
|
309
309
|
end
|
310
310
|
|
311
|
-
def self.
|
312
|
-
ResourceMocks.mock_action_call(:common_parameters, :
|
311
|
+
def self.common_parameter_list
|
312
|
+
ResourceMocks.mock_action_call(:common_parameters, :index, [{
|
313
313
|
"name" => "my param",
|
314
|
-
"value" => "random value"
|
315
|
-
})
|
314
|
+
"value" => "random value",
|
315
|
+
}])
|
316
316
|
end
|
317
317
|
|
318
318
|
def self.config_groups_index
|
data/test/unit/commands_test.rb
CHANGED
@@ -19,16 +19,16 @@ describe HammerCLIForeman do
|
|
19
19
|
]
|
20
20
|
|
21
21
|
set = HammerCLIForeman.collection_to_common_format(old_format)
|
22
|
-
set.must_be_kind_of HammerCLI::Output::RecordCollection
|
23
|
-
set.first.must_equal(kind)
|
22
|
+
_(set).must_be_kind_of HammerCLI::Output::RecordCollection
|
23
|
+
_(set.first).must_equal(kind)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should convert common API format" do
|
27
27
|
common_format = [ kind ]
|
28
28
|
|
29
29
|
set = HammerCLIForeman.collection_to_common_format(common_format)
|
30
|
-
set.must_be_kind_of HammerCLI::Output::RecordCollection
|
31
|
-
set.first.must_equal(kind)
|
30
|
+
_(set).must_be_kind_of HammerCLI::Output::RecordCollection
|
31
|
+
_(set.first).must_equal(kind)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should convert new API format" do
|
@@ -46,12 +46,12 @@ describe HammerCLIForeman do
|
|
46
46
|
}
|
47
47
|
|
48
48
|
set = HammerCLIForeman.collection_to_common_format(new_format)
|
49
|
-
set.must_be_kind_of HammerCLI::Output::RecordCollection
|
50
|
-
set.first.must_equal(kind)
|
49
|
+
_(set).must_be_kind_of HammerCLI::Output::RecordCollection
|
50
|
+
_(set.first).must_equal(kind)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should rise error on unexpected format" do
|
54
|
-
proc { HammerCLIForeman.collection_to_common_format('unexpected') }.must_raise RuntimeError
|
54
|
+
_(proc { HammerCLIForeman.collection_to_common_format('unexpected') }).must_raise RuntimeError
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -67,14 +67,14 @@ describe HammerCLIForeman do
|
|
67
67
|
}
|
68
68
|
|
69
69
|
rec = HammerCLIForeman.record_to_common_format(old_format)
|
70
|
-
rec.must_equal(arch)
|
70
|
+
_(rec).must_equal(arch)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should convert common API format" do
|
74
74
|
common_format = arch
|
75
75
|
|
76
76
|
rec = HammerCLIForeman.record_to_common_format(common_format)
|
77
|
-
rec.must_equal(arch)
|
77
|
+
_(rec).must_equal(arch)
|
78
78
|
|
79
79
|
end
|
80
80
|
end
|
@@ -92,7 +92,7 @@ describe HammerCLIForeman do
|
|
92
92
|
})
|
93
93
|
arch = HammerCLIForeman::Architecture::CreateCommand.new("", { :adapter => :csv, :interactive => false })
|
94
94
|
out, err = capture_io { arch.run(["--name='i386'"]) }
|
95
|
-
out.must_match("Message,Id,Name\nArchitecture created.,3,i386\n")
|
95
|
+
_(out).must_match("Message,Id,Name\nArchitecture created.,3,i386\n")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -111,7 +111,7 @@ describe HammerCLIForeman do
|
|
111
111
|
res.stubs(:get_identifier).returns(1)
|
112
112
|
res.stubs(:get_associated_identifier).returns(1)
|
113
113
|
|
114
|
-
res.get_new_ids.sort.must_equal ['1', '2']
|
114
|
+
_(res.get_new_ids.sort).must_equal ['1', '2']
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should associate resource with new format" do
|
@@ -128,7 +128,7 @@ describe HammerCLIForeman do
|
|
128
128
|
res.stubs(:get_identifier).returns(1)
|
129
129
|
res.stubs(:get_associated_identifier).returns(1)
|
130
130
|
|
131
|
-
res.get_new_ids.sort.must_equal ['1', '2']
|
131
|
+
_(res.get_new_ids.sort).must_equal ['1', '2']
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -152,7 +152,7 @@ describe HammerCLIForeman do
|
|
152
152
|
end
|
153
153
|
comm = DomainOuter::HostsCommand.new("", { :adapter => :csv, :interactive => false })
|
154
154
|
out, err = capture_io { comm.run(["--id=5"]) }
|
155
|
-
out.must_equal "Id,Name,Operating System,Host Group,IP,MAC\n2,random-host,,,192.168.100.112,6e:4b:3c:2c:8a:0a\n"
|
155
|
+
_(out).must_equal "Id,Name,Operating System,Host Group,IP,MAC\n2,random-host,,,192.168.100.112,6e:4b:3c:2c:8a:0a\n"
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
@@ -163,7 +163,7 @@ describe HammerCLIForeman::Command do
|
|
163
163
|
|
164
164
|
it "uses foreman option builder" do
|
165
165
|
builder = HammerCLIForeman::Command.option_builder
|
166
|
-
builder.class.must_equal HammerCLIForeman::ForemanOptionBuilder
|
166
|
+
_(builder.class).must_equal HammerCLIForeman::ForemanOptionBuilder
|
167
167
|
end
|
168
168
|
|
169
169
|
it "properly raises error on intentional searching of parameters that are not required" do
|
@@ -181,9 +181,9 @@ describe HammerCLIForeman::Command do
|
|
181
181
|
)
|
182
182
|
)
|
183
183
|
out, err = capture_io do
|
184
|
-
com.run(['--location', 'loc']).wont_equal HammerCLI::EX_OK
|
184
|
+
_(com.run(['--location', 'loc'])).wont_equal HammerCLI::EX_OK
|
185
185
|
end
|
186
|
-
err.must_equal "Error: Could not find location, please set one of options --location, --location-title, --location-id.\n"
|
186
|
+
_(err).must_equal "Error: Could not find location, please set one of options --location, --location-title, --location-id.\n"
|
187
187
|
|
188
188
|
end
|
189
189
|
|
@@ -205,7 +205,7 @@ describe HammerCLIForeman::Command do
|
|
205
205
|
ResourceMocks.mock_action_call(:domains, :index, [])
|
206
206
|
|
207
207
|
out, err = capture_io do
|
208
|
-
com.run([]).must_equal HammerCLI::EX_OK
|
208
|
+
_(com.run([])).must_equal HammerCLI::EX_OK
|
209
209
|
end
|
210
210
|
|
211
211
|
end
|
@@ -213,7 +213,7 @@ describe HammerCLIForeman::Command do
|
|
213
213
|
describe "build_options" do
|
214
214
|
it "uses build parameters in the block" do
|
215
215
|
HammerCLIForeman::Command.build_options do |o|
|
216
|
-
o.class.must_equal HammerCLIForeman::BuildParams
|
216
|
+
_(o.class).must_equal HammerCLIForeman::BuildParams
|
217
217
|
end
|
218
218
|
end
|
219
219
|
end
|
@@ -228,6 +228,6 @@ describe HammerCLIForeman::ListCommand do
|
|
228
228
|
it 'formats enum values in search fields help' do
|
229
229
|
search_field = { name: 'managed', values: [true, false] }
|
230
230
|
expected_output = 'Values: true, false'
|
231
|
-
OpenListCommand.new({}).search_field_help_value(search_field).must_equal(expected_output)
|
231
|
+
_(OpenListCommand.new({}).search_field_help_value(search_field)).must_equal(expected_output)
|
232
232
|
end
|
233
233
|
end
|
@@ -20,7 +20,7 @@ describe HammerCLIForeman::DependencyResolver do
|
|
20
20
|
|
21
21
|
it "returns empty array for an independent resource" do
|
22
22
|
resource = api.resource(:users)
|
23
|
-
resolver.resource_dependencies(resource).must_equal []
|
23
|
+
_(resolver.resource_dependencies(resource)).must_equal []
|
24
24
|
end
|
25
25
|
|
26
26
|
it "returns list of dependent resources" do
|
@@ -28,7 +28,7 @@ describe HammerCLIForeman::DependencyResolver do
|
|
28
28
|
|
29
29
|
resources = resolver.resource_dependencies(resource).map(&:name).sort_by{ |sym| sym.to_s }
|
30
30
|
expected = [:posts, :users]
|
31
|
-
resources.must_equal expected.sort_by{ |sym| sym.to_s }
|
31
|
+
_(resources).must_equal expected.sort_by{ |sym| sym.to_s }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -36,14 +36,14 @@ describe HammerCLIForeman::DependencyResolver do
|
|
36
36
|
|
37
37
|
it "returns empty array for an independent action" do
|
38
38
|
action = HammerCLIForeman.foreman_resource!(:users).action(:index)
|
39
|
-
resolver.action_dependencies(action).must_equal []
|
39
|
+
_(resolver.action_dependencies(action)).must_equal []
|
40
40
|
end
|
41
41
|
|
42
42
|
it "returns list of dependent resources" do
|
43
43
|
action = HammerCLIForeman.foreman_resource!(:comments).action(:create)
|
44
44
|
resources = resolver.action_dependencies(action).map(&:name).sort_by{ |sym| sym.to_s }
|
45
45
|
expected = [:posts, :users]
|
46
|
-
resources.must_equal expected.sort_by{|sym| sym.to_s}
|
46
|
+
_(resources).must_equal expected.sort_by{|sym| sym.to_s}
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -15,7 +15,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
15
15
|
ex = RestClient::UnprocessableEntity.new(response)
|
16
16
|
output.expects(:print_error).with(heading, "Network address can't be blank\nNetwork address is invalid\nName can't be blank")
|
17
17
|
err_code = handler.handle_exception(ex, :heading => heading)
|
18
|
-
err_code.must_equal HammerCLI::EX_DATAERR
|
18
|
+
_(err_code).must_equal HammerCLI::EX_DATAERR
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should print resource errors on unprocessable entity exception" do
|
@@ -26,21 +26,21 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
26
26
|
ex = RestClient::UnprocessableEntity.new(response)
|
27
27
|
output.expects(:print_error).with(heading, "Network address can't be blank\nNetwork address is invalid\nName can't be blank")
|
28
28
|
err_code = handler.handle_exception(ex, :heading => heading)
|
29
|
-
err_code.must_equal HammerCLI::EX_DATAERR
|
29
|
+
_(err_code).must_equal HammerCLI::EX_DATAERR
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should handle argument error" do
|
33
33
|
ex = ArgumentError.new
|
34
34
|
output.expects(:print_error).with(heading, ex.message)
|
35
35
|
err_code = handler.handle_exception(ex, :heading => heading)
|
36
|
-
err_code.must_equal HammerCLI::EX_USAGE
|
36
|
+
_(err_code).must_equal HammerCLI::EX_USAGE
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should handle forbidden error" do
|
40
40
|
ex = RestClient::Forbidden.new
|
41
41
|
output.expects(:print_error).with('Forbidden - server refused to process the request.', nil)
|
42
42
|
err_code = handler.handle_exception(ex)
|
43
|
-
err_code.must_equal HammerCLI::EX_NOPERM
|
43
|
+
_(err_code).must_equal HammerCLI::EX_NOPERM
|
44
44
|
end
|
45
45
|
|
46
46
|
it "handles forbidden error with permission details" do
|
@@ -57,13 +57,13 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
57
57
|
output.expects(:print_error).with(heading, "Error: message")
|
58
58
|
MyException = Class.new(Exception)
|
59
59
|
err_code = handler.handle_exception(MyException.new('message'), :heading => heading)
|
60
|
-
err_code.must_equal HammerCLI::EX_SOFTWARE
|
60
|
+
_(err_code).must_equal HammerCLI::EX_SOFTWARE
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should handle unsupported operation error" do
|
64
64
|
output.expects(:print_error).with(heading, "message")
|
65
65
|
err_code = handler.handle_exception(HammerCLIForeman::OperationNotSupportedError.new('message'), :heading => heading)
|
66
|
-
err_code.must_equal HammerCLI::EX_UNAVAILABLE
|
66
|
+
_(err_code).must_equal HammerCLI::EX_UNAVAILABLE
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should print resource errors on resource not found exception" do
|
@@ -75,7 +75,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
75
75
|
|
76
76
|
output.expects(:print_error).with(heading, "Resource architecture not found by id '1'")
|
77
77
|
err_code = handler.handle_exception(ex, :heading => heading)
|
78
|
-
err_code.must_equal HammerCLI::EX_NOT_FOUND
|
78
|
+
_(err_code).must_equal HammerCLI::EX_NOT_FOUND
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should print exception message on resource not found exception without explicit message" do
|
@@ -85,7 +85,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
85
85
|
|
86
86
|
output.expects(:print_error).with(heading, "ResourceNotFound message")
|
87
87
|
err_code = handler.handle_exception(ex, :heading => heading)
|
88
|
-
err_code.must_equal HammerCLI::EX_NOT_FOUND
|
88
|
+
_(err_code).must_equal HammerCLI::EX_NOT_FOUND
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should print resource errors on internal error exception" do
|
@@ -97,7 +97,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
97
97
|
|
98
98
|
output.expects(:print_error).with(heading, "Some internal exception")
|
99
99
|
err_code = handler.handle_exception(ex, :heading => heading)
|
100
|
-
err_code.must_equal HammerCLI::EX_SOFTWARE
|
100
|
+
_(err_code).must_equal HammerCLI::EX_SOFTWARE
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should print exception message on internal error exception without formatted message" do
|
@@ -110,7 +110,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
110
110
|
|
111
111
|
output.expects(:print_error).with(heading, "Unformatted\nlines\n")
|
112
112
|
err_code = handler.handle_exception(ex, :heading => heading)
|
113
|
-
err_code.must_equal HammerCLI::EX_SOFTWARE
|
113
|
+
_(err_code).must_equal HammerCLI::EX_SOFTWARE
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should print exception message on internal error exception with message that is not nested" do
|
@@ -122,7 +122,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
122
122
|
|
123
123
|
output.expects(:print_error).with(heading, "Some internal exception")
|
124
124
|
err_code = handler.handle_exception(ex, :heading => heading)
|
125
|
-
err_code.must_equal HammerCLI::EX_SOFTWARE
|
125
|
+
_(err_code).must_equal HammerCLI::EX_SOFTWARE
|
126
126
|
end
|
127
127
|
|
128
128
|
context "redirects" do
|
@@ -133,7 +133,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
133
133
|
|
134
134
|
output.expects(:print_error).with(heading, "Redirection of API call detected.\nIt seems hammer is configured to use HTTP and the server prefers HTTPS.\nUpdate your server url configuration.\nYou can set 'follow_redirects' to one of :default or :always to enable redirects following.")
|
135
135
|
err_code = handler.handle_exception(ex, :heading => heading)
|
136
|
-
err_code.must_equal HammerCLI::EX_CONFIG
|
136
|
+
_(err_code).must_equal HammerCLI::EX_CONFIG
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should detect redirection error" do
|
@@ -142,7 +142,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
142
142
|
|
143
143
|
output.expects(:print_error).with(heading, "Redirection of API call detected.\nUpdate your server url configuration.\nYou can set 'follow_redirects' to one of :default or :always to enable redirects following.")
|
144
144
|
err_code = handler.handle_exception(ex, :heading => heading)
|
145
|
-
err_code.must_equal HammerCLI::EX_CONFIG
|
145
|
+
_(err_code).must_equal HammerCLI::EX_CONFIG
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|