hammer_cli_foreman 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +33 -3
  3. data/lib/hammer_cli_foreman.rb +3 -21
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +1 -1
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  8. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  9. data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
  10. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  11. data/lib/hammer_cli_foreman/commands.rb +16 -9
  12. data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
  13. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  14. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  15. data/lib/hammer_cli_foreman/filter.rb +2 -2
  16. data/lib/hammer_cli_foreman/host.rb +1 -47
  17. data/lib/hammer_cli_foreman/hostgroup.rb +2 -53
  18. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -28
  19. data/lib/hammer_cli_foreman/id_resolver.rb +0 -61
  20. data/lib/hammer_cli_foreman/location.rb +0 -6
  21. data/lib/hammer_cli_foreman/operating_system.rb +2 -1
  22. data/lib/hammer_cli_foreman/option_builders.rb +6 -5
  23. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  24. data/lib/hammer_cli_foreman/option_sources/id_params.rb +27 -10
  25. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +25 -6
  26. data/lib/hammer_cli_foreman/organization.rb +0 -6
  27. data/lib/hammer_cli_foreman/ping.rb +6 -1
  28. data/lib/hammer_cli_foreman/references.rb +0 -16
  29. data/lib/hammer_cli_foreman/registration.rb +18 -0
  30. data/lib/hammer_cli_foreman/smart_proxy.rb +0 -52
  31. data/lib/hammer_cli_foreman/version.rb +1 -1
  32. data/lib/minitest/coverage_reporter.rb +1 -1
  33. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/test/data/2.4/foreman_api.json +1 -0
  47. data/test/data/2.5/foreman_api.json +1 -0
  48. data/test/functional/architecture_test.rb +81 -0
  49. data/test/functional/bookmark_test.rb +24 -1
  50. data/test/functional/compute_profile_test.rb +56 -0
  51. data/test/functional/compute_resource_test.rb +37 -0
  52. data/test/functional/filter_test.rb +115 -47
  53. data/test/functional/host_test.rb +94 -13
  54. data/test/functional/hostgroup/create_test.rb +0 -117
  55. data/test/functional/hostgroup/update_test.rb +0 -79
  56. data/test/functional/http_proxy_test.rb +12 -0
  57. data/test/functional/location_test.rb +13 -3
  58. data/test/functional/mail_notification_test.rb +22 -0
  59. data/test/functional/media_test.rb +11 -0
  60. data/test/functional/model_test.rb +52 -0
  61. data/test/functional/operating_system_test.rb +53 -0
  62. data/test/functional/ping_test.rb +33 -0
  63. data/test/functional/realm_test.rb +11 -0
  64. data/test/functional/registration_test.rb +8 -0
  65. data/test/functional/report_template_test.rb +11 -0
  66. data/test/functional/settings_test.rb +21 -0
  67. data/test/functional/status_test.rb +79 -13
  68. data/test/functional/template_test.rb +16 -37
  69. data/test/functional/user_test.rb +11 -0
  70. data/test/functional/usergroup_test.rb +53 -0
  71. data/test/test_helper.rb +1 -1
  72. data/test/unit/apipie_resource_mock.rb +22 -39
  73. data/test/unit/architecture_test.rb +10 -1
  74. data/test/unit/bookmark_test.rb +95 -0
  75. data/test/unit/compute_profile_test.rb +87 -0
  76. data/test/unit/config_report_test.rb +1 -0
  77. data/test/unit/helpers/command.rb +0 -8
  78. data/test/unit/host_test.rb +14 -61
  79. data/test/unit/hostgroup_test.rb +7 -26
  80. data/test/unit/id_resolver_test.rb +0 -28
  81. data/test/unit/mail_notification_test.rb +53 -0
  82. data/test/unit/model_test.rb +47 -37
  83. data/test/unit/operating_system_test.rb +10 -3
  84. data/test/unit/option_sources/id_params_test.rb +9 -0
  85. data/test/unit/option_sources/ids_params_test.rb +9 -0
  86. data/test/unit/settings_test.rb +4 -0
  87. data/test/unit/smart_proxy_test.rb +0 -12
  88. data/test/unit/usergroup_test.rb +10 -0
  89. metadata +76 -73
  90. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  91. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  92. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  93. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  94. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  95. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  96. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  97. data/test/functional/proxy_test.rb +0 -86
  98. data/test/functional/smart_class_parameter_test.rb +0 -97
  99. data/test/unit/config_group_test.rb +0 -72
  100. data/test/unit/puppet_class_test.rb +0 -72
  101. data/test/unit/puppet_environment_test.rb +0 -114
  102. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -95,6 +95,18 @@ describe 'template' do
95
95
 
96
96
  assert_cmd(success_result("Provisioning template updated.\n"), result)
97
97
  end
98
+
99
+ it 'updates nothing without template related parameters' do
100
+ params = %w[--id=1 --organization-id=1 --location-id=1]
101
+
102
+ api_expects(:template_kinds, :index, 'Get list of template kinds').returns(index_response([]))
103
+ api_expects(:provisioning_templates, :update, 'Update template with no params').returns({})
104
+
105
+ expected_result = success_result("Nothing to update.\n")
106
+
107
+ result = run_cmd(@cmd + params)
108
+ assert_cmd(expected_result, result)
109
+ end
98
110
  end
99
111
 
100
112
  describe 'create' do
@@ -128,45 +140,13 @@ describe 'template' do
128
140
  @cmd = %w(template combination)
129
141
  end
130
142
 
131
- it 'should create new combination with warning' do
132
- params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
133
- expected_result = success_result("Template combination created.\n")
134
- expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
135
- api_expects(:template_combinations, :create, 'Create template combination') do |params|
136
- params['provisioning_template_id'] == 10 &&
137
- params['hostgroup_id'] == 1 &&
138
- params['environment_id'] == 1 &&
139
- params['template_combination'] == {'environment_id' => 1, 'hostgroup_id' => 1}
140
- end
141
-
142
- result = run_cmd(@cmd + params)
143
- assert_cmd(expected_result, result)
144
- end
145
-
146
143
  it 'should create new combination' do
147
- params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
144
+ params = ['create','--provisioning-template-id=10', '--hostgroup-id=1']
148
145
  expected_result = success_result("Template combination created.\n")
149
146
  api_expects(:template_combinations, :create, 'Create template combination') do |params|
150
147
  params['provisioning_template_id'] == 10 &&
151
148
  params['hostgroup_id'] == 1 &&
152
- params['environment_id'] == 1 &&
153
- params['template_combination'] == {'environment_id' => 1, 'hostgroup_id' => 1}
154
- end
155
-
156
- result = run_cmd(@cmd + params)
157
- assert_cmd(expected_result, result)
158
- end
159
-
160
- it 'should update combination with warning' do
161
- params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
162
- expected_result = success_result("Template combination updated.\n")
163
- expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
164
- api_expects(:template_combinations, :update, 'Update template combination') do |params|
165
- params['id'] == '3' &&
166
- params['provisioning_template_id'] == 10 &&
167
- params['hostgroup_id'] == 1 &&
168
- params['environment_id'] == 1 &&
169
- params['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => 1 }
149
+ params['template_combination'] == {'hostgroup_id' => 1}
170
150
  end
171
151
 
172
152
  result = run_cmd(@cmd + params)
@@ -174,14 +154,13 @@ describe 'template' do
174
154
  end
175
155
 
176
156
  it 'should update combination' do
177
- params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--puppet-environment-id=1']
157
+ params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1']
178
158
  expected_result = success_result("Template combination updated.\n")
179
159
  api_expects(:template_combinations, :update, 'Update template combination') do |params|
180
160
  params['id'] == '3' &&
181
161
  params['provisioning_template_id'] == 10 &&
182
162
  params['hostgroup_id'] == 1 &&
183
- params['environment_id'] == 1 &&
184
- params['template_combination'] == { 'environment_id' => 1, 'hostgroup_id' => 1 }
163
+ params['template_combination'] == { 'hostgroup_id' => 1 }
185
164
  end
186
165
 
187
166
  result = run_cmd(@cmd + params)
@@ -82,6 +82,17 @@ describe "user" do
82
82
  assert_cmd(expected_result, result)
83
83
  end
84
84
 
85
+ it 'updates nothing without user related parameters' do
86
+ params = %w[--id=1]
87
+
88
+ api_expects(:users, :update, 'Update user with no params').returns({})
89
+
90
+ expected_result = success_result("Nothing to update.\n")
91
+
92
+ result = run_cmd(cmd + params)
93
+ assert_cmd(expected_result, result)
94
+ end
95
+
85
96
  describe "update password" do
86
97
  def replace_foreman_connection(connection)
87
98
  HammerCLI.context[:api_connection].drop('foreman')
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_helper')
4
+
5
+ describe 'user-group' do
6
+ describe 'list' do
7
+ before do
8
+ @cmd = %w[user-group list]
9
+ @user_groups = [{
10
+ id: 1,
11
+ name: 'test-user-group',
12
+ admin: 'yes',
13
+ }]
14
+ end
15
+
16
+ it 'should return a list of user groups' do
17
+ api_expects(:usergroups, :index, 'List user groups').returns(@user_groups)
18
+
19
+ output = IndexMatcher.new([
20
+ %w[ID NAME ADMIN],
21
+ %w[1 test-user-group yes]
22
+ ])
23
+ expected_result = success_result(output)
24
+
25
+ result = run_cmd(@cmd)
26
+ assert_cmd(expected_result, result)
27
+ end
28
+
29
+ it 'should run list command with defaults' do
30
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.5')) }
31
+ defaults = HammerCLI::Defaults.new(
32
+ {
33
+ organization_id: {
34
+ provider: 'foreman'
35
+ },
36
+ location_id: {
37
+ provider: 'foreman'
38
+ }
39
+ }
40
+ )
41
+ defaults.stubs(:write_to_file).returns(true)
42
+ defaults.stubs(:providers).returns(providers)
43
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
44
+ api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
45
+ api_expects(:usergroups, :index, 'List user groups').returns(@user_groups)
46
+
47
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
48
+ _(result.exit_code).must_equal HammerCLI::EX_OK
49
+ end
50
+ end
51
+ end
52
+
53
+
data/test/test_helper.rb CHANGED
@@ -17,7 +17,7 @@ require "mocha/minitest"
17
17
  require 'hammer_cli'
18
18
  require 'hammer_cli_foreman/testing/api_expectations'
19
19
 
20
- FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '2.1'
20
+ FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '2.5'
21
21
  unless Dir.entries('test/data').include? FOREMAN_VERSION
22
22
  raise StandardError.new "Version is not correct"
23
23
  end
@@ -19,15 +19,6 @@ module ResourceMocks
19
19
  end
20
20
  end
21
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
22
  def self.smart_variables_index
32
23
  ResourceMocks.mock_action_call(:smart_variables, :index,
33
24
  { "results" => [ { 'variable' => 'var', 'id' => '1'} ] })
@@ -107,8 +98,6 @@ module ResourceMocks
107
98
  ResourceMocks.mock_action_call(:hosts, :show, {
108
99
  "ip" => "192.168.122.51",
109
100
  "ip6" => nil,
110
- "environment_id" => 1,
111
- "environment_name" => "production",
112
101
  "last_report" => "2016-10-24 12:06:31 UTC",
113
102
  "mac" => "52:54:00:ce:b2:b9",
114
103
  "realm_id" => nil,
@@ -150,26 +139,11 @@ module ResourceMocks
150
139
  "organization_name" => nil,
151
140
  "location_id" => nil,
152
141
  "location_name" => nil,
153
- "puppet_status" => 0,
154
142
  "model_name" => "KVM",
155
143
  "configuration_status" => 0,
156
144
  "configuration_status_label" => "No reports",
157
145
  "name" => "foreman.example.com",
158
146
  "id" => 1,
159
- "puppet_proxy_id" => 1,
160
- "puppet_proxy_name" => "foreman.example.com",
161
- "puppet_ca_proxy_id" => 1,
162
- "puppet_ca_proxy_name" => "foreman.example.com",
163
- "puppet_proxy" => {
164
- "name" => "foreman.example.com",
165
- "id" => 1,
166
- "url" => "https://foreman.example.com:9090"
167
- },
168
- "puppet_ca_proxy" => {
169
- "name" => "foreman.example.com",
170
- "id" => 1,
171
- "url" => "https://foreman.example.com:9090"
172
- },
173
147
  "hostgroup_name" => nil,
174
148
  "hostgroup_title" => nil,
175
149
  "parameters" => [],
@@ -193,10 +167,7 @@ module ResourceMocks
193
167
  "primary" => false,
194
168
  "provision" => false,
195
169
  "type" => "interface"
196
- }],
197
- "puppetclasses" => [],
198
- "config_groups" => [],
199
- "all_puppetclasses" => []
170
+ }]
200
171
  })
201
172
  end
202
173
 
@@ -237,6 +208,27 @@ module ResourceMocks
237
208
  )
238
209
  end
239
210
 
211
+ def self.bookmarks
212
+ ResourceMocks.mock_action_calls(
213
+ [:bookmarks, :index, []],
214
+ [:bookmarks, :show, {}]
215
+ )
216
+ end
217
+
218
+ def self.mail_notifications
219
+ ResourceMocks.mock_action_calls(
220
+ [:mail_notifications, :index, []],
221
+ [:mail_notifications, :show, {}]
222
+ )
223
+ end
224
+
225
+ def self.compute_profiles
226
+ ResourceMocks.mock_action_calls(
227
+ [:compute_profiles, :index, []],
228
+ [:compute_profiles, :show, {}]
229
+ )
230
+ end
231
+
240
232
  def self.parameters_index
241
233
  ResourceMocks.mock_action_call(:parameters, :index, [])
242
234
  end
@@ -314,13 +306,4 @@ module ResourceMocks
314
306
  "value" => "random value",
315
307
  }])
316
308
  end
317
-
318
- def self.config_groups_index
319
- ResourceMocks.mock_action_call(:config_groups, :index, [{
320
- id: 15,
321
- name: "test config group",
322
- puppetclasses: [ { name: "My puppetclass" } ]
323
- }])
324
- end
325
-
326
309
  end
@@ -17,6 +17,8 @@ describe HammerCLIForeman::Architecture do
17
17
  context "parameters" do
18
18
  it_should_accept "no arguments"
19
19
  it_should_accept_search_params
20
+ it_should_accept 'organization', ['--organization-id=1']
21
+ it_should_accept 'location', ['--location-id=1']
20
22
  end
21
23
 
22
24
  context "output" do
@@ -37,6 +39,8 @@ describe HammerCLIForeman::Architecture do
37
39
  context "parameters" do
38
40
  it_should_accept "id", ["--id=1"]
39
41
  it_should_accept "name", ["--name=arch"]
42
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
43
+ it_should_accept 'location', %w[--id=1 --location-id=1]
40
44
  # it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
41
45
  end
42
46
 
@@ -57,6 +61,8 @@ describe HammerCLIForeman::Architecture do
57
61
 
58
62
  context "parameters" do
59
63
  it_should_accept "name", ["--name=arch"]
64
+ it_should_accept 'organization', %w[--name=arch --organization-id=1]
65
+ it_should_accept 'location', %w[--name=arch --location-id=1]
60
66
  # it_should_fail_with "name missing", []
61
67
  # TODO: temporarily disabled, parameters are checked in the api
62
68
  end
@@ -71,6 +77,8 @@ describe HammerCLIForeman::Architecture do
71
77
  context "parameters" do
72
78
  it_should_accept "name", ["--name=arch"]
73
79
  it_should_accept "id", ["--id=1"]
80
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
81
+ it_should_accept 'location', %w[--id=1 --location-id=1]
74
82
  # it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
75
83
  end
76
84
 
@@ -84,9 +92,10 @@ describe HammerCLIForeman::Architecture do
84
92
  context "parameters" do
85
93
  it_should_accept "name", ["--name=arch", "--new-name=arch2"]
86
94
  it_should_accept "id", ["--id=1", "--new-name=arch2"]
95
+ it_should_accept 'organization', %w[--id=1 --new-name=arch2 --organization-id=1]
96
+ it_should_accept 'location', %w[--id=1 --new-name=arch2 --location-id=1]
87
97
  # it_should_fail_with "no params", [] # TODO: temporarily disabled, parameters are checked in the id resolver
88
98
  # it_should_fail_with "name or id missing", ["--new-name=arch2"] # TODO: temporarily disabled, parameters are checked in the id resolver
89
99
  end
90
-
91
100
  end
92
101
  end
@@ -0,0 +1,95 @@
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/bookmark'
7
+
8
+ describe HammerCLIForeman::Bookmark do
9
+ include CommandTestHelper
10
+
11
+ context 'ListCommand' do
12
+ before :each do
13
+ ResourceMocks.bookmarks
14
+ end
15
+
16
+ let(:cmd) { HammerCLIForeman::Bookmark::ListCommand.new('', ctx) }
17
+
18
+ context 'parameters' do
19
+ it_should_accept 'no arguments'
20
+ it_should_accept 'organization', ['--organization-id=1']
21
+ it_should_accept 'location', ['--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
+ it_should_print_column 'Controller'
31
+ it_should_print_column 'Search Query'
32
+ it_should_print_column 'Public'
33
+ it_should_print_column 'Owner Id'
34
+ it_should_print_column 'Owner Type'
35
+ end
36
+ end
37
+
38
+ context 'InfoCommand' do
39
+ let(:cmd) { HammerCLIForeman::Bookmark::InfoCommand.new('', ctx) }
40
+
41
+ context 'parameters' do
42
+ it_should_accept 'id', ['--id=1']
43
+ it_should_accept 'name', ['--name=active']
44
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
45
+ it_should_accept 'location', %w[--id=1 --location-id=1]
46
+ end
47
+
48
+ context 'output' do
49
+ with_params ['--id=1'] do
50
+ it_should_print_n_records 1
51
+ it_should_print_column 'Id'
52
+ it_should_print_column 'Name'
53
+ it_should_print_column 'Controller'
54
+ it_should_print_column 'Search Query'
55
+ it_should_print_column 'Public'
56
+ it_should_print_column 'Owner Id'
57
+ it_should_print_column 'Owner Type'
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'CreateCommand' do
63
+ let(:cmd) { HammerCLIForeman::Bookmark::CreateCommand.new('', ctx) }
64
+
65
+ context 'parameters' do
66
+ it_should_accept 'name, public, controller, query, organization, location',
67
+ ['--name=active', '--public=1', '--controller=hosts', '--organization-id=1', '--location-id=1',
68
+ '--query=last_report > "35 minutes ago" and (status.applied > 0 or status.restarted > 0)']
69
+ end
70
+
71
+ end
72
+
73
+ context 'DeleteCommand' do
74
+ let(:cmd) { HammerCLIForeman::Bookmark::DeleteCommand.new('', ctx) }
75
+
76
+ context 'parameters' do
77
+ it_should_accept 'id', ['--id=1']
78
+ it_should_accept 'name', ['--name=active']
79
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
80
+ it_should_accept 'location', %w[--id=1 --location-id=1]
81
+ end
82
+ end
83
+
84
+ context 'UpdateCommand' do
85
+ let(:cmd) { HammerCLIForeman::Bookmark::UpdateCommand.new('', ctx) }
86
+
87
+ context 'parameters' do
88
+ it_should_accept 'id', ['--id=1']
89
+ it_should_accept 'name', ['--name=active']
90
+ it_should_accept 'name, public, controller, query, organization, location',
91
+ ['--name=active', '--public=1', '--controller=hosts', '--organization-id=1', '--location-id=1',
92
+ '--query=last_report > "35 minutes ago" and (status.applied > 0 or status.restarted > 0)']
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,87 @@
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/compute_profile'
7
+
8
+ describe HammerCLIForeman::ComputeProfile do
9
+ include CommandTestHelper
10
+
11
+ context 'ListCommand' do
12
+ before :each do
13
+ ResourceMocks.compute_profiles
14
+ end
15
+
16
+ let(:cmd) { HammerCLIForeman::ComputeProfile::ListCommand.new('', ctx) }
17
+
18
+ context 'parameters' do
19
+ it_should_accept 'no arguments'
20
+ it_should_accept 'organization', ['--organization-id=1']
21
+ it_should_accept 'location', ['--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::ComputeProfile::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_accept 'organization', %w[--id=1 --organization-id=1]
40
+ it_should_accept 'location', %w[--id=1 --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 'Created at'
49
+ it_should_print_column 'Updated at'
50
+ it_should_print_column 'Compute attributes'
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'CreateCommand' do
56
+ let(:cmd) { HammerCLIForeman::ComputeProfile::CreateCommand.new('', ctx) }
57
+
58
+ context 'parameters' do
59
+ it_should_accept 'name', ['--name=test']
60
+ it_should_accept 'organization', %w[--name=test --organization-id=1]
61
+ it_should_accept 'location', %w[--name=test --location-id=1]
62
+ end
63
+
64
+ end
65
+
66
+ context 'DeleteCommand' do
67
+ let(:cmd) { HammerCLIForeman::ComputeProfile::DeleteCommand.new('', ctx) }
68
+
69
+ context 'parameters' do
70
+ it_should_accept 'id', ['--id=1']
71
+ it_should_accept 'name', ['--name=test']
72
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
73
+ it_should_accept 'location', %w[--id=1 --location-id=1]
74
+ end
75
+ end
76
+
77
+ context 'UpdateCommand' do
78
+ let(:cmd) { HammerCLIForeman::ComputeProfile::UpdateCommand.new('', ctx) }
79
+
80
+ context 'parameters' do
81
+ it_should_accept 'id', ['--id=1']
82
+ it_should_accept 'name', ['--name=test']
83
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
84
+ it_should_accept 'location', %w[--id=1 --location-id=1]
85
+ end
86
+ end
87
+ end