hammer_cli_foreman_puppet 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hammer_cli_foreman_puppet/associating_commands.rb +1 -1
- data/lib/hammer_cli_foreman_puppet/class.rb +1 -3
- data/lib/hammer_cli_foreman_puppet/combination.rb +0 -1
- data/lib/hammer_cli_foreman_puppet/command_extensions/combination.rb +3 -3
- data/lib/hammer_cli_foreman_puppet/commands.rb +3 -2
- data/lib/hammer_cli_foreman_puppet/host.rb +4 -5
- data/lib/hammer_cli_foreman_puppet/hostgroup.rb +7 -8
- data/lib/hammer_cli_foreman_puppet/i18n.rb +2 -2
- data/lib/hammer_cli_foreman_puppet/id_resolver.rb +5 -5
- data/lib/hammer_cli_foreman_puppet/option_sources/puppet_environment_params.rb +1 -2
- data/lib/hammer_cli_foreman_puppet/puppet_references.rb +0 -1
- data/lib/hammer_cli_foreman_puppet/smart_class_parameter.rb +6 -6
- data/lib/hammer_cli_foreman_puppet/smart_proxy.rb +2 -2
- data/lib/hammer_cli_foreman_puppet/version.rb +1 -1
- data/locale/cs_CZ/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/cs_CZ/hammer-cli-foreman-puppet.po +282 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/de/hammer-cli-foreman-puppet.po +293 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/en/hammer-cli-foreman-puppet.po +276 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/es/hammer-cli-foreman-puppet.po +287 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/fr/hammer-cli-foreman-puppet.po +285 -0
- data/locale/hammer-cli-foreman-puppet.pot +386 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/ja/hammer-cli-foreman-puppet.po +283 -0
- data/locale/ka/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/ka/hammer-cli-foreman-puppet.po +280 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/pt_BR/hammer-cli-foreman-puppet.po +288 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
- data/locale/zh_CN/hammer-cli-foreman-puppet.po +283 -0
- metadata +31 -57
- data/test/data/2.1/foreman_api.json +0 -1
- data/test/data/3.0/foreman_api.json +0 -1
- data/test/data/3.3/foreman_api.json +0 -1
- data/test/data/README.md +0 -27
- data/test/functional/config_group_test.rb +0 -28
- data/test/functional/host/create_test.rb +0 -195
- data/test/functional/host/update_test.rb +0 -126
- data/test/functional/hostgroup/create_test.rb +0 -178
- data/test/functional/hostgroup/update_test.rb +0 -126
- data/test/functional/proxy_test.rb +0 -86
- data/test/functional/smart_class_parameter_test.rb +0 -97
- data/test/functional/template_test.rb +0 -38
- data/test/functional/test_helper.rb +0 -7
- data/test/test_helper.rb +0 -29
- data/test/unit/apipie_resource_mock.rb +0 -186
- data/test/unit/config_group_test.rb +0 -73
- data/test/unit/helpers/command.rb +0 -163
- data/test/unit/helpers/fake_searchables.rb +0 -19
- data/test/unit/helpers/resource_disabled.rb +0 -24
- data/test/unit/puppet_class_test.rb +0 -72
- data/test/unit/puppet_environment_test.rb +0 -116
- data/test/unit/smart_class_parameter_test.rb +0 -114
- data/test/unit/test_helper.rb +0 -18
- data/test/unit/test_output_adapter.rb +0 -22
@@ -1,86 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe 'proxy' do
|
4
|
-
describe 'import-classes' do
|
5
|
-
let(:cmd) { ['proxy', 'import-classes'] }
|
6
|
-
let(:params) { ['--id=83'] }
|
7
|
-
let(:report) do
|
8
|
-
{
|
9
|
-
'message' => 'Successfully updated environment and puppetclasses from the on-disk puppet installation',
|
10
|
-
'environments_with_new_puppetclasses' => 2,
|
11
|
-
'environments_updated_puppetclasses' => 0,
|
12
|
-
'environments_obsolete' => 0,
|
13
|
-
'environments_ignored' => 0,
|
14
|
-
'results' => [{
|
15
|
-
'name' => 'development',
|
16
|
-
'actions' => [ 'new', 'update' ],
|
17
|
-
'new_puppetclasses' => [
|
18
|
-
'motd',
|
19
|
-
'hammer'
|
20
|
-
],
|
21
|
-
'updated_puppetclasses' => [
|
22
|
-
'stdlib',
|
23
|
-
'vim'
|
24
|
-
]
|
25
|
-
},{
|
26
|
-
'name' => 'production',
|
27
|
-
'actions' => [ 'obsolete', 'ignore' ],
|
28
|
-
'obsolete_puppetclasses' => [
|
29
|
-
'apache'
|
30
|
-
],
|
31
|
-
'ignored_puppetclasses' => [
|
32
|
-
'hammer'
|
33
|
-
]
|
34
|
-
}]
|
35
|
-
}
|
36
|
-
end
|
37
|
-
let(:no_change_report) do
|
38
|
-
{
|
39
|
-
'message' => 'No changes to your environments detected'
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'prints detailed report' do
|
44
|
-
api_expects(:smart_proxies, :import_puppetclasses, 'Import classes')
|
45
|
-
.with_params('id' => '83')
|
46
|
-
.returns(report)
|
47
|
-
|
48
|
-
output = OutputMatcher.new([
|
49
|
-
'Result:',
|
50
|
-
' Successfully updated environment and puppetclasses from the on-disk puppet installation',
|
51
|
-
'Changed environments:',
|
52
|
-
' 1) development',
|
53
|
-
' New classes:',
|
54
|
-
' motd',
|
55
|
-
' hammer',
|
56
|
-
' Updated classes:',
|
57
|
-
' stdlib',
|
58
|
-
' vim',
|
59
|
-
' 2) production',
|
60
|
-
' Removed classes:',
|
61
|
-
' apache',
|
62
|
-
' Ignored classes:',
|
63
|
-
' hammer'
|
64
|
-
])
|
65
|
-
expected_result = success_result(output)
|
66
|
-
|
67
|
-
result = run_cmd(cmd + params)
|
68
|
-
assert_cmd(expected_result, result)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'prints a message when nothig has changed' do
|
72
|
-
api_expects(:smart_proxies, :import_puppetclasses, 'Import classes')
|
73
|
-
.with_params('id' => '83')
|
74
|
-
.returns(no_change_report)
|
75
|
-
|
76
|
-
output = OutputMatcher.new([
|
77
|
-
'Result:',
|
78
|
-
' No changes to your environments detected'
|
79
|
-
])
|
80
|
-
expected_result = success_result(output)
|
81
|
-
|
82
|
-
result = run_cmd(cmd + params)
|
83
|
-
assert_cmd(expected_result, result)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe 'sc-params update' do
|
4
|
-
let(:cmd) { %w[sc-param update] }
|
5
|
-
|
6
|
-
it 'does not allow to update parameter name' do
|
7
|
-
params = ['--id=1', '--new-name=name2']
|
8
|
-
|
9
|
-
expected_result = usage_error_result(
|
10
|
-
cmd,
|
11
|
-
"Unrecognised option '--new-name'.",
|
12
|
-
'Could not update the parameter'
|
13
|
-
)
|
14
|
-
|
15
|
-
api_expects_no_call
|
16
|
-
result = run_cmd(cmd + params)
|
17
|
-
assert_cmd(expected_result, result)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'sc-params add-matcher' do
|
22
|
-
let(:cmd) { %w[sc-param add-matcher] }
|
23
|
-
let(:override_value) { 'something' }
|
24
|
-
let(:match) { 'domain = example.com' }
|
25
|
-
let(:puppet_class) { { 'name' => 'motd', 'id' => '1' } }
|
26
|
-
let(:parameter) { { 'name' => 'content', 'id' => '2' } }
|
27
|
-
let(:base) do
|
28
|
-
[
|
29
|
-
'--puppet-class', puppet_class['name'],
|
30
|
-
'--smart-class-parameter', parameter['name'],
|
31
|
-
'--match', match
|
32
|
-
]
|
33
|
-
end
|
34
|
-
|
35
|
-
def api_expects_parameter_search(puppet_class, parameter)
|
36
|
-
api_expects(:puppetclasses, :index, 'Find puppet class') do |par|
|
37
|
-
par[:search] == %Q(name = "#{puppet_class['name']}")
|
38
|
-
end.returns(index_response('motd' => [puppet_class]))
|
39
|
-
|
40
|
-
api_expects(:smart_class_parameters, :index, 'Find smart parameter') do |par|
|
41
|
-
par[:search] == %Q(key = "#{parameter['name']}") &&
|
42
|
-
par[:puppetclass_id] == puppet_class['id']
|
43
|
-
end.returns(index_response([parameter]))
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'allows to set value' do
|
47
|
-
params = ['--value', override_value]
|
48
|
-
expected_result = success_result("Override value created.\n")
|
49
|
-
|
50
|
-
api_expects_parameter_search(puppet_class, parameter)
|
51
|
-
|
52
|
-
api_expects(:override_values, :create, 'Create override value').with_params(
|
53
|
-
smart_class_parameter_id: parameter['id'],
|
54
|
-
override_value: {
|
55
|
-
match: match,
|
56
|
-
value: override_value
|
57
|
-
}
|
58
|
-
)
|
59
|
-
|
60
|
-
result = run_cmd(cmd + base + params)
|
61
|
-
assert_cmd(expected_result, result)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'allows to set value with disabled puppet default' do
|
65
|
-
params = ['--value', override_value, '--omit', false]
|
66
|
-
expected_result = success_result("Override value created.\n")
|
67
|
-
|
68
|
-
api_expects_parameter_search(puppet_class, parameter)
|
69
|
-
|
70
|
-
api_expects(:override_values, :create, 'Create override value').with_params(
|
71
|
-
smart_class_parameter_id: parameter['id'],
|
72
|
-
override_value: {
|
73
|
-
match: match,
|
74
|
-
value: override_value,
|
75
|
-
omit: false
|
76
|
-
}
|
77
|
-
)
|
78
|
-
|
79
|
-
result = run_cmd(cmd + base + params)
|
80
|
-
assert_cmd(expected_result, result)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'does not allow to use puppet default and value at the same time' do
|
84
|
-
params = ['--value', 'something', '--omit', true]
|
85
|
-
|
86
|
-
expected_result = usage_error_result(
|
87
|
-
cmd,
|
88
|
-
'Cannot use --value when --omit is true.',
|
89
|
-
'Could not create the override value'
|
90
|
-
)
|
91
|
-
|
92
|
-
api_expects_parameter_search(puppet_class, parameter)
|
93
|
-
|
94
|
-
result = run_cmd(cmd + base + params)
|
95
|
-
assert_cmd(expected_result, result)
|
96
|
-
end
|
97
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe 'template' do
|
4
|
-
describe 'combinations' do
|
5
|
-
before do
|
6
|
-
@cmd = %w[template combination]
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should create new combination' do
|
10
|
-
params = ['create', '--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
|
11
|
-
expected_result = success_result("Template combination created.\n")
|
12
|
-
api_expects(:template_combinations, :create, 'Create template combination') do |p|
|
13
|
-
p['provisioning_template_id'] == '10' &&
|
14
|
-
p['hostgroup_id'] == '1' &&
|
15
|
-
p['environment_id'] == 1 &&
|
16
|
-
p['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => '1' }
|
17
|
-
end
|
18
|
-
|
19
|
-
result = run_cmd(@cmd + params)
|
20
|
-
assert_cmd(expected_result, result)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should update combination' do
|
24
|
-
params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
|
25
|
-
expected_result = success_result("Template combination updated.\n")
|
26
|
-
api_expects(:template_combinations, :update, 'Update template combination') do |p|
|
27
|
-
p['id'] == '3' &&
|
28
|
-
p['provisioning_template_id'] == '10' &&
|
29
|
-
p['hostgroup_id'] == '1' &&
|
30
|
-
p['environment_id'] == 1 &&
|
31
|
-
p['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => '1' }
|
32
|
-
end
|
33
|
-
|
34
|
-
result = run_cmd(@cmd + params)
|
35
|
-
assert_cmd(expected_result, result)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
require 'pathname'
|
3
|
-
|
4
|
-
SimpleCov.use_merging true
|
5
|
-
SimpleCov.start do
|
6
|
-
command_name 'MiniTest'
|
7
|
-
add_filter 'test'
|
8
|
-
end
|
9
|
-
SimpleCov.root Pathname.new(File.dirname(__FILE__) + "../../../")
|
10
|
-
|
11
|
-
|
12
|
-
require 'minitest/autorun'
|
13
|
-
require 'minitest/spec'
|
14
|
-
require "minitest-spec-context"
|
15
|
-
require "mocha/minitest"
|
16
|
-
|
17
|
-
require 'hammer_cli'
|
18
|
-
require 'hammer_cli/testing/command_assertions'
|
19
|
-
require 'hammer_cli_foreman/testing/api_expectations'
|
20
|
-
FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.3')
|
21
|
-
|
22
|
-
include HammerCLI::Testing::CommandAssertions
|
23
|
-
include HammerCLIForeman::Testing::APIExpectations
|
24
|
-
HammerCLI.context[:api_connection].create('foreman') do
|
25
|
-
api_connection({}, FOREMAN_VERSION)
|
26
|
-
end
|
27
|
-
|
28
|
-
require 'hammer_cli_foreman'
|
29
|
-
require 'hammer_cli_foreman_puppet'
|
@@ -1,186 +0,0 @@
|
|
1
|
-
module ResourceMocks
|
2
|
-
|
3
|
-
def self.mock_action_call(resource, action, value, params=:default)
|
4
|
-
response = ApipieBindings::Example.new('GET', '/', '', 200, JSON.dump(value))
|
5
|
-
@mocks ||= {}
|
6
|
-
@mocks[[resource, action]] ||= {}
|
7
|
-
@mocks[[resource, action]][params] = response
|
8
|
-
ApipieBindings::API.any_instance.stubs(:fake_responses).returns(@mocks)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.clear_mocks
|
12
|
-
@mocks = {}
|
13
|
-
ApipieBindings::API.any_instance.stubs(:fake_responses).returns(@mocks)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.mock_action_calls(*calls)
|
17
|
-
calls.each do |(resource, action, value, params)|
|
18
|
-
mock_action_call(resource, action, value, (params || :default))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.smart_class_parameters_index
|
23
|
-
ResourceMocks.mock_action_call(:smart_class_parameters, :index,
|
24
|
-
{ "results" => [ { 'parameter' => 'config', 'id' => '1'} ] })
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.smart_class_parameters_show
|
28
|
-
ResourceMocks.mock_action_call(:smart_class_parameters, :show, { 'smart_class_parameter' => { 'override_value_order' => '', 'environments' => [] }})
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.smart_variables_index
|
32
|
-
ResourceMocks.mock_action_call(:smart_variables, :index,
|
33
|
-
{ "results" => [ { 'variable' => 'var', 'id' => '1'} ] })
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.smart_variables_show
|
37
|
-
ResourceMocks.mock_action_call(:smart_variables, :show, { "id" => 1, "override_value_order" => "fqdn" })
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.organizations_index
|
41
|
-
ResourceMocks.mock_action_call(:organizations, :index, {
|
42
|
-
"results" => [
|
43
|
-
{
|
44
|
-
"label" => "Default_Organization",
|
45
|
-
"id" => 1,
|
46
|
-
"name" => "Default_Organization",
|
47
|
-
"title" => "Default_Organization"
|
48
|
-
}
|
49
|
-
]})
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.hosts_show
|
53
|
-
ResourceMocks.mock_action_call(:hosts, :show, {
|
54
|
-
"ip" => "192.168.122.51",
|
55
|
-
"ip6" => nil,
|
56
|
-
"environment_id" => 1,
|
57
|
-
"environment_name" => "production",
|
58
|
-
"last_report" => "2016-10-24 12:06:31 UTC",
|
59
|
-
"mac" => "52:54:00:ce:b2:b9",
|
60
|
-
"realm_id" => nil,
|
61
|
-
"realm_name" => nil,
|
62
|
-
"sp_mac" => nil,
|
63
|
-
"sp_ip" => nil,
|
64
|
-
"sp_name" => nil,
|
65
|
-
"domain_id" => 1,
|
66
|
-
"domain_name" => "tstrachota.usersys.redhat.com",
|
67
|
-
"architecture_id" => 1,
|
68
|
-
"architecture_name" => "x86_64",
|
69
|
-
"operatingsystem_id" => 1,
|
70
|
-
"operatingsystem_name" => "CentOS 7.2.1511",
|
71
|
-
"build" => false,
|
72
|
-
"model_id" => 1,
|
73
|
-
"hostgroup_id" => nil,
|
74
|
-
"owner_id" => nil,
|
75
|
-
"owner_type" => nil,
|
76
|
-
"enabled" => true,
|
77
|
-
"managed" => false,
|
78
|
-
"use_image" => nil,
|
79
|
-
"image_file" => "",
|
80
|
-
"uuid" => nil,
|
81
|
-
"compute_resource_id" => nil,
|
82
|
-
"compute_resource_name" => nil,
|
83
|
-
"compute_profile_id" => nil,
|
84
|
-
"compute_profile_name" => nil,
|
85
|
-
"capabilities" => ["build"],
|
86
|
-
"provision_method" => "build",
|
87
|
-
"certname" => "foreman.example.com",
|
88
|
-
"image_id" => nil,
|
89
|
-
"image_name" => nil,
|
90
|
-
"created_at" => "2016-10-24 08:36:43 UTC",
|
91
|
-
"updated_at" => "2016-10-24 12:06:46 UTC",
|
92
|
-
"last_compile" => "2016-10-24 12:06:41 UTC",
|
93
|
-
"global_status" => 0,
|
94
|
-
"global_status_label" => "Warning",
|
95
|
-
"organization_id" => nil,
|
96
|
-
"organization_name" => nil,
|
97
|
-
"location_id" => nil,
|
98
|
-
"location_name" => nil,
|
99
|
-
"puppet_status" => 0,
|
100
|
-
"model_name" => "KVM",
|
101
|
-
"configuration_status" => 0,
|
102
|
-
"configuration_status_label" => "No reports",
|
103
|
-
"name" => "foreman.example.com",
|
104
|
-
"id" => 1,
|
105
|
-
"puppet_proxy_id" => 1,
|
106
|
-
"puppet_proxy_name" => "foreman.example.com",
|
107
|
-
"puppet_ca_proxy_id" => 1,
|
108
|
-
"puppet_ca_proxy_name" => "foreman.example.com",
|
109
|
-
"puppet_proxy" => {
|
110
|
-
"name" => "foreman.example.com",
|
111
|
-
"id" => 1,
|
112
|
-
"url" => "https://foreman.example.com:9090"
|
113
|
-
},
|
114
|
-
"puppet_ca_proxy" => {
|
115
|
-
"name" => "foreman.example.com",
|
116
|
-
"id" => 1,
|
117
|
-
"url" => "https://foreman.example.com:9090"
|
118
|
-
},
|
119
|
-
"hostgroup_name" => nil,
|
120
|
-
"hostgroup_title" => nil,
|
121
|
-
"parameters" => [],
|
122
|
-
"all_parameters" => [],
|
123
|
-
"interfaces" => [{
|
124
|
-
"id" => 1,
|
125
|
-
"name" => "foreman.example.com",
|
126
|
-
"ip" => "192.168.122.51",
|
127
|
-
"mac" => "52:54:00:ce:b2:b9",
|
128
|
-
"identifier" => "eth0",
|
129
|
-
"primary" => true,
|
130
|
-
"provision" => true,
|
131
|
-
"type" => "interface"
|
132
|
-
},
|
133
|
-
{
|
134
|
-
"id" => 2,
|
135
|
-
"name" => nil,
|
136
|
-
"ip" => "10.34.130.105",
|
137
|
-
"mac" => "52:54:00:f5:1b:57",
|
138
|
-
"identifier" => "eth1",
|
139
|
-
"primary" => false,
|
140
|
-
"provision" => false,
|
141
|
-
"type" => "interface"
|
142
|
-
}],
|
143
|
-
"puppetclasses" => [],
|
144
|
-
"config_groups" => [],
|
145
|
-
"all_puppetclasses" => []
|
146
|
-
})
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
def self.organizations_show
|
151
|
-
ResourceMocks.mock_action_calls(
|
152
|
-
[:organizations, :index, [{ "id" => 2, "name" => "ACME" }]],
|
153
|
-
[:organizations, :show, { "id" => 2, "name" => "ACME" }]
|
154
|
-
)
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.locations_index
|
158
|
-
ResourceMocks.mock_action_call(:locations, :index, {
|
159
|
-
"results" => [
|
160
|
-
{
|
161
|
-
"ancestry" => nil,
|
162
|
-
"created_at" => "2014-07-17T17:21:49+02:00",
|
163
|
-
"updated_at" => "2015-06-17T13:18:10+02:00",
|
164
|
-
"id" => 2,
|
165
|
-
"name" => "Default_Location",
|
166
|
-
"title" => "Default_Location"
|
167
|
-
}
|
168
|
-
]})
|
169
|
-
end
|
170
|
-
|
171
|
-
def self.locations_show
|
172
|
-
ResourceMocks.mock_action_calls(
|
173
|
-
[:locations, :index, [{ "id" => 2, "name" => "Rack" }]],
|
174
|
-
[:locations, :show, { "id" => 2, "name" => "Rack" }]
|
175
|
-
)
|
176
|
-
end
|
177
|
-
|
178
|
-
def self.config_groups_index
|
179
|
-
ResourceMocks.mock_action_call(:config_groups, :index, [{
|
180
|
-
id: 15,
|
181
|
-
name: "test config group",
|
182
|
-
puppetclasses: [ { name: "My puppetclass" } ]
|
183
|
-
}])
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
3
|
-
|
4
|
-
require 'hammer_cli_foreman_puppet/config_group'
|
5
|
-
|
6
|
-
describe HammerCLIForemanPuppet::ConfigGroup do
|
7
|
-
include CommandTestHelper
|
8
|
-
|
9
|
-
context "ListCommand" do
|
10
|
-
let(:cmd) { HammerCLIForemanPuppet::ConfigGroup::ListCommand.new("", ctx) }
|
11
|
-
|
12
|
-
before :each do
|
13
|
-
ResourceMocks.config_groups_index
|
14
|
-
end
|
15
|
-
|
16
|
-
context "parameters" do
|
17
|
-
it_should_accept "no arguments"
|
18
|
-
it_should_accept_search_params
|
19
|
-
end
|
20
|
-
|
21
|
-
context "output" do
|
22
|
-
let(:expected_record_count) { cmd.resource.call(:index).length }
|
23
|
-
it_should_print_n_records
|
24
|
-
it_should_print_columns ["ID", "Name"]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "InfoCommand" do
|
29
|
-
let(:cmd) { HammerCLIForemanPuppet::ConfigGroup::InfoCommand.new("", ctx) }
|
30
|
-
|
31
|
-
context "parameters" do
|
32
|
-
it_should_accept "id", ["--id=1"]
|
33
|
-
it_should_accept "name", ["--name=group_x"]
|
34
|
-
end
|
35
|
-
|
36
|
-
context "output" do
|
37
|
-
with_params ["--id=1"] do
|
38
|
-
it_should_print_n_records 1
|
39
|
-
it_should_print_column "Name"
|
40
|
-
it_should_print_column "ID"
|
41
|
-
it_should_print_column "Puppetclasses"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "CreateCommand" do
|
47
|
-
let(:cmd) { HammerCLIForemanPuppet::ConfigGroup::CreateCommand.new("", ctx) }
|
48
|
-
|
49
|
-
context "parameters" do
|
50
|
-
it_should_accept 'name, puppetclass ids',
|
51
|
-
%w[--name=first_group --puppet-class-ids=1,2]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "DeleteCommand" do
|
56
|
-
let(:cmd) { HammerCLIForemanPuppet::ConfigGroup::DeleteCommand.new("", ctx) }
|
57
|
-
|
58
|
-
context "parameters" do
|
59
|
-
it_should_accept "name", ["--name=group_x"]
|
60
|
-
it_should_accept "id", ["--id=1"]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "UpdateCommand" do
|
65
|
-
|
66
|
-
let(:cmd) { HammerCLIForemanPuppet::ConfigGroup::UpdateCommand.new("", ctx) }
|
67
|
-
|
68
|
-
context "parameters" do
|
69
|
-
it_should_accept "name", ["--name=group_x"]
|
70
|
-
it_should_accept "id", ["--id=1"]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../test_output_adapter')
|
2
|
-
|
3
|
-
class IdResolverTestProxy
|
4
|
-
|
5
|
-
attr_reader :api
|
6
|
-
|
7
|
-
def initialize(original_resolver)
|
8
|
-
@original_resolver = original_resolver
|
9
|
-
define_id_finders
|
10
|
-
end
|
11
|
-
|
12
|
-
def scoped_options(scope, options, mode = nil)
|
13
|
-
@original_resolver.scoped_options(scope, options, mode)
|
14
|
-
end
|
15
|
-
|
16
|
-
def searchables(resource)
|
17
|
-
@original_resolver.searchables(resource)
|
18
|
-
end
|
19
|
-
|
20
|
-
def puppet_environment_id(options)
|
21
|
-
environment_id(options)
|
22
|
-
end
|
23
|
-
|
24
|
-
def puppet_environment_ids(options)
|
25
|
-
environment_ids(options)
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
def define_id_finders
|
31
|
-
@original_resolver.api.resources.each do |resource|
|
32
|
-
method_name = "#{resource.singular_name}_id"
|
33
|
-
self.class.send(:define_method, method_name) do |options|
|
34
|
-
value = options[HammerCLI.option_accessor_name("id")]
|
35
|
-
value ||= HammerCLI::NilValue if searchables(resource).any? do |s|
|
36
|
-
options[HammerCLI.option_accessor_name(s.name)] == HammerCLI::NilValue
|
37
|
-
end
|
38
|
-
value ||= 1 if searchables(resource).any? do |s|
|
39
|
-
!options[HammerCLI.option_accessor_name(s.name)].nil?
|
40
|
-
end
|
41
|
-
value
|
42
|
-
end
|
43
|
-
|
44
|
-
method_name = "#{resource.singular_name}_ids"
|
45
|
-
self.class.send(:define_method, method_name) do |options|
|
46
|
-
options["option_#{resource.singular_name}_ids"].nil? ? nil : [1]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
module CommandTestHelper
|
55
|
-
|
56
|
-
def self.included(base)
|
57
|
-
base.extend(ClassMethods)
|
58
|
-
|
59
|
-
base.before :each do
|
60
|
-
resolver = cmd.resolver
|
61
|
-
cmd.stubs(:resolver).returns(IdResolverTestProxy.new(resolver))
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def count_records(data)
|
66
|
-
HammerCLIForeman.collection_to_common_format(data['results']).count
|
67
|
-
end
|
68
|
-
|
69
|
-
module ClassMethods
|
70
|
-
|
71
|
-
def with_params(params, &block)
|
72
|
-
context "with params "+params.to_s do
|
73
|
-
let(:with_params) { params }
|
74
|
-
self.instance_eval &block
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def it_should_call_action(action, params, headers={})
|
79
|
-
it "should call action "+action.to_s do
|
80
|
-
arguments ||= respond_to?(:with_params) ? with_params : []
|
81
|
-
ApipieBindings::API.any_instance.expects(:call).with() do |r,a,p,h,o|
|
82
|
-
(r == cmd.resource.name && a == action && p == params && h == headers)
|
83
|
-
end
|
84
|
-
cmd.run(arguments)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def it_should_call_action_and_test_params(action, &block)
|
89
|
-
it "should call action "+action.to_s do
|
90
|
-
arguments ||= respond_to?(:with_params) ? with_params : []
|
91
|
-
ApipieBindings::API.any_instance.expects(:call).with() do |r,a,p,h,o|
|
92
|
-
(r == cmd.resource.name && a == action && yield(p))
|
93
|
-
end
|
94
|
-
cmd.run(arguments)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def it_should_fail_with(message, arguments=[])
|
99
|
-
it "should fail with " + message.to_s do
|
100
|
-
_(cmd.run(arguments)).must_equal HammerCLI::EX_USAGE
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def it_should_accept(message, arguments=[])
|
105
|
-
it "should accept " + message.to_s do
|
106
|
-
out, err = capture_io do
|
107
|
-
_(cmd.run(arguments)).must_equal HammerCLI::EX_OK
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def it_should_output(message, adapter=:base)
|
113
|
-
it "should output '" + message.to_s + "'" do
|
114
|
-
arguments ||= respond_to?(:with_params) ? with_params : []
|
115
|
-
cmd.stubs(:context).returns(ctx.update(:adapter => adapter))
|
116
|
-
out, err = capture_io do
|
117
|
-
cmd.run(arguments)
|
118
|
-
end
|
119
|
-
_(out).must_include message
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def it_should_print_column(column_name, arguments=nil)
|
124
|
-
it "should print column " + column_name do
|
125
|
-
arguments ||= respond_to?(:with_params) ? with_params : []
|
126
|
-
|
127
|
-
cmd.stubs(:context).returns(ctx.update(:adapter => :test))
|
128
|
-
out, err = capture_io do
|
129
|
-
cmd.run(arguments)
|
130
|
-
end
|
131
|
-
|
132
|
-
_(out.split("\n")[0]).must_match /.*##{column_name}#.*/
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def it_should_print_columns(column_names, arguments=nil)
|
137
|
-
column_names.each do |name|
|
138
|
-
it_should_print_column name, arguments
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def it_should_print_n_records(count=nil, arguments=nil)
|
143
|
-
it "should print correct count of records" do
|
144
|
-
arguments ||= respond_to?(:with_params) ? with_params : []
|
145
|
-
|
146
|
-
cmd.stubs(:context).returns(ctx.update(:adapter => :test))
|
147
|
-
count ||= expected_record_count rescue 0
|
148
|
-
out, err = capture_io do
|
149
|
-
cmd.run(arguments)
|
150
|
-
end
|
151
|
-
_(out.split(/\n/).length).must_equal count+1 # plus 1 for line with column headers
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def it_should_accept_search_params
|
156
|
-
it_should_accept "search", ["--search=some_search"]
|
157
|
-
it_should_accept "per page", ["--per-page=1"]
|
158
|
-
it_should_accept "page", ["--page=2"]
|
159
|
-
it_should_accept "order", ["--order=order"]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|