hammer_cli_katello 1.1.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/command_extensions/content_source.rb +32 -0
  3. data/lib/hammer_cli_katello/command_extensions/kickstart_repository.rb +50 -0
  4. data/lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb +12 -0
  5. data/lib/hammer_cli_katello/command_extensions.rb +2 -0
  6. data/lib/hammer_cli_katello/commands.rb +1 -1
  7. data/lib/hammer_cli_katello/content_export_helper.rb +6 -2
  8. data/lib/hammer_cli_katello/content_view.rb +11 -0
  9. data/lib/hammer_cli_katello/content_view_version.rb +3 -3
  10. data/lib/hammer_cli_katello/host_collection.rb +6 -0
  11. data/lib/hammer_cli_katello/host_collection_erratum.rb +10 -0
  12. data/lib/hammer_cli_katello/host_collection_package.rb +30 -0
  13. data/lib/hammer_cli_katello/host_collection_package_group.rb +30 -0
  14. data/lib/hammer_cli_katello/host_errata.rb +10 -3
  15. data/lib/hammer_cli_katello/host_extensions.rb +8 -6
  16. data/lib/hammer_cli_katello/host_package.rb +32 -0
  17. data/lib/hammer_cli_katello/host_package_group.rb +16 -0
  18. data/lib/hammer_cli_katello/hostgroup_extensions.rb +19 -12
  19. data/lib/hammer_cli_katello/id_resolver.rb +5 -2
  20. data/lib/hammer_cli_katello/option_sources/lifecycle_environment_params.rb +40 -3
  21. data/lib/hammer_cli_katello/organization.rb +28 -3
  22. data/lib/hammer_cli_katello/package.rb +2 -1
  23. data/lib/hammer_cli_katello/ping.rb +7 -0
  24. data/lib/hammer_cli_katello/repository.rb +10 -31
  25. data/lib/hammer_cli_katello/search_options_creators.rb +2 -1
  26. data/lib/hammer_cli_katello/srpm.rb +2 -0
  27. data/lib/hammer_cli_katello/version.rb +1 -1
  28. data/test/data/4.3/foreman_api.json +1 -0
  29. data/test/functional/activation_key/create_test.rb +1 -1
  30. data/test/functional/activation_key/subscriptions_test.rb +1 -1
  31. data/test/functional/content_view/version/promote_test.rb +41 -0
  32. data/test/functional/content_view/version/republish_repositories_test.rb +1 -1
  33. data/test/functional/host/errata/recalculate_test.rb +8 -22
  34. data/test/functional/host_collection/create_test.rb +11 -0
  35. data/test/functional/module_stream/info_test.rb +1 -1
  36. data/test/functional/organization/cdn_configuration_test.rb +42 -0
  37. data/test/functional/organization/info_test.rb +17 -0
  38. data/test/functional/package/list_test.rb +4 -2
  39. data/test/functional/ping_test.rb +3 -1
  40. data/test/functional/srpm/list_test.rb +1 -1
  41. data/test/functional/subscription/list_test.rb +2 -2
  42. data/test/test_helper.rb +1 -1
  43. metadata +9 -7
  44. data/lib/hammer_cli_katello/host_content_source_options.rb +0 -28
  45. data/lib/hammer_cli_katello/host_kickstart_repository_options.rb +0 -49
  46. data/test/functional/repository/export_test.rb +0 -121
@@ -4,7 +4,7 @@ require 'hammer_cli_katello/activation_key'
4
4
  module HammerCLIKatello
5
5
  describe ActivationKeyCommand do
6
6
  describe CreateCommand do
7
- it 'allows promoting a content view' do
7
+ it 'allows activation key creation' do
8
8
  ex = api_expects(:organizations, :index) do |p|
9
9
  p[:search] == "name = \"org1\""
10
10
  end
@@ -36,7 +36,7 @@ module HammerCLIKatello
36
36
  end
37
37
 
38
38
  it 'lists subscriptions used by the activation key' do
39
- api_expects(:subscriptions, :index) { |p| p['activation_key_id'] == 1 }
39
+ api_expects(:subscriptions, :index) { |p| p['activation_key_id'] == '1' }
40
40
  run_cmd(%w(activation-key subscriptions --organization-id 1 --id 1))
41
41
  end
42
42
 
@@ -30,5 +30,46 @@ module HammerCLIKatello
30
30
  run_cmd(%w(content-view version promote --organization org1 --content-view cv
31
31
  --to-lifecycle-environment test --version 1 --async))
32
32
  end
33
+
34
+ it 'allows promoting a content view without version name/id' do
35
+ ex = api_expects(:organizations, :index) do |p|
36
+ p[:search] == "name = \"org1\""
37
+ end
38
+ ex.at_least_once.returns(index_response([{'id' => 1}]))
39
+
40
+ ex = api_expects(:content_views, :index) do |p|
41
+ p['name'] == 'cv' && p['organization_id'] == 1
42
+ end
43
+ ex.returns(index_response([{'id' => 3}]))
44
+
45
+ ex = api_expects(:content_view_versions, :index) do |p|
46
+ p['content_view_id'] == 3
47
+ end
48
+ ex.returns(
49
+ index_response(
50
+ [
51
+ {'id' => 6, 'name' => 'cv', 'environments' => [{'id' => 1}]},
52
+ {'id' => 7, 'name' => 'cv2', 'environments' => [{'id' => 9}]}
53
+ ]
54
+ )
55
+ )
56
+
57
+ ex = api_expects(:lifecycle_environments, :index) do |p|
58
+ p['organization_id'] == 1 && p['name'] == 'Library'
59
+ end
60
+ ex.returns(index_response([{'id' => 1}]))
61
+
62
+ ex = api_expects(:lifecycle_environments, :index) do |p|
63
+ p['organization_id'] == 1 && p['name'] == 'test'
64
+ end
65
+ ex.returns(index_response([{'id' => 9}]))
66
+
67
+ api_expects(:content_view_versions, :promote) do |p|
68
+ p['id'] == 6 && p['environment_ids'] == [9]
69
+ end
70
+
71
+ run_cmd(%w(content-view version promote --organization org1 --content-view cv
72
+ --to-lifecycle-environment test --from-lifecycle-environment Library --async))
73
+ end
33
74
  end
34
75
  end
@@ -26,7 +26,7 @@ module HammerCLIKatello
26
26
  expect_foreman_task('3')
27
27
 
28
28
  result = run_cmd(%w(content-view version republish-repositories --organization org1
29
- --content-view cv --version 1))
29
+ --content-view cv --version 1 --force true))
30
30
 
31
31
  assert_equal(result.exit_code, 0)
32
32
  end
@@ -8,33 +8,19 @@ describe 'recalculate errata' do
8
8
  end
9
9
 
10
10
  let(:host_id) { 1 }
11
- let(:task_id) { '5' }
12
- let(:response) do
13
- {
14
- 'id' => task_id,
15
- 'state' => 'stopped'
16
- }
17
- end
18
11
 
19
12
  it "recalculates errata for a host" do
20
13
  params = ["--host-id=#{host_id}"]
21
14
 
22
15
  api_expects(:host_errata, :applicability, 'Host errata recalculate')
23
16
  .with_params('host_id' => host_id)
24
- .returns(response)
25
-
26
- expect_foreman_task(task_id)
27
-
28
- run_cmd(@cmd + params)
29
- end
30
-
31
- it "applies an errata to a host with async flag" do
32
- params = ["--host-id=#{host_id}", "--async"]
33
-
34
- api_expects(:host_errata, :applicability, 'Host errata recalculate')
35
- .with_params('host_id' => host_id)
36
- .returns(response)
37
-
38
- run_cmd(@cmd + params)
17
+ .returns({})
18
+
19
+ expected_result = success_result(
20
+ 'Errata recalculation started.
21
+ '
22
+ )
23
+ result = run_cmd(@cmd + params)
24
+ assert_cmd(expected_result, result)
39
25
  end
40
26
  end
@@ -29,6 +29,17 @@ module HammerCLIKatello
29
29
  run_cmd(%w(host-collection create --name hc1 --organization org1))
30
30
  end
31
31
 
32
+ it 'allows unlimited-hosts flag with no arguments' do
33
+ api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" }
34
+ .returns(index_response([{'id' => 1}]))
35
+
36
+ api_expects(:host_collections, :create) do |par|
37
+ par['unlimited_hosts'] == true
38
+ end
39
+
40
+ run_cmd(%w(host-collection create --name hc1 --organization org1 --unlimited-hosts))
41
+ end
42
+
32
43
  it 'allows organization label' do
33
44
  api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" }
34
45
  .returns(index_response([{'id' => 1}]))
@@ -15,7 +15,7 @@ module HammerCLIKatello
15
15
  .returns(index_response([{'id' => 1}]))
16
16
 
17
17
  api_expects(:module_streams, :show)
18
- .with_params(repository_id: "1", id: 1)
18
+ .with_params(repository_id: 1, id: 1)
19
19
 
20
20
  run_cmd(%w(module-stream info --name duck --repository-id 1))
21
21
  end
@@ -0,0 +1,42 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/organization'
3
+ require 'hammer_cli_katello/associating_commands'
4
+
5
+ describe HammerCLIKatello::Organization::ConfigureCdnCommand do
6
+ include OrganizationHelpers
7
+ before do
8
+ @cmd = %w(organization configure-cdn)
9
+ end
10
+
11
+ it 'by updates with the right params' do
12
+ org_id = '100'
13
+ org_label = 'org1'
14
+ ssl_cred_id = '1'
15
+ password = "pass"
16
+ username = "foo"
17
+ url = "https://goo.com"
18
+ upstream_label = "GreatOrg"
19
+ params = ["--label=#{org_label}",
20
+ "--url=#{url}",
21
+ "--username=#{username}",
22
+ "--upstream-organization-label=#{upstream_label}",
23
+ "--password=#{password}",
24
+ "--ssl-ca-credential-id=#{ssl_cred_id}"
25
+ ]
26
+ expect_organization_search(org_label, org_id, field: 'label')
27
+
28
+ api_expects(:organizations, :cdn_configuration) do |par|
29
+ par['id'].to_s == org_id &&
30
+ par['username'] == username &&
31
+ par['url'] == url &&
32
+ par['password'] == password &&
33
+ par['ssl_ca_credential_id'].to_s == ssl_cred_id &&
34
+ par['upstream_organization_label'] == upstream_label
35
+ end
36
+
37
+ assert_equal(
38
+ 0,
39
+ run_cmd(@cmd + params).exit_code
40
+ )
41
+ end
42
+ end
@@ -19,4 +19,21 @@ describe HammerCLIKatello::Organization::InfoCommand do
19
19
  expected = success_result(FieldMatcher.new('Simple Content Access', 'Enabled'))
20
20
  assert_cmd(expected, result)
21
21
  end
22
+
23
+ it "includes cdn configuration attributes" do
24
+ org_id = 2
25
+ params = ["--id=#{org_id}"]
26
+ api_expects(:organizations, :index).returns(index_response([{'id' => org_id}]))
27
+
28
+ cdn_configuration = {
29
+ "url" => "https://cdn.redhat.com"
30
+ }
31
+
32
+ api_expects(:organizations, :show)
33
+ .with_params('id' => org_id.to_s)
34
+ .returns("cdn_configuration" => cdn_configuration, "id" => org_id)
35
+ result = run_cmd(@cmd + params)
36
+ expected = success_result(FieldMatcher.new('URL', cdn_configuration["url"]))
37
+ assert_cmd(expected, result)
38
+ end
22
39
  end
@@ -24,7 +24,9 @@ module HammerCLIKatello
24
24
  api_expects(:content_view_versions, :index)
25
25
  .with_params('content_view_id' => 1, 'version' => '2.1')
26
26
  .returns(index_response([{'id' => 5}]))
27
- api_expects(:packages, :index).with_params('content_view_version_id' => 5)
27
+ api_expects(:packages, :index)
28
+ .with_params('content_view_version_id' => 5)
29
+ .returns(index_response([{'id' => 1}, {'id' => 2}]))
28
30
 
29
31
  run_cmd(%w(package list --content-view-id 1 --content-view-version 2.1))
30
32
  end
@@ -86,7 +88,7 @@ module HammerCLIKatello
86
88
  it 'may be specified environment name no org fails' do
87
89
  api_expects_no_call
88
90
  r = run_cmd(%w(package list --environment Library))
89
- expec_err = "--organization, --organization-title, --organization-label, --organization-id"
91
+ expec_err = "Missing options to search organization"
90
92
  puts r.err
91
93
  assert(r.err.include?(expec_err), "Invalid error message")
92
94
  end
@@ -15,6 +15,8 @@ describe 'ping' do
15
15
  'katello_events' =>
16
16
  {'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
17
17
  'pulp3' =>
18
+ {'status' => 'ok', 'duration_ms' => '34'},
19
+ 'pulp3_content' =>
18
20
  {'status' => 'ok', 'duration_ms' => '34'}
19
21
  }
20
22
  end
@@ -26,7 +28,7 @@ describe 'ping' do
26
28
  end
27
29
  let(:standard_response_keys) do
28
30
  %w(katello_agent foreman_tasks candlepin candlepin_events
29
- candlepin_auth katello_events pulp3).sort
31
+ candlepin_auth katello_events pulp3 pulp3_content).sort
30
32
  end
31
33
  let(:hammer_ping) { %w(ping katello) }
32
34
 
@@ -6,7 +6,7 @@ require 'hammer_cli_katello/package'
6
6
  require 'hammer_cli_katello/srpm'
7
7
 
8
8
  module HammerCLIKatello
9
- describe PackageCommand::ListCommand do
9
+ describe SrpmCommand::ListCommand do
10
10
  include OrganizationHelpers
11
11
  include RepositoryHelpers
12
12
  include ProductHelpers
@@ -60,7 +60,7 @@ module HammerCLIKatello
60
60
  end
61
61
 
62
62
  it 'allows host id' do
63
- api_expects(:subscriptions, :index) { |par| par['host_id'] == 1 }
63
+ api_expects(:subscriptions, :index) { |par| par['host_id'] == '1' }
64
64
  run_cmd(%w(subscription list --organization-id 1 --host-id 1))
65
65
  end
66
66
 
@@ -72,7 +72,7 @@ module HammerCLIKatello
72
72
  end
73
73
 
74
74
  it 'allows activation key id' do
75
- api_expects(:subscriptions, :index) { |par| par['activation_key_id'] == 1 }
75
+ api_expects(:subscriptions, :index) { |par| par['activation_key_id'] == '1' }
76
76
  run_cmd(%w(subscription list --organization-id 1 --activation-key-id 1))
77
77
  end
78
78
 
data/test/test_helper.rb CHANGED
@@ -17,7 +17,7 @@ require 'minitest/spec'
17
17
  require 'mocha/minitest'
18
18
  require 'hammer_cli'
19
19
 
20
- KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.1')
20
+ KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.3')
21
21
 
22
22
  if HammerCLI.context[:api_connection]
23
23
  HammerCLI.context[:api_connection].create('foreman') do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_katello
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Price
@@ -35,7 +35,7 @@ authors:
35
35
  autorequire:
36
36
  bindir: bin
37
37
  cert_chain: []
38
- date: 2021-05-14 00:00:00.000000000 Z
38
+ date: 2021-11-11 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: hammer_cli_foreman
@@ -206,6 +206,8 @@ files:
206
206
  - lib/hammer_cli_katello/associating_commands.rb
207
207
  - lib/hammer_cli_katello/capsule.rb
208
208
  - lib/hammer_cli_katello/command_extensions.rb
209
+ - lib/hammer_cli_katello/command_extensions/content_source.rb
210
+ - lib/hammer_cli_katello/command_extensions/kickstart_repository.rb
209
211
  - lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb
210
212
  - lib/hammer_cli_katello/command_extensions/lifecycle_environments.rb
211
213
  - lib/hammer_cli_katello/command_extensions/ping.rb
@@ -239,11 +241,9 @@ files:
239
241
  - lib/hammer_cli_katello/host_collection_erratum.rb
240
242
  - lib/hammer_cli_katello/host_collection_package.rb
241
243
  - lib/hammer_cli_katello/host_collection_package_group.rb
242
- - lib/hammer_cli_katello/host_content_source_options.rb
243
244
  - lib/hammer_cli_katello/host_deb.rb
244
245
  - lib/hammer_cli_katello/host_errata.rb
245
246
  - lib/hammer_cli_katello/host_extensions.rb
246
- - lib/hammer_cli_katello/host_kickstart_repository_options.rb
247
247
  - lib/hammer_cli_katello/host_package.rb
248
248
  - lib/hammer_cli_katello/host_package_group.rb
249
249
  - lib/hammer_cli_katello/host_subscription.rb
@@ -317,6 +317,7 @@ files:
317
317
  - test/data/3.9/foreman_api.json
318
318
  - test/data/4.0/foreman_api.json
319
319
  - test/data/4.1/foreman_api.json
320
+ - test/data/4.3/foreman_api.json
320
321
  - test/data/Readme.md
321
322
  - test/functional/activation_key/add_host_collection_test.rb
322
323
  - test/functional/activation_key/content_override_test.rb
@@ -439,6 +440,7 @@ files:
439
440
  - test/functional/local_helper_test.rb
440
441
  - test/functional/module_stream/info_test.rb
441
442
  - test/functional/module_stream/list_test.rb
443
+ - test/functional/organization/cdn_configuration_test.rb
442
444
  - test/functional/organization/delete_test.rb
443
445
  - test/functional/organization/info_test.rb
444
446
  - test/functional/organization/organization_helpers.rb
@@ -456,7 +458,6 @@ files:
456
458
  - test/functional/product/update_test.rb
457
459
  - test/functional/repository/create_test.rb
458
460
  - test/functional/repository/delete_test.rb
459
- - test/functional/repository/export_test.rb
460
461
  - test/functional/repository/info_test.rb
461
462
  - test/functional/repository/list_test.rb
462
463
  - test/functional/repository/remove_content_test.rb
@@ -507,7 +508,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
507
508
  - !ruby/object:Gem::Version
508
509
  version: '0'
509
510
  requirements: []
510
- rubygems_version: 3.1.2
511
+ rubygems_version: 3.1.6
511
512
  signing_key:
512
513
  specification_version: 4
513
514
  summary: Katello commands for Hammer
@@ -533,6 +534,7 @@ test_files:
533
534
  - test/data/3.9/foreman_api.json
534
535
  - test/data/4.0/foreman_api.json
535
536
  - test/data/4.1/foreman_api.json
537
+ - test/data/4.3/foreman_api.json
536
538
  - test/data/Readme.md
537
539
  - test/functional/activation_key/add_host_collection_test.rb
538
540
  - test/functional/activation_key/content_override_test.rb
@@ -655,6 +657,7 @@ test_files:
655
657
  - test/functional/local_helper_test.rb
656
658
  - test/functional/module_stream/info_test.rb
657
659
  - test/functional/module_stream/list_test.rb
660
+ - test/functional/organization/cdn_configuration_test.rb
658
661
  - test/functional/organization/delete_test.rb
659
662
  - test/functional/organization/info_test.rb
660
663
  - test/functional/organization/organization_helpers.rb
@@ -672,7 +675,6 @@ test_files:
672
675
  - test/functional/product/update_test.rb
673
676
  - test/functional/repository/create_test.rb
674
677
  - test/functional/repository/delete_test.rb
675
- - test/functional/repository/export_test.rb
676
678
  - test/functional/repository/info_test.rb
677
679
  - test/functional/repository/list_test.rb
678
680
  - test/functional/repository/remove_content_test.rb
@@ -1,28 +0,0 @@
1
- module HammerCLIKatello
2
- module HostContentSourceOptions
3
- def self.included(base)
4
- base.option "--content-source", "CONTENT_SOURCE_NAME",
5
- _("Content Source name "),
6
- :attribute_name => :option_content_source
7
- end
8
-
9
- def request_params
10
- super.tap do |mod|
11
- resource_name = resource.singular_name
12
- if option_content_source && !option_content_source_id
13
- resource_hash = if resource_name == "hostgroup"
14
- mod[resource_name]
15
- else
16
- mod[resource_name]["content_facet_attributes"]
17
- end
18
-
19
- proxy_options = { HammerCLI.option_accessor_name('name') => option_content_source}
20
- resource_hash["content_source_id"] = resolver.smart_proxy_id(proxy_options)
21
- end
22
- end
23
- rescue HammerCLIForeman::ResolverError => e
24
- e.message.gsub!('smart_proxy', _('Content Source'))
25
- raise e
26
- end
27
- end
28
- end
@@ -1,49 +0,0 @@
1
- module HammerCLIKatello
2
- module HostKickstartRepositoryOptions
3
- def self.included(base)
4
- base.option "--kickstart-repository", "REPOSITORY_NAME",
5
- _("Kickstart repository name "),
6
- :attribute_name => :option_kickstart_repository
7
- end
8
-
9
- def request_params
10
- super.tap do |mod|
11
- resource_name = resource.singular_name
12
- if option_kickstart_repository && !option_kickstart_repository_id
13
- resource_hash = if resource_name == "hostgroup"
14
- mod[resource_name]
15
- else
16
- mod[resource_name]["content_facet_attributes"]
17
- end
18
-
19
- resource_hash ||= {}
20
-
21
- env_id = resource_hash["lifecycle_environment_id"]
22
- cv_id = resource_hash["content_view_id"]
23
-
24
- raise _("Please provide --lifecycle-environment-id") unless env_id
25
-
26
- raise _("Please provide --content-view-id") unless cv_id
27
-
28
- resource_hash["kickstart_repository_id"] = fetch_repo_id(cv_id, env_id,
29
- option_kickstart_repository)
30
- end
31
- end
32
- end
33
-
34
- def fetch_repo_id(cv_id, env_id, repo_name)
35
- repo_resource = HammerCLIForeman.foreman_resource(:repositories)
36
- index_options = {
37
- :content_view_id => cv_id,
38
- :environment_id => env_id,
39
- :name => repo_name
40
- }
41
- repos = repo_resource.call(:index, index_options)["results"]
42
- if repos.empty?
43
- raise _("No such repository with name %{name}, in lifecycle environment"\
44
- " %{environment_id} and content view %{content_view_id}" % index_options)
45
- end
46
- repos.first["id"]
47
- end
48
- end
49
- end
@@ -1,121 +0,0 @@
1
- require_relative '../test_helper'
2
- require_relative '../organization/organization_helpers'
3
- require 'hammer_cli_katello/repository'
4
-
5
- module HammerCLIKatello
6
- describe Repository::ExportCommand do
7
- include ForemanTaskHelpers
8
- include OrganizationHelpers
9
-
10
- it 'allows minimal options' do
11
- ex = api_expects(:repositories, :export) do |p|
12
- p['id'] == 1
13
- end
14
- ex.returns(id: '2')
15
-
16
- expect_foreman_task('2')
17
-
18
- run_cmd(%w(repository export --id 1))
19
- end
20
-
21
- describe 'resolves repository ID' do
22
- it 'by requiring product' do
23
- api_expects_no_call
24
- result = run_cmd(%w(repository export --name repo1))
25
- assert(result.err[/--product, --product-id is required/], 'Incorrect error message')
26
- end
27
-
28
- it 'by product ID' do
29
- ex = api_expects(:repositories, :index) do |p|
30
- p['name'] == 'repo1' && p['product_id'] == 3
31
- end
32
- ex.returns(index_response([{'id' => 1}]))
33
-
34
- ex = api_expects(:repositories, :export) do |p|
35
- p['id'] == 1
36
- end
37
- ex.returns(id: '2')
38
-
39
- expect_foreman_task('2')
40
-
41
- run_cmd(%w(repository export --name repo1 --product-id 3))
42
- end
43
- end
44
-
45
- describe 'resolves product ID' do
46
- it 'by requiring organization options' do
47
- api_expects_no_call
48
- result = run_cmd(%w(repository export --name repo1 --product prod1))
49
- assert(result.err[/--organization-id, --organization, --organization-label is required/],
50
- "Organization option requirements must be validated")
51
- end
52
-
53
- it 'by organization ID' do
54
- ex = api_expects(:products, :index) do |p|
55
- p['name'] == 'prod3' && p['organization_id'] == '5'
56
- end
57
- ex.returns(index_response([{'id' => 3}]))
58
-
59
- ex = api_expects(:repositories, :index) do |p|
60
- p['name'] == 'repo1' && p['product_id'] == 3
61
- end
62
- ex.returns(index_response([{'id' => 1}]))
63
-
64
- ex = api_expects(:repositories, :export) do |p|
65
- p['id'] == 1
66
- end
67
- ex.returns(id: '2')
68
-
69
- expect_foreman_task('2')
70
-
71
- run_cmd(%w(repository export --name repo1 --product prod3 --organization-id 5))
72
- end
73
-
74
- it 'by organization name' do
75
- expect_organization_search('org5', 5)
76
-
77
- ex = api_expects(:products, :index) do |p|
78
- p['name'] == 'prod3' && p['organization_id'] == 5
79
- end
80
- ex.returns(index_response([{'id' => 3}]))
81
-
82
- ex = api_expects(:repositories, :index) do |p|
83
- p['name'] == 'repo1' && p['product_id'] == 3
84
- end
85
- ex.returns(index_response([{'id' => 1}]))
86
-
87
- ex = api_expects(:repositories, :export) do |p|
88
- p['id'] == 1
89
- end
90
- ex.returns(id: '2')
91
-
92
- expect_foreman_task('2')
93
-
94
- run_cmd(%w(repository export --name repo1 --product prod3 --organization org5))
95
- end
96
-
97
- it 'by organization label' do
98
- expect_organization_search('org5', 5, field: 'label')
99
-
100
- ex = api_expects(:products, :index) do |p|
101
- p['name'] == 'prod3' && p['organization_id'] == 5
102
- end
103
- ex.returns(index_response([{'id' => 3}]))
104
-
105
- ex = api_expects(:repositories, :index) do |p|
106
- p['name'] == 'repo1' && p['product_id'] == 3
107
- end
108
- ex.returns(index_response([{'id' => 1}]))
109
-
110
- ex = api_expects(:repositories, :export) do |p|
111
- p['id'] == 1
112
- end
113
- ex.returns(id: '2')
114
-
115
- expect_foreman_task('2')
116
-
117
- run_cmd(%w(repository export --name repo1 --product prod3 --organization-label org5))
118
- end
119
- end
120
- end
121
- end