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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_foreman_puppet/associating_commands.rb +1 -1
  3. data/lib/hammer_cli_foreman_puppet/class.rb +1 -3
  4. data/lib/hammer_cli_foreman_puppet/combination.rb +0 -1
  5. data/lib/hammer_cli_foreman_puppet/command_extensions/combination.rb +3 -3
  6. data/lib/hammer_cli_foreman_puppet/commands.rb +3 -2
  7. data/lib/hammer_cli_foreman_puppet/host.rb +4 -5
  8. data/lib/hammer_cli_foreman_puppet/hostgroup.rb +7 -8
  9. data/lib/hammer_cli_foreman_puppet/i18n.rb +2 -2
  10. data/lib/hammer_cli_foreman_puppet/id_resolver.rb +5 -5
  11. data/lib/hammer_cli_foreman_puppet/option_sources/puppet_environment_params.rb +1 -2
  12. data/lib/hammer_cli_foreman_puppet/puppet_references.rb +0 -1
  13. data/lib/hammer_cli_foreman_puppet/smart_class_parameter.rb +6 -6
  14. data/lib/hammer_cli_foreman_puppet/smart_proxy.rb +2 -2
  15. data/lib/hammer_cli_foreman_puppet/version.rb +1 -1
  16. data/locale/cs_CZ/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  17. data/locale/cs_CZ/hammer-cli-foreman-puppet.po +282 -0
  18. data/locale/de/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  19. data/locale/de/hammer-cli-foreman-puppet.po +293 -0
  20. data/locale/en/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  21. data/locale/en/hammer-cli-foreman-puppet.po +276 -0
  22. data/locale/es/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  23. data/locale/es/hammer-cli-foreman-puppet.po +287 -0
  24. data/locale/fr/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  25. data/locale/fr/hammer-cli-foreman-puppet.po +285 -0
  26. data/locale/hammer-cli-foreman-puppet.pot +386 -0
  27. data/locale/ja/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  28. data/locale/ja/hammer-cli-foreman-puppet.po +283 -0
  29. data/locale/ka/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  30. data/locale/ka/hammer-cli-foreman-puppet.po +280 -0
  31. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  32. data/locale/pt_BR/hammer-cli-foreman-puppet.po +288 -0
  33. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman-puppet.mo +0 -0
  34. data/locale/zh_CN/hammer-cli-foreman-puppet.po +283 -0
  35. metadata +31 -57
  36. data/test/data/2.1/foreman_api.json +0 -1
  37. data/test/data/3.0/foreman_api.json +0 -1
  38. data/test/data/3.3/foreman_api.json +0 -1
  39. data/test/data/README.md +0 -27
  40. data/test/functional/config_group_test.rb +0 -28
  41. data/test/functional/host/create_test.rb +0 -195
  42. data/test/functional/host/update_test.rb +0 -126
  43. data/test/functional/hostgroup/create_test.rb +0 -178
  44. data/test/functional/hostgroup/update_test.rb +0 -126
  45. data/test/functional/proxy_test.rb +0 -86
  46. data/test/functional/smart_class_parameter_test.rb +0 -97
  47. data/test/functional/template_test.rb +0 -38
  48. data/test/functional/test_helper.rb +0 -7
  49. data/test/test_helper.rb +0 -29
  50. data/test/unit/apipie_resource_mock.rb +0 -186
  51. data/test/unit/config_group_test.rb +0 -73
  52. data/test/unit/helpers/command.rb +0 -163
  53. data/test/unit/helpers/fake_searchables.rb +0 -19
  54. data/test/unit/helpers/resource_disabled.rb +0 -24
  55. data/test/unit/puppet_class_test.rb +0 -72
  56. data/test/unit/puppet_environment_test.rb +0 -116
  57. data/test/unit/smart_class_parameter_test.rb +0 -114
  58. data/test/unit/test_helper.rb +0 -18
  59. data/test/unit/test_output_adapter.rb +0 -22
data/test/data/README.md DELETED
@@ -1,27 +0,0 @@
1
- # Data for tests
2
-
3
- ## How to include API tests for new Foreman release
4
-
5
- 1. on the **foreman instance** run the tests with recording of examples turned on
6
-
7
- ```bash
8
- $ APIPIE_RECORD=examples bundle exec rake test:functionals
9
- ```
10
- 1. on the **Foreman instance** generate API documentation cache. It will land in `/usr/share/foreman/public/apipie-cache/apidoc/v2.en.json`
11
-
12
- ```bash
13
- $ FOREMAN_APIPIE_LANGS=en foreman-rake apipie:cache
14
- ```
15
- 1. when running from **git**, run a similar command and it will land in `$FOREMAN_CHECKOUT/public/apipie-cache/apidoc/v2.en.json`
16
-
17
- ```bash
18
- $ FOREMAN_APIPIE_LANGS=en bundle exec rake apipie:cache
19
- ```
20
- 1. in **hammer-cli-foreman** in `test/data/` Create directory with name matching the Foreman version in `test/data/` (e.g. `test/data/1.10`)
21
- 1. copy the API cache from the Foreman instance into the newly created directory and name it as `foreman_api.json`
22
- 1. update the following line in `test/test_helper.rb` to match the new default Foreman version
23
-
24
- ```ruby
25
- FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.0')
26
- ```
27
- 1. make sure the tests are green
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.join(File.dirname(__FILE__), 'test_helper')
4
-
5
- describe 'config_group' do
6
- describe 'list' do
7
- before do
8
- @cmd = %w[config-group list]
9
- @config_groups = [{
10
- id: 1,
11
- name: 'config-group-test',
12
- }]
13
- end
14
-
15
- it 'should return a list of config groups' do
16
- api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
17
-
18
- output = IndexMatcher.new([
19
- %w[ID NAME],
20
- %w[1 config-group-test]
21
- ])
22
- expected_result = success_result(output)
23
-
24
- result = run_cmd(@cmd)
25
- assert_cmd(expected_result, result)
26
- end
27
- end
28
- end
@@ -1,195 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module HammerCLIForemanPuppet
4
- describe Host do
5
- describe CreateCommand do
6
- let(:cmd) { %w[host create] }
7
- let(:minimal_params_without_hostgroup) { %w[--location-id=1 --organization-id=1 --name=hst1] }
8
-
9
- it 'allows puppet environment id' do
10
- params = %w[--puppet-environment-id=1]
11
- api_expects(:hosts, :create) do |p|
12
- p['host']['environment_id'] == 1 &&
13
- p['host']['name'] == 'hst1'
14
- end
15
- run_cmd(cmd + minimal_params_without_hostgroup + params)
16
- end
17
-
18
- it 'allows puppet environment name' do
19
- params = %w[--puppet-environment=env1]
20
- api_expects(:environments, :index) do |p|
21
- p[:search] == 'name = "env1"'
22
- end.returns(index_response([{ 'id' => 1 }]))
23
- # FIXME: Called twice because of environment_id being mentioned twice in the docs
24
- api_expects(:environments, :index) do |p|
25
- p[:search] == 'name = "env1"'
26
- end.returns(index_response([{ 'id' => 1 }]))
27
- api_expects(:hosts, :create) do |p|
28
- p['host']['puppet_attributes']['environment_id'] == 1 &&
29
- p['host']['name'] == 'hst1'
30
- end
31
- run_cmd(cmd + minimal_params_without_hostgroup + params)
32
- end
33
-
34
- it 'allows puppet ca proxy id' do
35
- params = %w[--puppet-ca-proxy-id=1]
36
- api_expects(:hosts, :create).with_params(
37
- {
38
- host: {
39
- name: 'hst1',
40
- puppet_ca_proxy_id: 1
41
- }
42
- }
43
- )
44
- run_cmd(cmd + minimal_params_without_hostgroup + params)
45
- end
46
-
47
- it 'allows puppet ca proxy name' do
48
- params = %w[--puppet-ca-proxy=sp1]
49
- api_expects(:smart_proxies, :index) do |p|
50
- p[:search] = 'name = "sp1"'
51
- end.returns(index_response([{ 'id' => 1 }]))
52
- api_expects(:hosts, :create) do |p|
53
- p['host']['puppet_ca_proxy_id'] == 1 &&
54
- p['host']['name'] == 'hst1'
55
- end
56
- run_cmd(cmd + minimal_params_without_hostgroup + params)
57
- end
58
-
59
- it 'allows puppet class ids' do
60
- params = %w[--puppet-class-ids=1,2]
61
- api_expects(:hosts, :create) do |p|
62
- p['host']['puppet_attributes']['puppetclass_ids'] == %w[1 2] &&
63
- p['host']['name'] == 'hst1'
64
- end
65
- run_cmd(cmd + minimal_params_without_hostgroup + params)
66
- end
67
-
68
- it 'allows puppet class names' do
69
- params = %w[--puppet-classes=pc1,pc2]
70
- api_expects(:puppetclasses, :index) do |p|
71
- p[:search] = 'name = "pc1" or name = "pc2"'
72
- end.returns(index_response('puppetclasses' => [
73
- {'id' => 1, 'name' => 'pc1'},
74
- {'id' => 2, 'name' => 'pc2'}
75
- ]))
76
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
77
- api_expects(:puppetclasses, :index) do |p|
78
- p[:search] = 'name = "pc1" or name = "pc2"'
79
- end.returns(index_response('puppetclasses' => [
80
- {'id' => 1, 'name' => 'pc1'},
81
- {'id' => 2, 'name' => 'pc2'}
82
- ]))
83
- api_expects(:hosts, :create) do |p|
84
- p['host']['puppet_attributes']['puppetclass_ids'] == [1,2] &&
85
- p['host']['name'] == 'hst1'
86
- end
87
- run_cmd(cmd + minimal_params_without_hostgroup + params)
88
- end
89
-
90
- it 'allows puppet class names that exceeds entries_per_page' do
91
- search_objects = []
92
- response_objects = []
93
- ids = []
94
- names = []
95
- 1100.times.with_object('pc').each do |id, name|
96
- next_name = "\"#{name}#{id}\""
97
- search_objects << "name = #{next_name}"
98
- response_objects << { 'id' => id, 'name' => next_name }
99
- ids << id
100
- names << next_name
101
- end
102
- params = ["--puppet-classes=#{names.join(',').tr('"', '')}"]
103
-
104
- api_expects(:puppetclasses, :index) do |p|
105
- p[:search] == search_objects.join(' or ') &&
106
- p[:page].to_i == 1 &&
107
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
108
- end.returns(
109
- index_response('puppetclasses' => response_objects[0...1000]))
110
-
111
- api_expects(:puppetclasses, :index) do |p|
112
- p[:search] == search_objects.join(' or ') &&
113
- p[:page].to_i == 2 &&
114
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
115
- end.returns(index_response('puppetclasses' => response_objects[1000...1100]))
116
-
117
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
118
- api_expects(:puppetclasses, :index) do |p|
119
- p[:search] == search_objects.join(' or ') &&
120
- p[:page].to_i == 1 &&
121
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
122
- end.returns(
123
- index_response('puppetclasses' => response_objects[0...1000]))
124
-
125
- api_expects(:puppetclasses, :index) do |p|
126
- p[:search] == search_objects.join(' or ') &&
127
- p[:page].to_i == 2 &&
128
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
129
- end.returns(index_response('puppetclasses' => response_objects[1000...1100]))
130
-
131
- api_expects(:hosts, :create) do |p|
132
- p['host']['name'] == 'hst1' &&
133
- p['host']['puppet_attributes']['puppetclass_ids'] == ids
134
- end
135
- run_cmd(cmd + minimal_params_without_hostgroup + params)
136
- end
137
-
138
- it 'allows puppet proxy id' do
139
- params = %w[--puppet-proxy-id=1]
140
- api_expects(:hosts, :create).with_params(
141
- {
142
- host: {
143
- name: 'hst1',
144
- puppet_proxy_id: 1
145
- }
146
- }
147
- )
148
- run_cmd(cmd + minimal_params_without_hostgroup + params)
149
- end
150
-
151
- it 'allows puppet proxy name' do
152
- params = %w[--puppet-proxy=sp1]
153
- api_expects(:smart_proxies, :index) do |p|
154
- p[:search] = 'name = "sp1"'
155
- end.returns(index_response([{ 'id' => 1 }]))
156
- api_expects(:hosts, :create) do |p|
157
- p['host']['puppet_proxy_id'] == 1 &&
158
- p['host']['name'] == 'hst1'
159
- end
160
- run_cmd(cmd + minimal_params_without_hostgroup + params)
161
- end
162
-
163
- it 'allows config group ids' do
164
- params = %w[--config-group-ids=1,2]
165
- api_expects(:hosts, :create) do |p|
166
- p['host']['puppet_attributes']['config_group_ids'] == %w[1 2] &&
167
- p['host']['name'] == 'hst1'
168
- end
169
- run_cmd(cmd + minimal_params_without_hostgroup + params)
170
- end
171
-
172
- it 'allows config group names' do
173
- params = %w[--config-groups=cg1,cg2]
174
- api_expects(:config_groups, :index) do |p|
175
- p[:search] = 'name = "cg1" or name = "cg2"'
176
- end.returns(index_response([
177
- {'id' => 1, 'name' => 'cg1'},
178
- {'id' => 2, 'name' => 'cg2'}
179
- ]))
180
- # FIXME: Called twice because of config_group_ids being mentioned twice in the docs
181
- api_expects(:config_groups, :index) do |p|
182
- p[:search] = 'name = "cg1" or name = "cg2"'
183
- end.returns(index_response([
184
- {'id' => 1, 'name' => 'cg1'},
185
- {'id' => 2, 'name' => 'cg2'}
186
- ]))
187
- api_expects(:hosts, :create) do |p|
188
- p['host']['puppet_attributes']['config_group_ids'] == [1, 2] &&
189
- p['host']['name'] == 'hst1'
190
- end
191
- run_cmd(cmd + minimal_params_without_hostgroup + params)
192
- end
193
- end
194
- end
195
- end
@@ -1,126 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module HammerCLIForemanPuppet
4
- describe Host do
5
- describe UpdateCommand do
6
- it 'allows environment id' do
7
- api_expects(:hosts, :update) do |p|
8
- p['host']['puppet_attributes']['environment_id'] == 1 &&
9
- p['id'] == '1'
10
- end
11
- run_cmd(%w(host update --id 1 --puppet-environment-id 1))
12
- end
13
-
14
- it 'allows environment name' do
15
- api_expects(:environments, :index) do |p|
16
- p[:search] = "name = \"env1\""
17
- end.returns(index_response([{'id' => 1}]))
18
- # FIXME: Called twice because of environment_id being mentioned twice in the docs
19
- api_expects(:environments, :index) do |p|
20
- p[:search] = "name = \"env1\""
21
- end.returns(index_response([{'id' => 1}]))
22
- api_expects(:hosts, :update) do |p|
23
- p['host']['puppet_attributes']['environment_id'] == 1 &&
24
- p['id'] == '1'
25
- end
26
- run_cmd(%w(host update --id 1 --puppet-environment env1))
27
- end
28
-
29
- it 'allows puppet ca proxy id' do
30
- api_expects(:hosts, :update).with_params({
31
- :id => '1',
32
- :host => { :puppet_ca_proxy_id => 1 }
33
- })
34
- run_cmd(%w(host update --id 1 --puppet-ca-proxy-id 1))
35
- end
36
-
37
- it 'allows puppet ca proxy name' do
38
- api_expects(:smart_proxies, :index) do |p|
39
- p[:search] = "name = \"sp1\""
40
- end.returns(index_response([{'id' => 1}]))
41
- api_expects(:hosts, :update) do |p|
42
- p['host']['puppet_ca_proxy_id'] == 1 &&
43
- p['id'] == '1'
44
- end
45
- run_cmd(%w(host update --id 1 --puppet-ca-proxy sp1))
46
- end
47
-
48
- it 'allows puppet class ids' do
49
- api_expects(:hosts, :update) do |p|
50
- p['host']['puppet_attributes']['puppetclass_ids'] == ['1','2'] &&
51
- p['id'] == '1'
52
- end
53
- run_cmd(%w(host update --id 1 --puppet-class-ids 1,2))
54
- end
55
-
56
- it 'allows puppet class names' do
57
- api_expects(:puppetclasses, :index) do |p|
58
- p[:search] = "name = \"pc1\" or name = \"pc2\""
59
- end.returns(index_response('puppetclasses' => [
60
- {'id' => 1, 'name' => 'pc1'},
61
- {'id' => 2, 'name' => 'pc2'}
62
- ]))
63
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
64
- api_expects(:puppetclasses, :index) do |p|
65
- p[:search] = "name = \"pc1\" or name = \"pc2\""
66
- end.returns(index_response('puppetclasses' => [
67
- {'id' => 1, 'name' => 'pc1'},
68
- {'id' => 2, 'name' => 'pc2'}
69
- ]))
70
- api_expects(:hosts, :update) do |p|
71
- p['host']['puppet_attributes']['puppetclass_ids'] == [1,2] &&
72
- p['id'] == '1'
73
- end
74
- run_cmd(%w(host update --id 1 --puppet-classes pc1,pc2))
75
- end
76
-
77
- it 'allows puppet proxy id' do
78
- api_expects(:hosts, :update).with_params({
79
- :id => '1',
80
- :host => { :puppet_proxy_id => 1 }
81
- })
82
- run_cmd(%w(host update --id 1 --puppet-proxy-id 1))
83
- end
84
-
85
- it 'allows puppet proxy name' do
86
- api_expects(:smart_proxies, :index) do |p|
87
- p[:search] = "name = \"sp1\""
88
- end.returns(index_response([{'id' => 1}]))
89
- api_expects(:hosts, :update) do |p|
90
- p['host']['puppet_proxy_id'] == 1 &&
91
- p['id'] == '1'
92
- end
93
- run_cmd(%w(host update --id 1 --puppet-proxy sp1))
94
- end
95
-
96
- it 'allows config group ids' do
97
- api_expects(:hosts, :update) do |p|
98
- p['host']['puppet_attributes']['config_group_ids'] == %w[1 2] &&
99
- p['id'] == '1'
100
- end
101
- run_cmd(%w[host update --id 1 --config-group-ids=1,2])
102
- end
103
-
104
- it 'allows config group names' do
105
- api_expects(:config_groups, :index) do |p|
106
- p[:search] = 'name = "cg1" or name = "cg2"'
107
- end.returns(index_response([
108
- {'id' => 1, 'name' => 'cg1'},
109
- {'id' => 2, 'name' => 'cg2'}
110
- ]))
111
- # FIXME: Called twice because of config_group_ids being mentioned twice in the docs
112
- api_expects(:config_groups, :index) do |p|
113
- p[:search] = 'name = "cg1" or name = "cg2"'
114
- end.returns(index_response([
115
- {'id' => 1, 'name' => 'cg1'},
116
- {'id' => 2, 'name' => 'cg2'}
117
- ]))
118
- api_expects(:hosts, :update) do |p|
119
- p['host']['puppet_attributes']['config_group_ids'] == [1, 2] &&
120
- p['id'] == '1'
121
- end
122
- run_cmd(%w[host update --id 1 --config-groups=cg1,cg2])
123
- end
124
- end
125
- end
126
- end
@@ -1,178 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module HammerCLIForemanPuppet
4
- describe Hostgroup do
5
- describe CreateCommand do
6
- it 'allows puppet environment id' do
7
- api_expects(:hostgroups, :create) do |p|
8
- p['hostgroup']['puppet_attributes']['environment_id'] == 1 &&
9
- p['hostgroup']['name'] == 'hg1'
10
- end
11
- run_cmd(%w[hostgroup create --name hg1 --puppet-environment-id 1])
12
- end
13
-
14
- it 'allows puppet environment name' do
15
- api_expects(:environments, :index) do |p|
16
- p[:search] == 'name = "env1"'
17
- end.returns(index_response([{ 'id' => 1 }]))
18
- # FIXME: Called twice because of environment_id being mentioned twice in the docs
19
- api_expects(:environments, :index) do |p|
20
- p[:search] == 'name = "env1"'
21
- end.returns(index_response([{ 'id' => 1 }]))
22
- api_expects(:hostgroups, :create) do |p|
23
- p['hostgroup']['puppet_attributes']['environment_id'] == 1 &&
24
- p['hostgroup']['name'] == 'hg1'
25
- end
26
- run_cmd(%w[hostgroup create --name hg1 --puppet-environment env1])
27
- end
28
-
29
- it 'allows puppet ca proxy id' do
30
- api_expects(:hostgroups, :create).with_params({
31
- :hostgroup => {
32
- :name => 'hg1',
33
- :puppet_ca_proxy_id => 1
34
- }
35
- })
36
- run_cmd(%w(hostgroup create --name hg1 --puppet-ca-proxy-id 1))
37
- end
38
-
39
- it 'allows puppet ca proxy name' do
40
- api_expects(:smart_proxies, :index) do |p|
41
- p[:search] = "name = \"sp1\""
42
- end.returns(index_response([{'id' => 1}]))
43
- api_expects(:hostgroups, :create) do |p|
44
- p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
45
- p['hostgroup']['name'] == 'hg1'
46
- end
47
- run_cmd(%w(hostgroup create --name hg1 --puppet-ca-proxy sp1))
48
- end
49
-
50
- it 'allows puppet class ids' do
51
- api_expects(:hostgroups, :create) do |p|
52
- p['hostgroup']['puppet_attributes']['puppetclass_ids'] == ['1','2'] &&
53
- p['hostgroup']['name'] == 'hg1'
54
- end
55
- run_cmd(%w(hostgroup create --name hg1 --puppet-class-ids 1,2))
56
- end
57
-
58
- it 'allows puppet class names' do
59
- api_expects(:puppetclasses, :index) do |p|
60
- p[:search] = "name = \"pc1\" or name = \"pc2\""
61
- end.returns(index_response('puppetclasses' => [
62
- {'id' => 1, 'name' => 'pc1'},
63
- {'id' => 2, 'name' => 'pc2'}
64
- ]))
65
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
66
- api_expects(:puppetclasses, :index) do |p|
67
- p[:search] = "name = \"pc1\" or name = \"pc2\""
68
- end.returns(index_response('puppetclasses' => [
69
- {'id' => 1, 'name' => 'pc1'},
70
- {'id' => 2, 'name' => 'pc2'}
71
- ]))
72
- api_expects(:hostgroups, :create) do |p|
73
- p['hostgroup']['puppet_attributes']['puppetclass_ids'] == [1,2] &&
74
- p['hostgroup']['name'] == 'hg1'
75
- end
76
- run_cmd(%w(hostgroup create --name hg1 --puppet-classes pc1,pc2))
77
- end
78
-
79
- it 'allows puppet class names that exceeds entries_per_page' do
80
- search_objects = []
81
- response_objects = []
82
- ids = []
83
- names = []
84
- 1100.times.with_object('pc').each do |id, name|
85
- next_name = "\"#{name}#{id}\""
86
- search_objects << "name = #{next_name}"
87
- response_objects << { 'id' => id, 'name' => next_name }
88
- ids << id
89
- names << next_name
90
- end
91
-
92
- api_expects(:puppetclasses, :index) do |p|
93
- p[:search] == search_objects.join(' or ') &&
94
- p[:page].to_i == 1 &&
95
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
96
- end.returns(
97
- index_response('puppetclasses' => response_objects[0...1000]))
98
-
99
- api_expects(:puppetclasses, :index) do |p|
100
- p[:search] == search_objects.join(' or ') &&
101
- p[:page].to_i == 2 &&
102
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
103
- end.returns(index_response('puppetclasses' => response_objects[1000...1100]))
104
-
105
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
106
- api_expects(:puppetclasses, :index) do |p|
107
- p[:search] == search_objects.join(' or ') &&
108
- p[:page].to_i == 1 &&
109
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
110
- end.returns(
111
- index_response('puppetclasses' => response_objects[0...1000]))
112
-
113
- api_expects(:puppetclasses, :index) do |p|
114
- p[:search] == search_objects.join(' or ') &&
115
- p[:page].to_i == 2 &&
116
- p[:per_page].to_i == HammerCLIForeman::IdResolver::ALL_PER_PAGE
117
- end.returns(index_response('puppetclasses' => response_objects[1000...1100]))
118
-
119
- api_expects(:hostgroups, :create) do |p|
120
- p['hostgroup']['name'] == 'hg1' &&
121
- p['hostgroup']['puppet_attributes']['puppetclass_ids'] == ids
122
- end
123
-
124
- run_cmd(%w[hostgroup create --name hg1 --puppet-classes] << names.join(',').tr('"', ''))
125
- end
126
-
127
- it 'allows puppet proxy id' do
128
- api_expects(:hostgroups, :create).with_params({
129
- :hostgroup => {
130
- :name => 'hg1',
131
- :puppet_proxy_id => 1
132
- }
133
- })
134
- run_cmd(%w(hostgroup create --name hg1 --puppet-proxy-id 1))
135
- end
136
-
137
- it 'allows puppet proxy name' do
138
- api_expects(:smart_proxies, :index) do |p|
139
- p[:search] = "name = \"sp1\""
140
- end.returns(index_response([{'id' => 1}]))
141
- api_expects(:hostgroups, :create) do |p|
142
- p['hostgroup']['puppet_proxy_id'] == 1 &&
143
- p['hostgroup']['name'] == 'hg1'
144
- end
145
- run_cmd(%w(hostgroup create --name hg1 --puppet-proxy sp1))
146
- end
147
-
148
- it 'allows config group ids' do
149
- api_expects(:hostgroups, :create) do |p|
150
- p['hostgroup']['puppet_attributes']['config_group_ids'] == %w[1 2] &&
151
- p['hostgroup']['name'] == 'hg1'
152
- end
153
- run_cmd(%w[hostgroup create --name hg1 --config-group-ids 1,2])
154
- end
155
-
156
- it 'allows config group names' do
157
- api_expects(:config_groups, :index) do |p|
158
- p[:search] = 'name = "cg1" or name = "cg2"'
159
- end.returns(index_response([
160
- {'id' => 1, 'name' => 'cg1'},
161
- {'id' => 2, 'name' => 'cg2'}
162
- ]))
163
- # FIXME: Called twice because of config_group_ids being mentioned twice in the docs
164
- api_expects(:config_groups, :index) do |p|
165
- p[:search] = 'name = "cg1" or name = "cg2"'
166
- end.returns(index_response([
167
- {'id' => 1, 'name' => 'cg1'},
168
- {'id' => 2, 'name' => 'cg2'}
169
- ]))
170
- api_expects(:hostgroups, :create) do |p|
171
- p['hostgroup']['puppet_attributes']['config_group_ids'] == [1, 2] &&
172
- p['hostgroup']['name'] == 'hg1'
173
- end
174
- run_cmd(%w[hostgroup create --name hg1 --config-groups cg1,cg2])
175
- end
176
- end
177
- end
178
- end
@@ -1,126 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module HammerCLIForemanPuppet
4
- describe Hostgroup do
5
- describe UpdateCommand do
6
- it 'allows environment id' do
7
- api_expects(:hostgroups, :update) do |p|
8
- p['hostgroup']['puppet_attributes']['environment_id'] == 1 &&
9
- p['id'] == '1'
10
- end
11
- run_cmd(%w(hostgroup update --id 1 --puppet-environment-id 1))
12
- end
13
-
14
- it 'allows environment name' do
15
- api_expects(:environments, :index) do |p|
16
- p[:search] = "name = \"env1\""
17
- end.returns(index_response([{'id' => 1}]))
18
- # FIXME: Called twice because of environment_id being mentioned twice in the docs
19
- api_expects(:environments, :index) do |p|
20
- p[:search] = "name = \"env1\""
21
- end.returns(index_response([{'id' => 1}]))
22
- api_expects(:hostgroups, :update) do |p|
23
- p['hostgroup']['puppet_attributes']['environment_id'] == 1 &&
24
- p['id'] == '1'
25
- end
26
- run_cmd(%w(hostgroup update --id 1 --puppet-environment env1))
27
- end
28
-
29
- it 'allows puppet ca proxy id' do
30
- api_expects(:hostgroups, :update).with_params({
31
- :id => '1',
32
- :hostgroup => { :puppet_ca_proxy_id => 1 }
33
- })
34
- run_cmd(%w(hostgroup update --id 1 --puppet-ca-proxy-id 1))
35
- end
36
-
37
- it 'allows puppet ca proxy name' do
38
- api_expects(:smart_proxies, :index) do |p|
39
- p[:search] = "name = \"sp1\""
40
- end.returns(index_response([{'id' => 1}]))
41
- api_expects(:hostgroups, :update) do |p|
42
- p['hostgroup']['puppet_ca_proxy_id'] == 1 &&
43
- p['id'] == '1'
44
- end
45
- run_cmd(%w(hostgroup update --id 1 --puppet-ca-proxy sp1))
46
- end
47
-
48
- it 'allows puppet class ids' do
49
- api_expects(:hostgroups, :update) do |p|
50
- p['hostgroup']['puppet_attributes']['puppetclass_ids'] == ['1','2'] &&
51
- p['id'] == '1'
52
- end
53
- run_cmd(%w(hostgroup update --id 1 --puppet-class-ids 1,2))
54
- end
55
-
56
- it 'allows puppet class names' do
57
- api_expects(:puppetclasses, :index) do |p|
58
- p[:search] = "name = \"pc1\" or name = \"pc2\""
59
- end.returns(index_response('puppetclasses' => [
60
- {'id' => 1, 'name' => 'pc1'},
61
- {'id' => 2, 'name' => 'pc2'}
62
- ]))
63
- # FIXME: Called twice because of puppetclass_ids being mentioned twice in the docs
64
- api_expects(:puppetclasses, :index) do |p|
65
- p[:search] = "name = \"pc1\" or name = \"pc2\""
66
- end.returns(index_response('puppetclasses' => [
67
- {'id' => 1, 'name' => 'pc1'},
68
- {'id' => 2, 'name' => 'pc2'}
69
- ]))
70
- api_expects(:hostgroups, :update) do |p|
71
- p['hostgroup']['puppet_attributes']['puppetclass_ids'] == [1,2] &&
72
- p['id'] == '1'
73
- end
74
- run_cmd(%w(hostgroup update --id 1 --puppet-classes pc1,pc2))
75
- end
76
-
77
- it 'allows puppet proxy id' do
78
- api_expects(:hostgroups, :update).with_params({
79
- :id => '1',
80
- :hostgroup => { :puppet_proxy_id => 1 }
81
- })
82
- run_cmd(%w(hostgroup update --id 1 --puppet-proxy-id 1))
83
- end
84
-
85
- it 'allows puppet proxy name' do
86
- api_expects(:smart_proxies, :index) do |p|
87
- p[:search] = "name = \"sp1\""
88
- end.returns(index_response([{'id' => 1}]))
89
- api_expects(:hostgroups, :update) do |p|
90
- p['hostgroup']['puppet_proxy_id'] == 1 &&
91
- p['id'] == '1'
92
- end
93
- run_cmd(%w(hostgroup update --id 1 --puppet-proxy sp1))
94
- end
95
-
96
- it 'allows config group ids' do
97
- api_expects(:hostgroups, :update) do |p|
98
- p['hostgroup']['puppet_attributes']['config_group_ids'] == %w[1 2] &&
99
- p['id'] == '1'
100
- end
101
- run_cmd(%w[hostgroup update --id 1 --config-group-ids 1,2])
102
- end
103
-
104
- it 'allows config group names' do
105
- api_expects(:config_groups, :index) do |p|
106
- p[:search] = 'name = "cg1" or name = "cg2"'
107
- end.returns(index_response([
108
- {'id' => 1, 'name' => 'cg1'},
109
- {'id' => 2, 'name' => 'cg2'}
110
- ]))
111
- # FIXME: Called twice because of config_group_ids being mentioned twice in the docs
112
- api_expects(:config_groups, :index) do |p|
113
- p[:search] = 'name = "cg1" or name = "cg2"'
114
- end.returns(index_response([
115
- {'id' => 1, 'name' => 'cg1'},
116
- {'id' => 2, 'name' => 'cg2'}
117
- ]))
118
- api_expects(:hostgroups, :update) do |p|
119
- p['hostgroup']['puppet_attributes']['config_group_ids'] == [1, 2] &&
120
- p['id'] == '1'
121
- end
122
- run_cmd(%w[hostgroup update --id 1 --config-groups cg1,cg2])
123
- end
124
- end
125
- end
126
- end