hammer_cli_katello 0.24.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +24 -15
  3. data/lib/hammer_cli_katello/activation_key.rb +5 -5
  4. data/lib/hammer_cli_katello/capsule.rb +2 -3
  5. data/lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb +10 -7
  6. data/lib/hammer_cli_katello/command_extensions/lifecycle_environments.rb +11 -8
  7. data/lib/hammer_cli_katello/content_credential.rb +20 -19
  8. data/lib/hammer_cli_katello/content_export.rb +73 -0
  9. data/lib/hammer_cli_katello/content_export_complete.rb +25 -0
  10. data/lib/hammer_cli_katello/content_export_helper.rb +181 -0
  11. data/lib/hammer_cli_katello/content_export_incremental.rb +25 -0
  12. data/lib/hammer_cli_katello/content_import.rb +78 -0
  13. data/lib/hammer_cli_katello/content_view.rb +19 -32
  14. data/lib/hammer_cli_katello/content_view_version.rb +4 -290
  15. data/lib/hammer_cli_katello/deb_package.rb +3 -3
  16. data/lib/hammer_cli_katello/docker.rb +13 -0
  17. data/lib/hammer_cli_katello/docker_manifest.rb +53 -0
  18. data/lib/hammer_cli_katello/docker_tag.rb +40 -0
  19. data/lib/hammer_cli_katello/erratum.rb +1 -1
  20. data/lib/hammer_cli_katello/erratum_info_command.rb +1 -1
  21. data/lib/hammer_cli_katello/file.rb +3 -3
  22. data/lib/hammer_cli_katello/filter.rb +2 -2
  23. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  24. data/lib/hammer_cli_katello/host_collection.rb +2 -2
  25. data/lib/hammer_cli_katello/host_deb.rb +1 -1
  26. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  27. data/lib/hammer_cli_katello/host_extensions.rb +5 -5
  28. data/lib/hammer_cli_katello/host_package.rb +1 -1
  29. data/lib/hammer_cli_katello/hostgroup_extensions.rb +4 -4
  30. data/lib/hammer_cli_katello/id_resolver.rb +8 -7
  31. data/lib/hammer_cli_katello/lifecycle_environment.rb +2 -2
  32. data/lib/hammer_cli_katello/module_stream.rb +8 -8
  33. data/lib/hammer_cli_katello/organization.rb +10 -0
  34. data/lib/hammer_cli_katello/organization_options.rb +8 -6
  35. data/lib/hammer_cli_katello/ostree_branch.rb +2 -2
  36. data/lib/hammer_cli_katello/package.rb +5 -5
  37. data/lib/hammer_cli_katello/package_group.rb +4 -4
  38. data/lib/hammer_cli_katello/ping.rb +13 -19
  39. data/lib/hammer_cli_katello/product.rb +3 -3
  40. data/lib/hammer_cli_katello/product_content.rb +2 -2
  41. data/lib/hammer_cli_katello/repository.rb +27 -37
  42. data/lib/hammer_cli_katello/repository_set.rb +4 -4
  43. data/lib/hammer_cli_katello/simple_content_access.rb +42 -0
  44. data/lib/hammer_cli_katello/srpm.rb +2 -2
  45. data/lib/hammer_cli_katello/subscription.rb +2 -3
  46. data/lib/hammer_cli_katello/sync_plan.rb +2 -2
  47. data/lib/hammer_cli_katello/version.rb +1 -1
  48. data/locale/hammer-cli-katello.pot +0 -25
  49. data/test/data/3.19/foreman_api.json +1 -0
  50. data/test/data/4.0/foreman_api.json +1 -0
  51. data/test/data/4.1/foreman_api.json +1 -0
  52. data/test/functional/activation_key/subscriptions_test.rb +5 -2
  53. data/test/functional/capsule/content/info_test.rb +1 -2
  54. data/test/functional/content_credentials/create_test.rb +32 -0
  55. data/test/functional/{repository → content_credentials}/data/test_cert.json +0 -0
  56. data/test/functional/content_credentials/list_test.rb +6 -8
  57. data/test/functional/content_export/complete/library_test.rb +155 -0
  58. data/test/functional/content_export/complete/version_test.rb +217 -0
  59. data/test/functional/content_export/content_export_helpers.rb +26 -0
  60. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  61. data/test/functional/content_export/incremental/library_test.rb +172 -0
  62. data/test/functional/content_export/incremental/version_test.rb +268 -0
  63. data/test/functional/content_export/list_test.rb +64 -0
  64. data/test/functional/content_import/library_test.rb +85 -0
  65. data/test/functional/content_import/list_test.rb +65 -0
  66. data/test/functional/content_import/metadata.json +1 -0
  67. data/test/functional/content_import/version_test.rb +85 -0
  68. data/test/functional/content_view/content_view_helpers.rb +3 -1
  69. data/test/functional/content_view/list_test.rb +0 -2
  70. data/test/functional/content_view/publish_test.rb +0 -21
  71. data/test/functional/content_view/version/promote_test.rb +1 -2
  72. data/test/functional/content_view/version/republish_repositories_test.rb +1 -2
  73. data/test/functional/host/errata/apply_test.rb +0 -2
  74. data/test/functional/host/errata/recalculate_test.rb +0 -2
  75. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +1 -1
  76. data/test/functional/organization/info_test.rb +22 -0
  77. data/test/functional/ping_test.rb +52 -15
  78. data/test/functional/repository/create_test.rb +0 -30
  79. data/test/functional/repository/info_test.rb +4 -4
  80. data/test/functional/repository/list_test.rb +0 -2
  81. data/test/functional/search_helpers.rb +11 -0
  82. data/test/functional/simple_content_access/disable_test.rb +48 -0
  83. data/test/functional/simple_content_access/enable_test.rb +46 -0
  84. data/test/test_helper.rb +1 -1
  85. metadata +50 -56
  86. data/lib/hammer_cli_katello/content_view_puppet_module.rb +0 -60
  87. data/lib/hammer_cli_katello/cv_import_export_helper.rb +0 -166
  88. data/lib/hammer_cli_katello/gpg_key.rb +0 -67
  89. data/lib/hammer_cli_katello/puppet_module.rb +0 -59
  90. data/test/functional/content_view/puppet_module/add_test.rb +0 -24
  91. data/test/functional/content_view/puppet_module/remove_test.rb +0 -54
  92. data/test/functional/content_view/version/default_export_test.rb +0 -40
  93. data/test/functional/content_view/version/export_histories_test.rb +0 -34
  94. data/test/functional/content_view/version/export_test.rb +0 -136
  95. data/test/functional/content_view/version/import_test.rb +0 -318
  96. data/test/functional/gpg_test.rb +0 -39
  97. data/test/functional/repository/data/test_ca.json +0 -43
  98. data/test/functional/repository/data/test_key.json +0 -43
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_export'
3
+
4
+ describe 'content-export list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_exports, :index)
23
+
24
+ ex.returns(empty_response)
25
+ # rubocop:disable LineLength
26
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
27
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
28
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
29
+ ')
30
+ # rubocop:enable LineLength
31
+ result = run_cmd(%w(content-export list))
32
+ assert_cmd(expected_result, result)
33
+ end
34
+
35
+ it 'works with content-view-id only' do
36
+ api_expects(:content_view_versions, :index).returns(empty_response)
37
+
38
+ ex = api_expects(:content_exports, :index)
39
+
40
+ ex.returns(empty_response)
41
+ # rubocop:disable LineLength
42
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
43
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
44
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
45
+ ')
46
+ # rubocop:enable LineLength
47
+ result = run_cmd(%w(content-export list --content-view-id=1))
48
+ assert_cmd(expected_result, result)
49
+ end
50
+
51
+ it 'works with content-view-version-id only' do
52
+ ex = api_expects(:content_exports, :index)
53
+
54
+ ex.returns(empty_response)
55
+ # rubocop:disable LineLength
56
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
57
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
58
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
59
+ ')
60
+ # rubocop:enable LineLength
61
+ result = run_cmd(%w(content-export list --content-view-version-id=1))
62
+ assert_cmd(expected_result, result)
63
+ end
64
+ end
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import library' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import library)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :library)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :library)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -0,0 +1,65 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_imports, :index)
23
+
24
+ ex.returns(empty_response)
25
+
26
+ # rubocop:disable LineLength
27
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
28
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
29
+ ---|------|------|----------------------|-------------------------|------------|-----------
30
+ ')
31
+ # rubocop:enable LineLength
32
+ result = run_cmd(%w(content-import list))
33
+ assert_cmd(expected_result, result)
34
+ end
35
+
36
+ it 'works with content-view-id only' do
37
+ api_expects(:content_view_versions, :index).returns(empty_response)
38
+
39
+ ex = api_expects(:content_imports, :index)
40
+
41
+ ex.returns(empty_response)
42
+ # rubocop:disable LineLength
43
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
44
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
45
+ ---|------|------|----------------------|-------------------------|------------|-----------
46
+ ')
47
+ # rubocop:enable LineLength
48
+ result = run_cmd(%w(content-import list --content-view-id=1))
49
+ assert_cmd(expected_result, result)
50
+ end
51
+
52
+ it 'works with content-view-version-id only' do
53
+ ex = api_expects(:content_imports, :index)
54
+
55
+ ex.returns(empty_response)
56
+ # rubocop:disable LineLength
57
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
58
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
59
+ ---|------|------|----------------------|-------------------------|------------|-----------
60
+ ')
61
+ # rubocop:enable LineLength
62
+ result = run_cmd(%w(content-import list --content-view-version-id=1))
63
+ assert_cmd(expected_result, result)
64
+ end
65
+ end
@@ -0,0 +1 @@
1
+ {"organization":"export-9697","repository_mapping":{"katello-15062":{"repository":"katello","product":"prod","redhat":false},"misc-28137":{"repository":"misc","product":"prod","redhat":false},"candlepin-37918":{"repository":"candlepin","product":"prod","redhat":false}},"content_view":"view","content_view_version":{"major":1,"minor":0},"incremental":false,"toc":"export-24d91ced-3d11-4fa2-b5ea-19a41f7b97a5-20201118_1523-toc.json"}
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import version' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import version)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :version)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :version)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -13,6 +13,8 @@ module ContentViewHelpers
13
13
  end
14
14
 
15
15
  def expect_content_view_version_search(params, returns)
16
- expect_generic_search(:content_view_versions, params: params, returns: returns)
16
+ expect_lenient_search(:content_view_versions,
17
+ params: params,
18
+ returns: returns)
17
19
  end
18
20
  end
@@ -1,8 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), '../test_helper')
2
2
  require File.join(File.dirname(__FILE__), '../lifecycle_environment/lifecycle_environment_helpers')
3
3
 
4
- require 'hammer_cli_katello/content_view_puppet_module'
5
-
6
4
  describe 'listing content-views' do
7
5
  include LifecycleEnvironmentHelpers
8
6
 
@@ -1,5 +1,4 @@
1
1
  require_relative '../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
  require 'hammer_cli_katello/content_view'
4
3
 
5
4
  module HammerCLIKatello
@@ -22,24 +21,4 @@ module HammerCLIKatello
22
21
  run_cmd(%w(content-view publish --major 5 --minor 1 --organization org1 --name cv --async))
23
22
  end
24
23
  end
25
-
26
- describe ContentViewPuppetModule do
27
- it 'allows adding a puppet module' do
28
- ex = api_expects(:organizations, :index) do |p|
29
- p[:search] == "name = \"org1\""
30
- end
31
- ex.returns(index_response([{'id' => 1}]))
32
-
33
- ex = api_expects(:content_views, :index) do |p|
34
- p['name'] == 'cv' && p['organization_id'] == 1
35
- end
36
- ex.returns(index_response([{'id' => 3}]))
37
-
38
- api_expects(:content_views, :publish) do |p|
39
- p['id'] == 3
40
- end
41
-
42
- run_cmd(%w(content-view publish --organization org1 --name cv --async))
43
- end
44
- end
45
24
  end
@@ -1,8 +1,7 @@
1
1
  require_relative '../../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
 
4
3
  module HammerCLIKatello
5
- describe ContentViewPuppetModule do
4
+ describe ContentViewVersion::PromoteCommand do
6
5
  it 'allows promoting a content view' do
7
6
  ex = api_expects(:organizations, :index) do |p|
8
7
  p[:search] == "name = \"org1\""
@@ -1,8 +1,7 @@
1
1
  require_relative '../../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
 
4
3
  module HammerCLIKatello
5
- describe ContentViewPuppetModule do
4
+ describe ContentViewVersion::RepublishRepositoriesCommand do
6
5
  include ForemanTaskHelpers
7
6
  include OrganizationHelpers
8
7
 
@@ -1,7 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '../../test_helper')
2
2
 
3
- require 'hammer_cli_katello/content_view_puppet_module'
4
-
5
3
  describe 'apply an errata' do
6
4
  include ForemanTaskHelpers
7
5
 
@@ -1,7 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '../../test_helper')
2
2
 
3
- require 'hammer_cli_katello/content_view_puppet_module'
4
-
5
3
  describe 'recalculate errata' do
6
4
  include ForemanTaskHelpers
7
5
 
@@ -4,7 +4,7 @@ module LifecycleEnvironmentHelpers
4
4
  include SearchHelpers
5
5
 
6
6
  def expect_lifecycle_environment_search(org_id, name, id)
7
- expect_generic_search(:lifecycle_environments,
7
+ expect_lenient_search(:lifecycle_environments,
8
8
  params: {'name' => name, 'organization_id' => org_id},
9
9
  returns: {'id' => id})
10
10
  end
@@ -0,0 +1,22 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/organization'
3
+ require 'hammer_cli_katello/associating_commands'
4
+
5
+ describe HammerCLIKatello::Organization::InfoCommand do
6
+ before do
7
+ @cmd = %w(organization info)
8
+ end
9
+
10
+ it "includes simple content access attributes" do
11
+ org_id = 2
12
+ params = ["--id=#{org_id}"]
13
+ api_expects(:organizations, :index).returns(index_response([{'id' => org_id}]))
14
+
15
+ api_expects(:organizations, :show)
16
+ .with_params('id' => org_id.to_s)
17
+ .returns("simple_content_access" => true, "id" => org_id)
18
+ result = run_cmd(@cmd + params)
19
+ expected = success_result(FieldMatcher.new('Simple Content Access', 'Enabled'))
20
+ assert_cmd(expected, result)
21
+ end
22
+ end
@@ -1,22 +1,59 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  describe 'ping' do
4
+ let(:standard_response_services) do
5
+ {
6
+ 'katello_agent' =>
7
+ {'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
8
+ 'foreman_tasks' =>
9
+ {'status' => 'ok', 'duration_ms' => '34'},
10
+ 'candlepin' => {'status' => 'ok', 'duration_ms' => '34'},
11
+ 'candlepin_events' =>
12
+ {'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
13
+ 'candlepin_auth' =>
14
+ {'status' => 'ok', 'duration_ms' => '34'},
15
+ 'katello_events' =>
16
+ {'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
17
+ 'pulp3' =>
18
+ {'status' => 'ok', 'duration_ms' => '34'}
19
+ }
20
+ end
21
+ let(:standard_response) do
22
+ {
23
+ 'status' => 'ok',
24
+ 'services' => standard_response_services
25
+ }
26
+ end
27
+ let(:standard_response_keys) do
28
+ %w(katello_agent foreman_tasks candlepin candlepin_events
29
+ candlepin_auth katello_events pulp3).sort
30
+ end
31
+ let(:hammer_ping) { %w(ping katello) }
32
+
4
33
  it 'does not require authentication' do
5
- api_expects(:ping, :index).returns(
34
+ api_expects(:ping, :index).returns(standard_response)
35
+
36
+ run_cmd(hammer_ping)
37
+ end
38
+
39
+ it "includes all keys" do
40
+ api_expects(:ping, :index).returns(standard_response)
41
+
42
+ result = JSON.parse(run_cmd(%w(--output=json ping katello))&.out)&.first&.keys&.sort
43
+ expected = standard_response_keys
44
+
45
+ assert_equal result, expected
46
+ end
47
+
48
+ it "skips katello_agent if not included in API response" do
49
+ response_without_katello_agent = {
6
50
  'status' => 'ok',
7
- 'services' => {
8
- 'foreman_tasks' => {'status' => 'ok', 'duration_ms' => '34'},
9
- 'foreman_auth' => {'status' => 'ok', 'duration_ms' => '34'},
10
- 'candlepin' => {'status' => 'ok', 'duration_ms' => '34'},
11
- 'candlepin_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
12
- 'candlepin_auth' => {'status' => 'ok', 'duration_ms' => '34'},
13
- 'katello_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
14
- 'pulp' => {'status' => 'ok', 'duration_ms' => '34'},
15
- 'pulp_auth' => {'status' => 'ok', 'duration_ms' => '34'},
16
- 'pulp3' => {'status' => 'ok', 'duration_ms' => '34'}
17
- }
18
- )
19
-
20
- run_cmd(%w(ping katello))
51
+ 'services' => standard_response_services.select { |k, _v| k != 'katello_agent' }
52
+ }
53
+ api_expects(:ping, :index).returns(response_without_katello_agent)
54
+ result = JSON.parse(run_cmd(%w(--output=json ping katello))&.out)&.first&.keys&.sort
55
+ expected = standard_response_keys.select { |k| k != 'katello_agent' }
56
+
57
+ assert_equal result, expected
21
58
  end
22
59
  end