hammer_cli_foreman 2.1.2 → 2.4.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 +35 -4
- data/doc/testing.md +13 -0
- data/lib/hammer_cli_foreman.rb +0 -4
- data/lib/hammer_cli_foreman/architecture.rb +5 -5
- data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
- data/lib/hammer_cli_foreman/auth.rb +4 -4
- data/lib/hammer_cli_foreman/bookmark.rb +6 -6
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
- data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
- data/lib/hammer_cli_foreman/commands.rb +3 -1
- data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
- data/lib/hammer_cli_foreman/config_group.rb +5 -5
- data/lib/hammer_cli_foreman/host.rb +3 -2
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +17 -10
- data/lib/hammer_cli_foreman/location.rb +2 -0
- data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
- data/lib/hammer_cli_foreman/model.rb +5 -5
- data/lib/hammer_cli_foreman/operating_system.rb +10 -9
- 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 +16 -2
- data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -0
- data/lib/hammer_cli_foreman/usergroup.rb +5 -5
- 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/architecture_test.rb +49 -0
- data/test/functional/audit_test.rb +86 -63
- data/test/functional/bookmark_test.rb +20 -0
- data/test/functional/commands/list_test.rb +11 -11
- data/test/functional/compute_profile_test.rb +47 -2
- data/test/functional/config_group_test.rb +50 -0
- data/test/functional/filter_test.rb +114 -47
- data/test/functional/host_test.rb +105 -19
- data/test/functional/location_test.rb +134 -0
- data/test/functional/mail_notification_test.rb +20 -0
- data/test/functional/media_test.rb +130 -0
- data/test/functional/model_test.rb +50 -0
- data/test/functional/operating_system_test.rb +51 -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 +78 -1
- data/test/functional/status_test.rb +79 -13
- data/test/functional/user_test.rb +39 -0
- data/test/functional/usergroup_test.rb +51 -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 +25 -4
- data/test/unit/architecture_test.rb +10 -1
- data/test/unit/bookmark_test.rb +99 -0
- data/test/unit/commands_test.rb +19 -19
- data/test/unit/common_parameter_test.rb +1 -1
- data/test/unit/compute_profile_test.rb +87 -0
- data/test/unit/config_group_test.rb +10 -0
- 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/mail_notification_test.rb +53 -0
- data/test/unit/media_test.rb +1 -1
- data/test/unit/model_test.rb +10 -0
- data/test/unit/operating_system_test.rb +14 -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/settings_test.rb +4 -0
- data/test/unit/template_test.rb +1 -1
- data/test/unit/usergroup_test.rb +10 -0
- metadata +26 -7
- data/lib/hammer_cli_foreman/trend.rb +0 -47
- data/test/functional/trend_test.rb +0 -22
@@ -16,6 +16,8 @@ describe HammerCLIForeman::ConfigGroup do
|
|
16
16
|
context "parameters" do
|
17
17
|
it_should_accept "no arguments"
|
18
18
|
it_should_accept_search_params
|
19
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
20
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
19
21
|
end
|
20
22
|
|
21
23
|
context "output" do
|
@@ -31,6 +33,8 @@ describe HammerCLIForeman::ConfigGroup do
|
|
31
33
|
context "parameters" do
|
32
34
|
it_should_accept "id", ["--id=1"]
|
33
35
|
it_should_accept "name", ["--name=group_x"]
|
36
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
37
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
34
38
|
end
|
35
39
|
|
36
40
|
context "output" do
|
@@ -48,6 +52,8 @@ describe HammerCLIForeman::ConfigGroup do
|
|
48
52
|
|
49
53
|
context "parameters" do
|
50
54
|
it_should_accept "name, puppetclass ids", ["--name=first_group", "--puppet-class-ids=1,2"]
|
55
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
56
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
@@ -57,6 +63,8 @@ describe HammerCLIForeman::ConfigGroup do
|
|
57
63
|
context "parameters" do
|
58
64
|
it_should_accept "name", ["--name=group_x"]
|
59
65
|
it_should_accept "id", ["--id=1"]
|
66
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
67
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
@@ -67,6 +75,8 @@ describe HammerCLIForeman::ConfigGroup do
|
|
67
75
|
context "parameters" do
|
68
76
|
it_should_accept "name", ["--name=group_x"]
|
69
77
|
it_should_accept "id", ["--id=1"]
|
78
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
79
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
70
80
|
end
|
71
81
|
end
|
72
82
|
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
|
|
@@ -97,14 +97,14 @@ module CommandTestHelper
|
|
97
97
|
|
98
98
|
def it_should_fail_with(message, arguments=[])
|
99
99
|
it "should fail with " + message.to_s do
|
100
|
-
cmd.run(arguments).must_equal HammerCLI::EX_USAGE
|
100
|
+
_(cmd.run(arguments)).must_equal HammerCLI::EX_USAGE
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
def it_should_accept(message, arguments=[])
|
105
105
|
it "should accept " + message.to_s do
|
106
106
|
out, err = capture_io do
|
107
|
-
cmd.run(arguments).must_equal HammerCLI::EX_OK
|
107
|
+
_(cmd.run(arguments)).must_equal HammerCLI::EX_OK
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -116,7 +116,7 @@ module CommandTestHelper
|
|
116
116
|
out, err = capture_io do
|
117
117
|
cmd.run(arguments)
|
118
118
|
end
|
119
|
-
out.must_include message
|
119
|
+
_(out).must_include message
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -129,7 +129,7 @@ module CommandTestHelper
|
|
129
129
|
cmd.run(arguments)
|
130
130
|
end
|
131
131
|
|
132
|
-
out.split("\n")[0].must_match /.*##{column_name}#.*/
|
132
|
+
_(out.split("\n")[0]).must_match /.*##{column_name}#.*/
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -148,7 +148,7 @@ module CommandTestHelper
|
|
148
148
|
out, err = capture_io do
|
149
149
|
cmd.run(arguments)
|
150
150
|
end
|
151
|
-
out.split(/\n/).length.must_equal count+1 # plus 1 for line with column headers
|
151
|
+
_(out.split(/\n/).length).must_equal count+1 # plus 1 for line with column headers
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -9,7 +9,7 @@ module ResourceDisabled
|
|
9
9
|
it "should return error" do
|
10
10
|
cmd.class.resource.stubs(:call).raises(RestClient::ResourceNotFound)
|
11
11
|
arguments = respond_to?(:with_params) ? with_params : []
|
12
|
-
cmd.run(arguments).must_equal HammerCLI::EX_UNAVAILABLE
|
12
|
+
_(cmd.run(arguments)).must_equal HammerCLI::EX_UNAVAILABLE
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should print error message" do
|
@@ -17,7 +17,7 @@ module ResourceDisabled
|
|
17
17
|
cmd.stubs(:context).returns(ctx.update(:adapter => :test))
|
18
18
|
|
19
19
|
arguments = respond_to?(:with_params) ? with_params : []
|
20
|
-
lambda { cmd.run(arguments) }.must_output "", /.*not support.*/
|
20
|
+
_(lambda { cmd.run(arguments) }).must_output "", /.*not support.*/
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/test/unit/host_test.rb
CHANGED
@@ -76,7 +76,7 @@ describe HammerCLIForeman::Host do
|
|
76
76
|
|
77
77
|
it "should output status" do
|
78
78
|
cmd.stubs(:context).returns(ctx.update(:adapter => :test))
|
79
|
-
proc { cmd.run(with_params) }.must_output "#Status#Power#\n#No reports#running#\n"
|
79
|
+
_(proc { cmd.run(with_params) }).must_output "#Status#Power#\n#No reports#running#\n"
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -132,29 +132,6 @@ describe HammerCLIForeman::Host do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
|
135
|
-
context "PuppetRunCommand" do
|
136
|
-
|
137
|
-
let(:cmd) { HammerCLIForeman::Host::PuppetRunCommand.new("", ctx) }
|
138
|
-
|
139
|
-
context "parameters" do
|
140
|
-
it_should_accept "name", ["--name=host"]
|
141
|
-
it_should_accept "id", ["--id=1"]
|
142
|
-
# it_should_fail_with "no arguments"
|
143
|
-
# TODO: temporarily disabled, parameters are checked in the id resolver
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
context "output" do
|
148
|
-
with_params ["--id=1"] do
|
149
|
-
it "should inform that puppet was triggered" do
|
150
|
-
cmd.stubs(:context).returns(ctx.update(:adapter => :test))
|
151
|
-
proc { cmd.run(with_params) }.must_output "Puppet run triggered\n"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
135
|
context "ConfigReportsCommand" do
|
159
136
|
before do
|
160
137
|
ResourceMocks.mock_action_call(:config_reports, :index, [])
|
@@ -14,7 +14,7 @@ describe HammerCLIForeman::IdResolver do
|
|
14
14
|
|
15
15
|
describe "scoped options" do
|
16
16
|
it "returns empty hash when there are no options" do
|
17
|
-
resolver.scoped_options("scope", {}).must_equal({})
|
17
|
+
_(resolver.scoped_options("scope", {})).must_equal({})
|
18
18
|
end
|
19
19
|
|
20
20
|
it "unscopes options" do
|
@@ -29,7 +29,7 @@ describe HammerCLIForeman::IdResolver do
|
|
29
29
|
"option_name" => "ACME",
|
30
30
|
"option_a" => :value
|
31
31
|
}
|
32
|
-
resolver.scoped_options("organization", scoped).must_equal(unscoped)
|
32
|
+
_(resolver.scoped_options("organization", scoped)).must_equal(unscoped)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "clears old values" do
|
@@ -43,7 +43,7 @@ describe HammerCLIForeman::IdResolver do
|
|
43
43
|
"option_id" => 2,
|
44
44
|
"option_a" => :value
|
45
45
|
}
|
46
|
-
resolver.scoped_options("organization", scoped).must_equal(unscoped)
|
46
|
+
_(resolver.scoped_options("organization", scoped)).must_equal(unscoped)
|
47
47
|
end
|
48
48
|
|
49
49
|
let(:scoped_multi) {{
|
@@ -63,7 +63,7 @@ describe HammerCLIForeman::IdResolver do
|
|
63
63
|
"option_name" => "ACME",
|
64
64
|
"option_a" => :value
|
65
65
|
}
|
66
|
-
resolver.scoped_options("organization", scoped_multi, :single).must_equal(unscoped)
|
66
|
+
_(resolver.scoped_options("organization", scoped_multi, :single)).must_equal(unscoped)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "unscopes the right options in multi mode" do
|
@@ -75,7 +75,7 @@ describe HammerCLIForeman::IdResolver do
|
|
75
75
|
"option_names" => "Corp",
|
76
76
|
"option_a" => :value
|
77
77
|
}
|
78
|
-
resolver.scoped_options("organization", scoped_multi, :multi).must_equal(unscoped)
|
78
|
+
_(resolver.scoped_options("organization", scoped_multi, :multi)).must_equal(unscoped)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "does not change the original options" do
|
@@ -87,7 +87,7 @@ describe HammerCLIForeman::IdResolver do
|
|
87
87
|
}
|
88
88
|
scoped_original = scoped.dup
|
89
89
|
resolver.scoped_options("organization", scoped)
|
90
|
-
scoped.must_equal(scoped_original)
|
90
|
+
_(scoped).must_equal(scoped_original)
|
91
91
|
end
|
92
92
|
|
93
93
|
end
|
@@ -102,19 +102,19 @@ describe HammerCLIForeman::IdResolver do
|
|
102
102
|
it "must define methods for all resources" do
|
103
103
|
expected_method_names = api.resources.map(&:singular_name).collect{|r| "#{r}_id"}
|
104
104
|
missing_methods = expected_method_names - resolver.methods.map(&:to_s)
|
105
|
-
missing_methods.must_equal []
|
105
|
+
_(missing_methods).must_equal []
|
106
106
|
end
|
107
107
|
|
108
108
|
describe "when no search options are found" do
|
109
109
|
let(:resolver_run) { proc { resolver.comment_id({"option_unknown" => "value"}) } }
|
110
110
|
|
111
111
|
it "raises exception" do
|
112
|
-
err = resolver_run.must_raise HammerCLIForeman::MissingSearchOptions
|
112
|
+
err = _(resolver_run).must_raise HammerCLIForeman::MissingSearchOptions
|
113
113
|
end
|
114
114
|
|
115
115
|
it "builds correct error message" do
|
116
|
-
err = resolver_run.must_raise HammerCLIForeman::MissingSearchOptions
|
117
|
-
err.message.must_equal "Missing options to search comment."
|
116
|
+
err = _(resolver_run).must_raise HammerCLIForeman::MissingSearchOptions
|
117
|
+
_(err.message).must_equal "Missing options to search comment."
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -124,15 +124,15 @@ describe HammerCLIForeman::IdResolver do
|
|
124
124
|
it "raises exception when no resource is found" do
|
125
125
|
ResourceMocks.mock_action_call(:users, :index, index_response([]))
|
126
126
|
|
127
|
-
err = resolver_run.must_raise HammerCLIForeman::ResolverError
|
128
|
-
err.message.must_equal "user not found."
|
127
|
+
err = _(resolver_run).must_raise HammerCLIForeman::ResolverError
|
128
|
+
_(err.message).must_equal "user not found."
|
129
129
|
end
|
130
130
|
|
131
131
|
it "raises exception when multiple resources are found" do
|
132
132
|
ResourceMocks.mock_action_call(:users, :index, index_response([john, jane]))
|
133
133
|
|
134
|
-
err = resolver_run.must_raise HammerCLIForeman::ResolverError
|
135
|
-
err.message.must_equal "Found more than one user."
|
134
|
+
err = _(resolver_run).must_raise HammerCLIForeman::ResolverError
|
135
|
+
_(err.message).must_equal "Found more than one user."
|
136
136
|
end
|
137
137
|
|
138
138
|
it "calls index action with appropriate search params" do
|
@@ -148,17 +148,17 @@ describe HammerCLIForeman::IdResolver do
|
|
148
148
|
it "uses option id when it's available" do
|
149
149
|
ResourceMocks.mock_action_call(:users, :index, [])
|
150
150
|
|
151
|
-
resolver.user_id({"option_id" => 83, "option_name" => "John Doe"}).must_equal 83
|
151
|
+
_(resolver.user_id({"option_id" => 83, "option_name" => "John Doe"})).must_equal 83
|
152
152
|
end
|
153
153
|
|
154
154
|
it "returns NIL when the search name is NIL" do
|
155
|
-
resolver.user_id({"option_name" => HammerCLI::NilValue}).must_equal HammerCLI::NilValue
|
155
|
+
_(resolver.user_id({"option_name" => HammerCLI::NilValue})).must_equal HammerCLI::NilValue
|
156
156
|
end
|
157
157
|
|
158
158
|
it "returns id of the resource" do
|
159
159
|
ResourceMocks.mock_action_call(:users, :index, index_response([john]))
|
160
160
|
|
161
|
-
resolver_run.call.must_equal john_id
|
161
|
+
_(resolver_run.call).must_equal john_id
|
162
162
|
end
|
163
163
|
|
164
164
|
end
|
@@ -170,16 +170,16 @@ describe HammerCLIForeman::IdResolver do
|
|
170
170
|
ResourceMocks.mock_action_call(:posts, :index, index_response([]))
|
171
171
|
ResourceMocks.mock_action_call(:users, :index, index_response([]))
|
172
172
|
|
173
|
-
err = resolver_run.must_raise HammerCLIForeman::ResolverError
|
174
|
-
err.message.must_equal "user not found."
|
173
|
+
err = _(resolver_run).must_raise HammerCLIForeman::ResolverError
|
174
|
+
_(err.message).must_equal "user not found."
|
175
175
|
end
|
176
176
|
|
177
177
|
it "raises exception when multiple resources are found" do
|
178
178
|
ResourceMocks.mock_action_call(:posts, :index, index_response([]))
|
179
179
|
ResourceMocks.mock_action_call(:users, :index, index_response([john, jane]))
|
180
180
|
|
181
|
-
err = resolver_run.must_raise HammerCLIForeman::ResolverError
|
182
|
-
err.message.must_equal "Found more than one user."
|
181
|
+
err = _(resolver_run).must_raise HammerCLIForeman::ResolverError
|
182
|
+
_(err.message).must_equal "Found more than one user."
|
183
183
|
end
|
184
184
|
|
185
185
|
it "calls index action with appropriate search params" do
|
@@ -209,7 +209,7 @@ describe HammerCLIForeman::IdResolver do
|
|
209
209
|
{"id" => 22, "name" => "User 22"}
|
210
210
|
]
|
211
211
|
))
|
212
|
-
resolver_run.call.must_equal 11
|
212
|
+
_(resolver_run.call).must_equal 11
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -288,7 +288,7 @@ describe HammerCLIForeman::IdResolver do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
it "returns NilValue when the search name is NilValue" do
|
291
|
-
resolver.user_ids({"option_names" => HammerCLI::NilValue}).must_equal HammerCLI::NilValue
|
291
|
+
_(resolver.user_ids({"option_names" => HammerCLI::NilValue})).must_equal HammerCLI::NilValue
|
292
292
|
end
|
293
293
|
end
|
294
294
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
4
|
+
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
5
|
+
|
6
|
+
require 'hammer_cli_foreman/mail_notification'
|
7
|
+
|
8
|
+
describe HammerCLIForeman::MailNotification do
|
9
|
+
include CommandTestHelper
|
10
|
+
|
11
|
+
context 'ListCommand' do
|
12
|
+
before :each do
|
13
|
+
ResourceMocks.mail_notifications
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:cmd) { HammerCLIForeman::MailNotification::ListCommand.new('', ctx) }
|
17
|
+
|
18
|
+
context 'parameters' do
|
19
|
+
it_should_accept 'no arguments'
|
20
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
21
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'output' do
|
25
|
+
let(:expected_record_count) { count_records(cmd.resource.call(:index)) }
|
26
|
+
|
27
|
+
it_should_print_n_records
|
28
|
+
it_should_print_column 'Id'
|
29
|
+
it_should_print_column 'Name'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'InfoCommand' do
|
34
|
+
let(:cmd) { HammerCLIForeman::MailNotification::InfoCommand.new('', ctx) }
|
35
|
+
|
36
|
+
context 'parameters' do
|
37
|
+
it_should_accept 'id', ['--id=1']
|
38
|
+
it_should_accept 'name', ['--name=test']
|
39
|
+
it_should_fail_with 'organization param', ['--organization-id=1']
|
40
|
+
it_should_fail_with 'location param', ['--location-id=1']
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'output' do
|
44
|
+
with_params ['--id=1'] do
|
45
|
+
it_should_print_n_records 1
|
46
|
+
it_should_print_column 'Id'
|
47
|
+
it_should_print_column 'Name'
|
48
|
+
it_should_print_column 'Description'
|
49
|
+
it_should_print_column 'Subscription type'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|