hammer_cli_katello 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
- data/lib/hammer_cli_katello/host_collection.rb +6 -0
- data/lib/hammer_cli_katello/host_errata.rb +1 -1
- data/lib/hammer_cli_katello/repository.rb +0 -27
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/test/data/2.5/foreman_api.json +1 -0
- data/test/data/3.0/foreman_api.json +1 -0
- data/test/data/3.10/foreman_api.json +1 -0
- data/test/data/3.11/foreman_api.json +1 -0
- data/test/data/3.12/foreman_api.json +1 -0
- data/test/data/3.13/foreman_api.json +1 -0
- data/test/data/3.14/foreman_api.json +1 -0
- data/test/data/3.15/foreman_api.json +1 -0
- data/test/data/3.16/foreman_api.json +1 -0
- data/test/data/3.17/foreman_api.json +1 -0
- data/test/data/3.18/foreman_api.json +1 -0
- data/test/data/3.19/foreman_api.json +1 -0
- data/test/data/3.2/foreman_api.json +1 -0
- data/test/data/3.4/foreman_api.json +1 -0
- data/test/data/3.5/foreman_api.json +1 -0
- data/test/data/3.6/foreman_api.json +1 -0
- data/test/data/3.7/foreman_api.json +1 -0
- data/test/data/3.8/foreman_api.json +1 -0
- data/test/data/3.9/foreman_api.json +1 -0
- data/test/data/4.0/foreman_api.json +1 -0
- data/test/data/4.1/foreman_api.json +1 -0
- data/test/data/Readme.md +5 -0
- data/test/functional/activation_key/add_host_collection_test.rb +62 -0
- data/test/functional/activation_key/content_override_test.rb +92 -0
- data/test/functional/activation_key/create_test.rb +33 -0
- data/test/functional/activation_key/data/activation_key.json +17 -0
- data/test/functional/activation_key/info_test.rb +29 -0
- data/test/functional/activation_key/list_test.rb +68 -0
- data/test/functional/activation_key/product_content_test.rb +23 -0
- data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
- data/test/functional/activation_key/subscriptions_test.rb +74 -0
- data/test/functional/activation_key/update_test.rb +26 -0
- data/test/functional/apipie_helper_test.rb +31 -0
- data/test/functional/capsule/capsule_helpers.rb +13 -0
- data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
- data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
- data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
- data/test/functional/capsule/content/data/library_env.json +47 -0
- data/test/functional/capsule/content/data/sync_status.json +6 -0
- data/test/functional/capsule/content/data/sync_tasks.json +62 -0
- data/test/functional/capsule/content/info_test.rb +61 -0
- data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
- data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
- data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
- data/test/functional/capsule/info_test.rb +25 -0
- data/test/functional/capsule/list_test.rb +24 -0
- data/test/functional/content_credentials/create_test.rb +32 -0
- data/test/functional/content_credentials/data/test_cert.json +43 -0
- data/test/functional/content_credentials/info_test.rb +50 -0
- data/test/functional/content_credentials/list_test.rb +66 -0
- data/test/functional/content_export/complete/library_test.rb +155 -0
- data/test/functional/content_export/complete/version_test.rb +252 -0
- data/test/functional/content_export/content_export_helpers.rb +26 -0
- data/test/functional/content_export/generate_metadata_test.rb +64 -0
- data/test/functional/content_export/incremental/library_test.rb +172 -0
- data/test/functional/content_export/incremental/version_test.rb +268 -0
- data/test/functional/content_export/list_test.rb +64 -0
- data/test/functional/content_import/library_test.rb +85 -0
- data/test/functional/content_import/list_test.rb +65 -0
- data/test/functional/content_import/metadata.json +1 -0
- data/test/functional/content_import/version_test.rb +85 -0
- data/test/functional/content_view/add_content_view_version_test.rb +88 -0
- data/test/functional/content_view/add_repository_test.rb +21 -0
- data/test/functional/content_view/component/add_test.rb +177 -0
- data/test/functional/content_view/component/list_test.rb +55 -0
- data/test/functional/content_view/component/remove_test.rb +107 -0
- data/test/functional/content_view/component/update_test.rb +134 -0
- data/test/functional/content_view/content_view_helpers.rb +20 -0
- data/test/functional/content_view/copy_test.rb +53 -0
- data/test/functional/content_view/create_test.rb +34 -0
- data/test/functional/content_view/delete_test.rb +62 -0
- data/test/functional/content_view/filter/create_test.rb +57 -0
- data/test/functional/content_view/filter/delete_test.rb +90 -0
- data/test/functional/content_view/filter/info_test.rb +89 -0
- data/test/functional/content_view/filter/list_test.rb +98 -0
- data/test/functional/content_view/filter/update_test.rb +91 -0
- data/test/functional/content_view/list_test.rb +68 -0
- data/test/functional/content_view/publish_test.rb +24 -0
- data/test/functional/content_view/purge_test.rb +97 -0
- data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
- data/test/functional/content_view/remove_test.rb +79 -0
- data/test/functional/content_view/update_test.rb +53 -0
- data/test/functional/content_view/version/incremental_update_test.rb +108 -0
- data/test/functional/content_view/version/list_test.rb +44 -0
- data/test/functional/content_view/version/promote_test.rb +34 -0
- data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
- data/test/functional/content_view/version/update_test.rb +48 -0
- data/test/functional/erratum/erratum_helpers.rb +91 -0
- data/test/functional/erratum/info_test.rb +29 -0
- data/test/functional/erratum/list_test.rb +108 -0
- data/test/functional/file/file_helpers.rb +13 -0
- data/test/functional/file/info_test.rb +162 -0
- data/test/functional/file/list_test.rb +112 -0
- data/test/functional/filter_rule/create_test.rb +99 -0
- data/test/functional/filter_rule/delete_test.rb +104 -0
- data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
- data/test/functional/filter_rule/info_test.rb +104 -0
- data/test/functional/filter_rule/list_test.rb +91 -0
- data/test/functional/filter_rule/update_test.rb +104 -0
- data/test/functional/host/errata/apply_test.rb +45 -0
- data/test/functional/host/errata/info_test.rb +27 -0
- data/test/functional/host/errata/list_test.rb +49 -0
- data/test/functional/host/errata/recalculate_test.rb +40 -0
- data/test/functional/host/extensions/create_test.rb +95 -0
- data/test/functional/host/extensions/data/host.json +320 -0
- data/test/functional/host/extensions/data/host_list.json +117 -0
- data/test/functional/host/extensions/info_test.rb +35 -0
- data/test/functional/host/extensions/list_test.rb +21 -0
- data/test/functional/host/extensions/update_test.rb +70 -0
- data/test/functional/host/host_helpers.rb +8 -0
- data/test/functional/host/subscription/attach_test.rb +54 -0
- data/test/functional/host/subscription/auto_attach_test.rb +35 -0
- data/test/functional/host/subscription/content_override_test.rb +96 -0
- data/test/functional/host/subscription/product_content_test.rb +27 -0
- data/test/functional/host/subscription/register_test.rb +53 -0
- data/test/functional/host/subscription/remove_test.rb +52 -0
- data/test/functional/host/subscription/unregister_test.rb +37 -0
- data/test/functional/host/traces/list_test.rb +37 -0
- data/test/functional/host/traces/resolve_test.rb +31 -0
- data/test/functional/host_collection/add_host_test.rb +90 -0
- data/test/functional/host_collection/content_api_expectations.rb +35 -0
- data/test/functional/host_collection/content_install_test.rb +62 -0
- data/test/functional/host_collection/content_remove_test.rb +37 -0
- data/test/functional/host_collection/content_update_test.rb +37 -0
- data/test/functional/host_collection/copy_test.rb +64 -0
- data/test/functional/host_collection/create_test.rb +54 -0
- data/test/functional/host_collection/delete_test.rb +57 -0
- data/test/functional/host_collection/hosts_test.rb +39 -0
- data/test/functional/host_collection/info_test.rb +57 -0
- data/test/functional/host_collection/list_test.rb +63 -0
- data/test/functional/host_collection/remove_host_test.rb +90 -0
- data/test/functional/host_collection/update_test.rb +57 -0
- data/test/functional/hostgroup/create_test.rb +112 -0
- data/test/functional/hostgroup/data/hostgroup.json +50 -0
- data/test/functional/hostgroup/info_test.rb +33 -0
- data/test/functional/hostgroup/update_test.rb +120 -0
- data/test/functional/lifecycle_environment/create_test.rb +14 -0
- data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
- data/test/functional/lifecycle_environment/list_test.rb +38 -0
- data/test/functional/lifecycle_environment/update_test.rb +14 -0
- data/test/functional/local_helper_test.rb +30 -0
- data/test/functional/module_stream/info_test.rb +58 -0
- data/test/functional/module_stream/list_test.rb +53 -0
- data/test/functional/organization/delete_test.rb +26 -0
- data/test/functional/organization/info_test.rb +22 -0
- data/test/functional/organization/organization_helpers.rb +10 -0
- data/test/functional/package/list_test.rb +158 -0
- data/test/functional/package_group/list_test.rb +38 -0
- data/test/functional/ping_test.rb +59 -0
- data/test/functional/product/create_test.rb +54 -0
- data/test/functional/product/delete_test.rb +41 -0
- data/test/functional/product/info_test.rb +33 -0
- data/test/functional/product/list_test.rb +58 -0
- data/test/functional/product/product_helpers.rb +24 -0
- data/test/functional/product/remove_sync_plan_test.rb +35 -0
- data/test/functional/product/set_sync_plan_test.rb +49 -0
- data/test/functional/product/update_proxy.rb +48 -0
- data/test/functional/product/update_test.rb +46 -0
- data/test/functional/repository/create_test.rb +21 -0
- data/test/functional/repository/delete_test.rb +95 -0
- data/test/functional/repository/info_test.rb +156 -0
- data/test/functional/repository/list_test.rb +68 -0
- data/test/functional/repository/remove_content_test.rb +108 -0
- data/test/functional/repository/repository_helpers.rb +18 -0
- data/test/functional/repository/synchronize_test.rb +57 -0
- data/test/functional/repository/update_test.rb +149 -0
- data/test/functional/repository/upload_test.rb +345 -0
- data/test/functional/repository_set/available_repositories_test.rb +18 -0
- data/test/functional/repository_set/disable_test.rb +42 -0
- data/test/functional/repository_set/enable_test.rb +42 -0
- data/test/functional/repository_set/info_test.rb +17 -0
- data/test/functional/repository_set/list_test.rb +18 -0
- data/test/functional/repository_set/repository_set_helpers.rb +20 -0
- data/test/functional/search_helpers.rb +17 -0
- data/test/functional/simple_content_access/disable_test.rb +48 -0
- data/test/functional/simple_content_access/enable_test.rb +46 -0
- data/test/functional/srpm/list_test.rb +92 -0
- data/test/functional/subscription/list_test.rb +86 -0
- data/test/functional/sync_plan/create_test.rb +60 -0
- data/test/functional/sync_plan/delete_test.rb +46 -0
- data/test/functional/sync_plan/info_test.rb +37 -0
- data/test/functional/sync_plan/list_test.rb +31 -0
- data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
- data/test/functional/sync_plan/update_test.rb +44 -0
- data/test/functional/test_helper.rb +24 -0
- data/test/task_helper.rb +7 -0
- data/test/test_helper.rb +38 -0
- data/test/unit/id_name_options_validator_test.rb +96 -0
- data/test/unit/id_resolver_test.rb +58 -0
- data/test/unit/messages_test.rb +7 -0
- data/test/unit/search_options_creators_test.rb +145 -0
- metadata +388 -6
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative '../repository/repository_helpers'
|
3
|
+
require_relative '../product/product_helpers'
|
4
|
+
require_relative '../organization/organization_helpers'
|
5
|
+
require 'hammer_cli_katello/package'
|
6
|
+
require 'hammer_cli_katello/srpm'
|
7
|
+
|
8
|
+
module HammerCLIKatello
|
9
|
+
describe PackageCommand::ListCommand do
|
10
|
+
include OrganizationHelpers
|
11
|
+
include RepositoryHelpers
|
12
|
+
include ProductHelpers
|
13
|
+
|
14
|
+
it 'allows minimal options' do
|
15
|
+
api_expects(:srpms, :index)
|
16
|
+
|
17
|
+
run_cmd(%w(srpm list))
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'repository options' do
|
21
|
+
it 'may be specified by ID' do
|
22
|
+
api_expects(:srpms, :index).with_params('repository_id' => 1)
|
23
|
+
|
24
|
+
run_cmd(%w(srpm list --repository-id 1))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'require product ID when given repository name' do
|
28
|
+
api_expects_no_call
|
29
|
+
|
30
|
+
r = run_cmd(%w(srpm list --repository repo1))
|
31
|
+
assert(r.err.include?("--product-id, --product is required"), "Invalid error message")
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'may be specified by name and product ID' do
|
35
|
+
expect_repository_search(2, 'repo1', 1)
|
36
|
+
|
37
|
+
api_expects(:srpms, :index).with_params('repository_id' => 1)
|
38
|
+
|
39
|
+
run_cmd(%w(srpm list --repository repo1 --product-id 2))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'organization options' do
|
44
|
+
it 'may be specified by ID' do
|
45
|
+
api_expects(:srpms, :index).with_params('organization_id' => 1)
|
46
|
+
|
47
|
+
run_cmd(%w(srpm list --organization-id 1))
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'may be specified by name' do
|
51
|
+
expect_organization_search('org3', 1)
|
52
|
+
api_expects(:srpms, :index).with_params('organization_id' => 1)
|
53
|
+
|
54
|
+
run_cmd(%w(srpm list --organization org3))
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'may be specified by label' do
|
58
|
+
expect_organization_search('org3', 1, field: 'label')
|
59
|
+
api_expects(:srpms, :index).with_params('organization_id' => 1)
|
60
|
+
|
61
|
+
run_cmd(%w(srpm list --organization-label org3))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'content-view options' do
|
66
|
+
it 'may be specified by ID' do
|
67
|
+
api_expects(:content_view_versions, :index)
|
68
|
+
.with_params('content_view_id' => 1, 'version' => '2.1')
|
69
|
+
.returns(index_response([{'id' => 5}]))
|
70
|
+
api_expects(:srpms, :index).with_params('content_view_version_id' => 5)
|
71
|
+
|
72
|
+
run_cmd(%w(srpm list --content-view-id 1 --content-view-version 2.1))
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'requires organization ID when given content view name' do
|
76
|
+
api_expects_no_call
|
77
|
+
|
78
|
+
r = run_cmd(%w(srpm list --content-view cv1 --content-view-version 2.1))
|
79
|
+
expected_error = "--organization-id, --organization, --organization-label is required"
|
80
|
+
assert(r.err.include?(expected_error), "Invalid error message")
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'requires content view ID when given content view version number' do
|
84
|
+
api_expects_no_call
|
85
|
+
|
86
|
+
r = run_cmd(%w(srpm list --content-view-version cvv1))
|
87
|
+
assert(r.err.include?("--content-view-id, --content-view is required"),
|
88
|
+
"Invalid error message")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/subscription'
|
3
|
+
|
4
|
+
module HammerCLIKatello
|
5
|
+
describe SubscriptionCommand::ListCommand do
|
6
|
+
before do
|
7
|
+
@cmd = %w(subscription list)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:org_id) { 1 }
|
11
|
+
|
12
|
+
it "returns the correct subscription type" do
|
13
|
+
cmd = SubscriptionCommand::ListCommand.new({})
|
14
|
+
assert_equal("Physical", cmd.get_subscription_type("virt_only" => false))
|
15
|
+
|
16
|
+
hostname = "boo.com"
|
17
|
+
with_hostname = cmd.get_subscription_type("virt_only" => true, "host" => {"name" => hostname})
|
18
|
+
assert(with_hostname.include?(hostname))
|
19
|
+
|
20
|
+
assert_equal("Temporary",
|
21
|
+
cmd.get_subscription_type("virt_only" => true, "unmapper_guest" => true))
|
22
|
+
|
23
|
+
assert_equal("Virtual",
|
24
|
+
cmd.get_subscription_type("virt_only" => true))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "lists an organizations subscriptions" do
|
28
|
+
params = ["--organization-id=#{org_id}"]
|
29
|
+
|
30
|
+
ex = api_expects(:subscriptions, :index, 'Subscription list') do |par|
|
31
|
+
par['organization_id'] == org_id
|
32
|
+
end
|
33
|
+
|
34
|
+
ex.returns(index_response([]))
|
35
|
+
|
36
|
+
result = run_cmd(@cmd + params)
|
37
|
+
|
38
|
+
fields = ['ID', 'UUID', 'NAME', 'TYPE', 'CONTRACT', 'ACCOUNT', 'SUPPORT',
|
39
|
+
'START DATE', 'END DATE', 'QUANTITY', 'CONSUMED']
|
40
|
+
expected_result = success_result(IndexMatcher.new([fields, []]))
|
41
|
+
assert_cmd(expected_result, result)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows organization name' do
|
45
|
+
api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" }
|
46
|
+
.returns(index_response([{'id' => 1}]))
|
47
|
+
|
48
|
+
api_expects(:subscriptions, :index) { |par| par['organization_id'].to_i == 1 }
|
49
|
+
|
50
|
+
run_cmd(%w(subscription list --organization org1))
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'allows organization label' do
|
54
|
+
api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" }
|
55
|
+
.returns(index_response([{'id' => 1}]))
|
56
|
+
|
57
|
+
api_expects(:subscriptions, :index) { |par| par['organization_id'].to_i == 1 }
|
58
|
+
|
59
|
+
run_cmd(%w(subscription list --organization-label org1))
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'allows host id' do
|
63
|
+
api_expects(:subscriptions, :index) { |par| par['host_id'] == 1 }
|
64
|
+
run_cmd(%w(subscription list --organization-id 1 --host-id 1))
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'allows host name' do
|
68
|
+
api_expects(:hosts, :index) { |par| par[:search] == "name = \"host1\"" }
|
69
|
+
.returns(index_response([{'id' => 1}]))
|
70
|
+
api_expects(:subscriptions, :index) { |par| par['host_id'] == 1 }
|
71
|
+
run_cmd(%w(subscription list --organization-id 1 --host host1))
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'allows activation key id' do
|
75
|
+
api_expects(:subscriptions, :index) { |par| par['activation_key_id'] == 1 }
|
76
|
+
run_cmd(%w(subscription list --organization-id 1 --activation-key-id 1))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'allows activation key name' do
|
80
|
+
api_expects(:activation_keys, :index) { |par| par['name'] == "ak1" }
|
81
|
+
.returns(index_response([{'id' => 1}]))
|
82
|
+
api_expects(:subscriptions, :index) { |par| par['activation_key_id'] == 1 }
|
83
|
+
run_cmd(%w(subscription list --organization-id 1 --activation-key ak1))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe "create sync plan" do
|
4
|
+
let(:org_id) { 1 }
|
5
|
+
let(:name) { "sync_plan1" }
|
6
|
+
let(:hourly) { "hourly" }
|
7
|
+
let(:custom) { "custom cron" }
|
8
|
+
let(:cron) { "10 * * * *" }
|
9
|
+
let(:date) { "2018-09-08T00:00:00+00:00" }
|
10
|
+
|
11
|
+
it 'with organization ID,name,interval,date and enabled' do
|
12
|
+
api_expects(:sync_plans, :create, 'create a sync plan').
|
13
|
+
with_params('organization_id' => org_id,
|
14
|
+
'name' => name,
|
15
|
+
'interval' => hourly,
|
16
|
+
'sync_date' => date,
|
17
|
+
'enabled' => true)
|
18
|
+
command = %W(sync-plan create --organization-id #{org_id} --name #{name}
|
19
|
+
--interval #{hourly} --enabled 1 --sync-date #{date})
|
20
|
+
assert_equal(0, run_cmd(command).exit_code)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'with custom cron' do
|
24
|
+
api_expects(:sync_plans, :create, 'create a sync plan').
|
25
|
+
with_params('organization_id' => org_id,
|
26
|
+
'name' => name,
|
27
|
+
'interval' => custom,
|
28
|
+
'cron_expression' => cron,
|
29
|
+
'sync_date' => date,
|
30
|
+
'enabled' => true)
|
31
|
+
# end
|
32
|
+
command = %W(sync-plan create --organization-id #{org_id} --name #{name} --interval #{custom}
|
33
|
+
--cron-expression #{cron} --enabled 1 --sync-date #{date})
|
34
|
+
assert_equal(0, run_cmd(command).exit_code)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'fails without organization-id' do
|
38
|
+
command = %w(sync-plan create --name #{name}
|
39
|
+
--interval #{hourly} --enabled 1 --sync-date #{date})
|
40
|
+
refute_equal(0, run_cmd(command).exit_code)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'fails without name' do
|
44
|
+
command = %w(sync-plan create --organization-id #{org_id}
|
45
|
+
--interval #{hourly} --enabled 1 --sync-date #{date})
|
46
|
+
refute_equal(0, run_cmd(command).err)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'fails without interval' do
|
50
|
+
command = %w(sync-plan create --organization-id #{org_id} --name #{name}
|
51
|
+
--enabled 1 --sync-date #{date})
|
52
|
+
refute_equal(0, run_cmd(command).exit_code)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'fails without enabled' do
|
56
|
+
command = %w(sync-plan create --organization-id #{org_id} --name #{name}
|
57
|
+
--interval #{hourly} --sync-date #{date})
|
58
|
+
refute_equal(0, run_cmd(command).exit_code)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative 'sync_plan_helpers'
|
3
|
+
require_relative '../organization/organization_helpers'
|
4
|
+
|
5
|
+
describe 'delete a sync plan' do
|
6
|
+
include OrganizationHelpers
|
7
|
+
include SyncPlanHelpers
|
8
|
+
|
9
|
+
let(:org_id) { 1 }
|
10
|
+
let(:id) { 1 }
|
11
|
+
let(:name) { "sync_plan1" }
|
12
|
+
let(:org_name) { "org1" }
|
13
|
+
|
14
|
+
it 'by organization ID and sync plan id' do
|
15
|
+
api_expects(:sync_plans, :destroy, 'delete a sync plan').
|
16
|
+
with_params('organization_id' => org_id,
|
17
|
+
'id' => id)
|
18
|
+
command = %W(sync-plan delete --organization-id #{org_id} --id #{id})
|
19
|
+
assert_equal(0, run_cmd(command).exit_code)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'by organization ID and sync plan name' do
|
23
|
+
expect_sync_plan_search(1, 'sync_plan1', 1)
|
24
|
+
api_expects(:sync_plans, :destroy, 'delete a sync plan').
|
25
|
+
with_params('id' => id)
|
26
|
+
command = %W(sync-plan delete --organization-id #{org_id} --name #{name})
|
27
|
+
assert_equal(0, run_cmd(command).exit_code)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'by organization name and sync plan name' do
|
31
|
+
expect_organization_search('org1', 1)
|
32
|
+
expect_sync_plan_search(1, 'sync_plan1', 1)
|
33
|
+
api_expects(:sync_plans, :destroy, 'delete a sync plan').
|
34
|
+
with_params('id' => id)
|
35
|
+
command = %W(sync-plan delete --organization #{org_name} --name #{name})
|
36
|
+
assert_equal(0, run_cmd(command).exit_code)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'by organization name and sync plan id' do
|
40
|
+
expect_organization_search(org_name, org_id)
|
41
|
+
api_expects(:sync_plans, :destroy, 'delete a sync plan').
|
42
|
+
with_params('id' => id)
|
43
|
+
command = %W(sync-plan delete --organization #{org_name} --id #{id})
|
44
|
+
assert_equal(0, run_cmd(command).exit_code)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/sync_plan'
|
3
|
+
require_relative 'sync_plan_helpers'
|
4
|
+
require_relative '../organization/organization_helpers'
|
5
|
+
module HammerCLIKatello
|
6
|
+
describe SyncPlan::InfoCommand do
|
7
|
+
include OrganizationHelpers
|
8
|
+
include SyncPlanHelpers
|
9
|
+
|
10
|
+
it 'allows ID' do
|
11
|
+
api_expects(:sync_plans, :show).with_params('id' => 1)
|
12
|
+
|
13
|
+
run_cmd(%w(sync-plan info --id 1))
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'allows organization id and sync plan name' do
|
17
|
+
org_id = 1
|
18
|
+
name = "SyncPlan1"
|
19
|
+
id = 100
|
20
|
+
expect_sync_plan_search(org_id, name, id)
|
21
|
+
api_expects(:sync_plans, :show).with_params('id' => id)
|
22
|
+
run_cmd("sync-plan info --organization-id #{org_id} --name #{name}".split)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'allows organization name and sync plan name' do
|
26
|
+
org_id = 1
|
27
|
+
org_label = "org"
|
28
|
+
name = "SyncPlan1"
|
29
|
+
id = 100
|
30
|
+
|
31
|
+
expect_organization_search(org_label, org_id, field: 'label')
|
32
|
+
expect_sync_plan_search(org_id, name, id)
|
33
|
+
api_expects(:sync_plans, :show).with_params('id' => id)
|
34
|
+
run_cmd("sync-plan info --organization-label #{org_label} --name #{name}".split)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/sync_plan'
|
3
|
+
require_relative 'sync_plan_helpers'
|
4
|
+
require_relative '../organization/organization_helpers'
|
5
|
+
|
6
|
+
module HammerCLIKatello
|
7
|
+
describe SyncPlan::ListCommand do
|
8
|
+
include SyncPlanHelpers
|
9
|
+
include OrganizationHelpers
|
10
|
+
|
11
|
+
it 'allows minimal options' do
|
12
|
+
expect_sync_plan_search(1, nil, nil)
|
13
|
+
|
14
|
+
run_cmd(%w(sync-plan list --organization-id 1))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'allows org name' do
|
18
|
+
expect_organization_search('org1', 1)
|
19
|
+
expect_sync_plan_search(1, nil, nil)
|
20
|
+
|
21
|
+
run_cmd(%w(sync-plan list --organization org1))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'allows org label' do
|
25
|
+
expect_organization_search('org1', 1, field: 'label')
|
26
|
+
expect_sync_plan_search(1, nil, nil)
|
27
|
+
|
28
|
+
run_cmd(%w(sync-plan list --organization-label org1))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative 'sync_plan_helpers'
|
3
|
+
require_relative '../organization/organization_helpers'
|
4
|
+
|
5
|
+
describe 'update a sync plan' do
|
6
|
+
include OrganizationHelpers
|
7
|
+
include SyncPlanHelpers
|
8
|
+
|
9
|
+
let(:org_id) { 1 }
|
10
|
+
let(:id) { 1 }
|
11
|
+
let(:name) { "sync_plan1" }
|
12
|
+
let(:org_name) { "org1" }
|
13
|
+
let(:desc) { "New Description" }
|
14
|
+
|
15
|
+
it 'with organization id and sync plan ID' do
|
16
|
+
api_expects(:sync_plans, :update, 'update a sync plan').
|
17
|
+
with_params('description' => desc,
|
18
|
+
'id' => id)
|
19
|
+
command = %W(sync-plan update --organization-id #{org_id} --id #{id}
|
20
|
+
--description #{desc})
|
21
|
+
assert_equal(0, run_cmd(command).exit_code)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'with organization ID and sync plan name' do
|
25
|
+
expect_sync_plan_search(org_id, name, id)
|
26
|
+
api_expects(:sync_plans, :update, 'update a sync plan').
|
27
|
+
with_params('description' => desc,
|
28
|
+
'id' => id)
|
29
|
+
command = %W(sync-plan update --organization-id #{org_id} --name #{name}
|
30
|
+
--description #{desc})
|
31
|
+
assert_equal(0, run_cmd(command).exit_code)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'with organization name and sync plan name' do
|
35
|
+
expect_organization_search(org_name, org_id)
|
36
|
+
expect_sync_plan_search(org_id, name, id)
|
37
|
+
api_expects(:sync_plans, :update, 'update a sync plan').
|
38
|
+
with_params('description' => desc,
|
39
|
+
'id' => id)
|
40
|
+
command = %W(sync-plan update --organization #{org_name} --name #{name}
|
41
|
+
--description #{desc})
|
42
|
+
assert_equal(0, run_cmd(command).exit_code)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
+
|
3
|
+
require 'hammer_cli/testing/output_matchers'
|
4
|
+
require 'hammer_cli/testing/command_assertions'
|
5
|
+
require 'hammer_cli/testing/data_helpers'
|
6
|
+
require 'hammer_cli_foreman/testing/api_expectations'
|
7
|
+
|
8
|
+
include HammerCLI::Testing::OutputMatchers
|
9
|
+
include HammerCLI::Testing::CommandAssertions
|
10
|
+
include HammerCLI::Testing::DataHelpers
|
11
|
+
include HammerCLIForeman::Testing::APIExpectations
|
12
|
+
|
13
|
+
def assert_success(command_run_result)
|
14
|
+
assert command_run_result.exit_code.zero?,
|
15
|
+
"Nonzero exit code (#{command_run_result.exit_code}): #{command_run_result.err}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_failure(command_run_result, msg = nil)
|
19
|
+
assert !command_run_result.exit_code.zero?, "Success exit code (0) when expecting failure"
|
20
|
+
if msg
|
21
|
+
assert command_run_result.err[msg],
|
22
|
+
"Actual:\n#{command_run_result.err}\nExpected:\n#{msg.inspect}"
|
23
|
+
end
|
24
|
+
end
|
data/test/task_helper.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
if RUBY_VERSION > "2.2"
|
2
|
+
# Coverage - Keep these two lines at the top of this file
|
3
|
+
require 'simplecov'
|
4
|
+
require 'coveralls'
|
5
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
6
|
+
SimpleCov.start do
|
7
|
+
minimum_coverage 70
|
8
|
+
maximum_coverage_drop 0.1
|
9
|
+
track_files "lib/**/*.rb"
|
10
|
+
add_filter '/test/'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require File.join(File.dirname(__FILE__), './task_helper.rb')
|
15
|
+
require 'minitest/autorun'
|
16
|
+
require 'minitest/spec'
|
17
|
+
require 'mocha/minitest'
|
18
|
+
require 'hammer_cli'
|
19
|
+
|
20
|
+
KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.1')
|
21
|
+
|
22
|
+
if HammerCLI.context[:api_connection]
|
23
|
+
HammerCLI.context[:api_connection].create('foreman') do
|
24
|
+
HammerCLI::Apipie::ApiConnection.new(
|
25
|
+
:apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s,
|
26
|
+
:apidoc_cache_name => 'foreman_api',
|
27
|
+
:dry_run => true
|
28
|
+
)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
HammerCLIForeman.stubs(:resource_config).returns(
|
32
|
+
:apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s,
|
33
|
+
:apidoc_cache_name => 'foreman_api',
|
34
|
+
:dry_run => true
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'hammer_cli_katello'
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/id_name_options_validator'
|
3
|
+
|
4
|
+
module HammerCLIKatello
|
5
|
+
describe IdNameOptionsValidator do
|
6
|
+
before(:each) do
|
7
|
+
@cmd = Object.new
|
8
|
+
@cmd.extend(IdNameOptionsValidator)
|
9
|
+
@cmd.class.send(:define_method, :validate_options) do |*_args, &block|
|
10
|
+
block.call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#validate_id_or_name_with_parent' do
|
15
|
+
it 'accepts no record name and validates id, name, and parent opts' do
|
16
|
+
any_stub = stub(:required => true)
|
17
|
+
option_stub = stub(:exist? => true)
|
18
|
+
@cmd.stubs(:option).returns(option_stub)
|
19
|
+
|
20
|
+
@cmd.expects(:any).with('option_id', 'option_name').returns(any_stub)
|
21
|
+
@cmd.expects(:any).with('option_organization_id',
|
22
|
+
'option_organization_name',
|
23
|
+
'option_organization_label'
|
24
|
+
).returns(any_stub)
|
25
|
+
|
26
|
+
@cmd.validate_id_or_name_with_parent
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts content view as a record name' do
|
30
|
+
any_stub = stub(:required => true)
|
31
|
+
option_stub = stub(:exist? => true)
|
32
|
+
@cmd.stubs(:option).returns(option_stub)
|
33
|
+
|
34
|
+
@cmd.expects(:any).with('option_content_view_id',
|
35
|
+
'option_content_view_name'
|
36
|
+
).returns(any_stub)
|
37
|
+
@cmd.expects(:any).with('option_organization_id',
|
38
|
+
'option_organization_name',
|
39
|
+
'option_organization_label'
|
40
|
+
).returns(any_stub)
|
41
|
+
|
42
|
+
@cmd.validate_id_or_name_with_parent(:content_view)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not validate org options if the name opt is not used' do
|
46
|
+
any_stub = stub(:required => true)
|
47
|
+
option_stub = stub(:exist? => false) # --name was not supplied
|
48
|
+
@cmd.stubs(:option).returns(option_stub)
|
49
|
+
|
50
|
+
@cmd.expects(:any).at_most_once.returns(any_stub)
|
51
|
+
|
52
|
+
@cmd.validate_id_or_name_with_parent
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not validate name or id if required is false' do
|
56
|
+
any_stub = stub(:required => true)
|
57
|
+
option_stub = stub(:exist? => true)
|
58
|
+
@cmd.stubs(:option).returns(option_stub)
|
59
|
+
|
60
|
+
@cmd.expects(:any).with('option_organization_id',
|
61
|
+
'option_organization_name',
|
62
|
+
'option_organization_label'
|
63
|
+
).returns(any_stub)
|
64
|
+
|
65
|
+
@cmd.validate_id_or_name_with_parent(required: false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'accepts a hash of fields for the parent' do
|
69
|
+
any_stub = stub(:required => true)
|
70
|
+
option_stub = stub(:exist? => true)
|
71
|
+
@cmd.stubs(:option).returns(option_stub)
|
72
|
+
|
73
|
+
@cmd.expects(:any).with('option_id', 'option_name').returns(any_stub)
|
74
|
+
@cmd.expects(:any).with('option_product_test').returns(any_stub)
|
75
|
+
|
76
|
+
@cmd.validate_id_or_name_with_parent(parent: {:product => ['test']})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#validate_id_or_name' do
|
81
|
+
it 'validates that id or name is required' do
|
82
|
+
any_stub = stub(:required => true)
|
83
|
+
@cmd.expects(:any).with('option_id', 'option_name').returns(any_stub)
|
84
|
+
@cmd.validate_id_or_name
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'accepts a custom record name' do
|
88
|
+
any_stub = stub(:required => true)
|
89
|
+
@cmd.expects(:any).with('option_content_view_id',
|
90
|
+
'option_content_view_name'
|
91
|
+
).returns(any_stub)
|
92
|
+
@cmd.validate_id_or_name(:content_view)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/id_resolver'
|
3
|
+
|
4
|
+
module HammerCLIKatello
|
5
|
+
describe IdResolver do
|
6
|
+
let(:api) { mock('api') }
|
7
|
+
let(:searchables) { mock('searchables') }
|
8
|
+
let(:id_resolver) { IdResolver.new api, searchables }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
api.stubs(:resources).returns([])
|
12
|
+
api.stubs(:resource).returns([])
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#repository_ids' do
|
16
|
+
it 'accepts nil repository_names' do
|
17
|
+
id_resolver.stubs(:find_resources).returns([])
|
18
|
+
id_resolver.repository_ids({}).must_equal(nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'accepts repository_ids' do
|
22
|
+
id_resolver.repository_ids(
|
23
|
+
'option_repository_ids' => [1, 2]
|
24
|
+
).must_equal [1, 2]
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts repository_names' do
|
28
|
+
id_resolver.stubs(:find_resources).returns(
|
29
|
+
[
|
30
|
+
{'id' => 1, 'name' => 'repo1'},
|
31
|
+
{'id' => 2, 'name' => 'repo2'}
|
32
|
+
]
|
33
|
+
)
|
34
|
+
id_resolver.repository_ids(
|
35
|
+
'option_names' => %w(repo1 repo2)
|
36
|
+
).must_equal [1, 2]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#repository_id' do
|
41
|
+
it 'resolves ID from name' do
|
42
|
+
id_resolver.expects(:find_resource).with(:repositories, name: 'repo1').returns('id' => 5)
|
43
|
+
options = {name: 'repo1'}
|
44
|
+
id_resolver.repository_id(options).must_equal 5
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#content_view_version_id' do
|
49
|
+
it 'resolves ID from version number' do
|
50
|
+
options = {'option_version' => '2.0', 'option_content_view_id' => 4}
|
51
|
+
id_resolver.expects(:find_resources)
|
52
|
+
.with(:content_view_versions, options)
|
53
|
+
.returns(['id' => 5])
|
54
|
+
id_resolver.content_view_version_id(options).must_equal 5
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|