hammer_cli_foreman 2.1.2 → 2.2.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 +8 -4
- data/doc/testing.md +13 -0
- data/lib/hammer_cli_foreman/associating_commands.rb +2 -3
- 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/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/commands/list_test.rb +11 -11
- data/test/functional/host_test.rb +3 -3
- data/test/functional/realm_test.rb +104 -0
- data/test/functional/trend_test.rb +63 -2
- 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 +2 -2
- data/test/unit/id_resolver_test.rb +23 -23
- 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/sessions_test.rb +24 -24
- data/test/unit/template_test.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c478d3535da7a22a10907ad8838baedd0dd1ad9cd3f5168cadab57ef5cc61e53
|
4
|
+
data.tar.gz: d362b8e3e44db4ec092ea2451363be8875cbd1576aaa14e4f8b3652b19ae483f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bebff2d84aacc7ed3053a64920ff86b1420f10d98fc2cfba91a627d69722d5d9866afbf31131c25868ecdf705161ec0401aeaa338f26a5f2f97476664fd1704
|
7
|
+
data.tar.gz: 5dd93dbc8bfff2308ee1768c80ed545dd452278fa0753d2b7016d80ba659741b4c39c1f1b99aa27149e546bc2628b08bcc84419ab5f85cb8ab2ef673952c2581
|
data/doc/release_notes.md
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
|
-
### 2.
|
3
|
+
### 2.2.0 (2020-08-11)
|
4
4
|
* Change config templates to provisioning templates ([PR #531](https://github.com/theforeman/hammer-cli-foreman/pull/531)), [#29971](http://projects.theforeman.org/issues/29971)
|
5
|
+
* Fix minitest deprecation ([PR #523](https://github.com/theforeman/hammer-cli-foreman/pull/523))
|
6
|
+
* Add a coverage test ([PR #522](https://github.com/theforeman/hammer-cli-foreman/pull/522))
|
5
7
|
* Return 'set current context for request' to help ([PR #530](https://github.com/theforeman/hammer-cli-foreman/pull/530)), [#30182](http://projects.theforeman.org/issues/30182)
|
6
|
-
* Display request uuid for audit ([PR #528](https://github.com/theforeman/hammer-cli-foreman/pull/528))
|
7
|
-
|
8
|
-
|
8
|
+
* Display request uuid for audit ([PR #528](https://github.com/theforeman/hammer-cli-foreman/pull/528)), [#30130](http://projects.theforeman.org/issues/30130)
|
9
|
+
* Use parent resource instead of hardcoded one ([PR #527](https://github.com/theforeman/hammer-cli-foreman/pull/527)), [#30125](http://projects.theforeman.org/issues/30125)
|
10
|
+
* Added missing tests to realm command ([PR #526](https://github.com/theforeman/hammer-cli-foreman/pull/526)), [#30096](http://projects.theforeman.org/issues/30096)
|
11
|
+
* Added missing tests to trend test ([PR #525](https://github.com/theforeman/hammer-cli-foreman/pull/525)), [#30070](http://projects.theforeman.org/issues/30070)
|
9
12
|
* Revert "skip one test on ruby 2.7" ([PR #520](https://github.com/theforeman/hammer-cli-foreman/pull/520)), [#28601](http://projects.theforeman.org/issues/28601)
|
10
13
|
* Eliminate auth_type from sessions file ([PR #521](https://github.com/theforeman/hammer-cli-foreman/pull/521)), [#29876](http://projects.theforeman.org/issues/29876)
|
11
14
|
* Add disable option for user ([PR #497](https://github.com/theforeman/hammer-cli-foreman/pull/497)), [#28973](http://projects.theforeman.org/issues/28973)
|
12
15
|
* Added manage command to user mail notifications ([PR #513](https://github.com/theforeman/hammer-cli-foreman/pull/513)), [#7665](http://projects.theforeman.org/issues/7665)
|
16
|
+
* Bump to 2.2.0-develop
|
13
17
|
|
14
18
|
### 2.1.0 (2020-05-14)
|
15
19
|
* Bump hammer_cli to 2.1.0 ([PR #519](https://github.com/theforeman/hammer-cli-foreman/pull/519))
|
data/doc/testing.md
CHANGED
@@ -131,3 +131,16 @@ connection = api_connection
|
|
131
131
|
api = APIExpectationsDecorator.new(connection.api)
|
132
132
|
api.expects_search(:users, 'login=admin')
|
133
133
|
```
|
134
|
+
## Checking the coverage against the API
|
135
|
+
You can check how many API endpoints are covered by Hammer, this test runs all hammer tests,
|
136
|
+
and check which API actions run, therefore there could be two reasons for an endpoint to not be covered:
|
137
|
+
1. there is no test for this action
|
138
|
+
2. there is no hammer command for the API endpoint.
|
139
|
+
### running the coverage test
|
140
|
+
```bash
|
141
|
+
|
142
|
+
rake test TESTOPTS="-c"
|
143
|
+
|
144
|
+
TEST_API_VERSION=2.0 rake test TESTOPTS="-c"
|
145
|
+
|
146
|
+
```
|
@@ -244,8 +244,7 @@ module HammerCLIForeman
|
|
244
244
|
|
245
245
|
def request_params
|
246
246
|
params = super
|
247
|
-
|
248
|
-
template_ids = params['operatingsystem']['provisioning_template_ids']
|
247
|
+
template_ids = params[resource.singular_name]['provisioning_template_ids']
|
249
248
|
if options['option_provisioning_template_search']
|
250
249
|
templates = HammerCLIForeman.collection_to_common_format(
|
251
250
|
associated_resource.call(
|
@@ -259,7 +258,7 @@ module HammerCLIForeman
|
|
259
258
|
template_ids << template_id.to_s
|
260
259
|
end
|
261
260
|
end
|
262
|
-
params[
|
261
|
+
params[resource.singular_name]['provisioning_template_ids'] = template_ids.uniq
|
263
262
|
params
|
264
263
|
end
|
265
264
|
|
@@ -35,7 +35,7 @@ module HammerCLIForeman::Output
|
|
35
35
|
if detail.is_a?(Hash)
|
36
36
|
next if detail[:id] && !show_ids
|
37
37
|
if detail[:label]
|
38
|
-
"#{detail[:label]}: #{get_value(data, detail[:key])}"
|
38
|
+
"#{detail[:label][:target]}: #{get_value(data, detail[:key])}"
|
39
39
|
else
|
40
40
|
get_value(data, detail[:key])
|
41
41
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module HammerCLIForeman
|
2
2
|
module Testing
|
3
3
|
module APIExpectations
|
4
|
+
|
5
|
+
def self.api_calls
|
6
|
+
@api_calls ||= []
|
7
|
+
end
|
8
|
+
|
4
9
|
class APICallMatcher < Mocha::ParameterMatchers::Base
|
5
10
|
attr_accessor :expected_params, :expected_resource, :expected_action, :block
|
6
11
|
|
@@ -160,7 +165,12 @@ module HammerCLIForeman
|
|
160
165
|
}.merge(options))
|
161
166
|
end
|
162
167
|
|
168
|
+
def api_calls
|
169
|
+
HammerCLIForeman::Testing::APIExpectations.api_calls
|
170
|
+
end
|
171
|
+
|
163
172
|
def api_expects(resource=nil, action=nil, note=nil, &block)
|
173
|
+
api_calls << [resource, action]
|
164
174
|
APIExpectationsDecorator.new.expects_call(resource, action, note, &block)
|
165
175
|
end
|
166
176
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Minitest
|
4
|
+
class CoverageRunner
|
5
|
+
|
6
|
+
RESOURCE_BLACK_LIST = ['tasks','home','config_groups','statistics','table_preferences','autosign','puppet_hosts']
|
7
|
+
attr_reader :raw_data, :api_endpoints, :covered_resources, :uncovered_resources, :partially_covered_resources
|
8
|
+
def initialize(file_path)
|
9
|
+
@raw_data = JSON.load(File.open(file_path))
|
10
|
+
@api_endpoints = {}
|
11
|
+
@covered_resources = []
|
12
|
+
@uncovered_resources = []
|
13
|
+
@partially_covered_resources = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def filtered_endpoints(covered)
|
17
|
+
api_endpoints.select { |_k, v| v == covered }.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_endpoints_by_resource(endpoints)
|
21
|
+
endpoints_by_resource = {}
|
22
|
+
endpoints.each do |url|
|
23
|
+
resource,action = url.split("/")
|
24
|
+
endpoints_by_resource[resource] ||= []
|
25
|
+
endpoints_by_resource[resource] << action
|
26
|
+
end
|
27
|
+
endpoints_by_resource
|
28
|
+
end
|
29
|
+
|
30
|
+
def uncovered_endpoints_by_resource
|
31
|
+
get_endpoints_by_resource(filtered_endpoints(false))
|
32
|
+
end
|
33
|
+
|
34
|
+
def covered_endpoints_by_resource
|
35
|
+
get_endpoints_by_resource(filtered_endpoints(true))
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_coverage
|
39
|
+
get_endpoints_by_resource(api_endpoints.keys).each do |resource, actions|
|
40
|
+
if covered_endpoints_by_resource[resource] == actions
|
41
|
+
@covered_resources << resource
|
42
|
+
elsif uncovered_endpoints_by_resource[resource] == actions
|
43
|
+
@uncovered_resources << resource
|
44
|
+
else
|
45
|
+
@partially_covered_resources[resource] = uncovered_endpoints_by_resource[resource]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def endpoints_percentage(endpoints)
|
51
|
+
"#{(endpoints.count / api_endpoints.count.to_f * 100 ).to_i}%"
|
52
|
+
end
|
53
|
+
|
54
|
+
def uncovered_endpoints_percentage
|
55
|
+
endpoints_percentage(filtered_endpoints(false))
|
56
|
+
end
|
57
|
+
|
58
|
+
def covered_endpoints_percentage
|
59
|
+
endpoints_percentage(filtered_endpoints(true))
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_tests
|
63
|
+
raw_data["docs"]["resources"].each do |resource|
|
64
|
+
resource[1]["methods"].each do | method |
|
65
|
+
@api_endpoints[method["doc_url"].delete_prefix!("../apidoc/v2/")] = false
|
66
|
+
end unless RESOURCE_BLACK_LIST.include? resource[0]
|
67
|
+
end
|
68
|
+
HammerCLIForeman::Testing::APIExpectations.api_calls.each do |api_call|
|
69
|
+
resource, action = api_call
|
70
|
+
url = "#{resource}/#{action}"
|
71
|
+
@api_endpoints[url] = true
|
72
|
+
end
|
73
|
+
get_coverage
|
74
|
+
output_coverage
|
75
|
+
end
|
76
|
+
|
77
|
+
def color(str, code)
|
78
|
+
puts "\e[#{code}m#{str}\e[0m"
|
79
|
+
end
|
80
|
+
|
81
|
+
def output_coverage
|
82
|
+
covered_resources
|
83
|
+
color("COVERED RESOURCES" , 32)
|
84
|
+
puts covered_resources
|
85
|
+
color("NOT COVERED AT ALL", 31)
|
86
|
+
puts uncovered_resources
|
87
|
+
color("PARTIALLY COVERED RESOURCES", 33)
|
88
|
+
partially_covered_resources.each do |resource, endpoints|
|
89
|
+
puts "#{resource}: #{endpoints.join(' ')}"
|
90
|
+
end
|
91
|
+
color("covered endpoints #{covered_endpoints_percentage} uncovered endpoints #{uncovered_endpoints_percentage}", 35)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'coverage_reporter'
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Minitest
|
5
|
+
def self.plugin_hammer_coverage_options(opts, options)
|
6
|
+
opts.on "-c", "--coverage", "Generate coverage reports for API endpoints" do
|
7
|
+
options[:coverage] = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.plugin_hammer_coverage_init(options)
|
12
|
+
if options[:coverage]
|
13
|
+
Minitest.reporter.reporters.clear
|
14
|
+
Minitest.after_run do
|
15
|
+
Minitest::CoverageRunner.new("test/data/#{ FOREMAN_VERSION }/foreman_api.json").run_tests
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -39,12 +39,12 @@ describe HammerCLIForeman::ListCommand do
|
|
39
39
|
|
40
40
|
it 'shows search fields in help' do
|
41
41
|
result = run_cmd(cmd + params)
|
42
|
-
result.out.must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+name\s+string/)
|
42
|
+
_(result.out).must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+name\s+string/)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'formats enum values' do
|
46
46
|
result = run_cmd(cmd + params)
|
47
|
-
result.out.must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+managed\s+Values: true, false/)
|
47
|
+
_(result.out).must_match(/.*Search \/ Order fields:\s+(\S+\s+\S+)*\s+managed\s+Values: true, false/)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -53,7 +53,7 @@ describe HammerCLIForeman::ListCommand do
|
|
53
53
|
it "fetches only first page when there's not enough records" do
|
54
54
|
expect_paged_call(1, 1000, 10)
|
55
55
|
result = run_cmd([], {}, TestList)
|
56
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
56
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
57
57
|
end
|
58
58
|
|
59
59
|
it "fetches all records" do
|
@@ -62,27 +62,27 @@ describe HammerCLIForeman::ListCommand do
|
|
62
62
|
expect_paged_call(3, per_page_all, 10)
|
63
63
|
|
64
64
|
result = run_cmd([], {}, TestList)
|
65
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
65
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
66
66
|
end
|
67
67
|
|
68
68
|
it "uses --per-page value" do
|
69
69
|
per_page = 10
|
70
70
|
expect_paged_call(1, per_page, 10)
|
71
71
|
result = run_cmd(["--per-page=#{per_page}"], {}, TestList)
|
72
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
72
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
73
73
|
end
|
74
74
|
|
75
75
|
it "uses both --per-page and --page value" do
|
76
76
|
per_page = 10
|
77
77
|
expect_paged_call(2, per_page, 10)
|
78
78
|
result = run_cmd(["--per-page=#{per_page}", '--page=2'], {}, TestList)
|
79
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
79
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
80
80
|
end
|
81
81
|
|
82
82
|
it "sets per_page to 20 when only --page is used" do
|
83
83
|
expect_paged_call(2, 20, 10)
|
84
84
|
result = run_cmd(['--page=2'], {}, TestList)
|
85
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
85
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -96,20 +96,20 @@ describe HammerCLIForeman::ListCommand do
|
|
96
96
|
per_page = 10
|
97
97
|
expect_paged_call(1, per_page, 10)
|
98
98
|
result = run_cmd(["--per-page=#{per_page}"], {}, TestList)
|
99
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
99
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
100
100
|
end
|
101
101
|
|
102
102
|
it "respects per_page setting when the adapter allows pagination by default" do
|
103
103
|
expect_paged_call(1, per_page_in_settings, 30)
|
104
104
|
result = run_cmd([], { :adapter => :base, :interactive => false }, TestList)
|
105
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
105
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
106
106
|
end
|
107
107
|
|
108
108
|
it "fetches all records when the adapter doesn't allow pagination by default" do
|
109
109
|
expect_paged_call(1, per_page_all, 1000)
|
110
110
|
expect_paged_call(2, per_page_all, 10)
|
111
111
|
result = run_cmd([], { :adapter => :csv, :interactive => false }, TestList)
|
112
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
112
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -128,7 +128,7 @@ describe HammerCLIForeman::ListCommand do
|
|
128
128
|
|
129
129
|
result = run_cmd([], {}, TestListWithOutput)
|
130
130
|
assert_cmd(expected_result, result)
|
131
|
-
result.out.wont_match pagination_line_re
|
131
|
+
_(result.out).wont_match pagination_line_re
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'prints one page when --per-page is used' do
|
@@ -428,7 +428,7 @@ describe 'host config reports' do
|
|
428
428
|
end.returns(index_response([report15]))
|
429
429
|
|
430
430
|
result = run_cmd(['host', 'config-reports', '--id=1'])
|
431
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
431
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
432
432
|
end
|
433
433
|
|
434
434
|
it 'filters reports by --name' do
|
@@ -437,7 +437,7 @@ describe 'host config reports' do
|
|
437
437
|
end.returns(index_response([report15]))
|
438
438
|
|
439
439
|
result = run_cmd(['host', 'config-reports', '--name=host.example.com'])
|
440
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
440
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
441
441
|
end
|
442
442
|
|
443
443
|
it 'prints error or missing --id and --name' do
|
@@ -462,7 +462,7 @@ describe 'host config reports' do
|
|
462
462
|
end.returns(index_response([report15]))
|
463
463
|
|
464
464
|
result = run_cmd(['host', 'config-reports', '--name=host.example.com', '--search=reported > "2 hour ago"'])
|
465
|
-
result.exit_code.must_equal HammerCLI::EX_OK
|
465
|
+
_(result.exit_code).must_equal HammerCLI::EX_OK
|
466
466
|
end
|
467
467
|
end
|
468
468
|
describe 'disassociate host from vm' do
|
@@ -0,0 +1,104 @@
|
|
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['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
|
104
|
+
|