knife-ionoscloud 5.0.0.beta.1
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 +7 -0
- data/.gitbook.yaml +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +54 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +51 -0
- data/.github/workflows/ci.yml +38 -0
- data/.github/workflows/publish.yml +58 -0
- data/.gitignore +26 -0
- data/.rubocop.yml +148 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +201 -0
- data/Rakefile +7 -0
- data/docs/README.md +67 -0
- data/docs/changelog.md +1 -0
- data/docs/docs_generator.rb +107 -0
- data/docs/subcommands/backupunit_create.md +38 -0
- data/docs/subcommands/backupunit_delete.md +26 -0
- data/docs/subcommands/backupunit_list.md +26 -0
- data/docs/subcommands/backupunit_ssourl.md +30 -0
- data/docs/subcommands/composite_server_create.md +97 -0
- data/docs/subcommands/contract_list.md +26 -0
- data/docs/subcommands/datacenter_create.md +41 -0
- data/docs/subcommands/datacenter_delete.md +26 -0
- data/docs/subcommands/datacenter_list.md +26 -0
- data/docs/subcommands/firewall_create.md +65 -0
- data/docs/subcommands/firewall_delete.md +38 -0
- data/docs/subcommands/firewall_list.md +38 -0
- data/docs/subcommands/group_create.md +48 -0
- data/docs/subcommands/group_delete.md +26 -0
- data/docs/subcommands/group_get.md +30 -0
- data/docs/subcommands/group_list.md +29 -0
- data/docs/subcommands/group_user_add.md +30 -0
- data/docs/subcommands/group_user_remove.md +30 -0
- data/docs/subcommands/image_list.md +26 -0
- data/docs/subcommands/ipblock_create.md +37 -0
- data/docs/subcommands/ipblock_delete.md +26 -0
- data/docs/subcommands/ipblock_list.md +26 -0
- data/docs/subcommands/ipfailover_add.md +46 -0
- data/docs/subcommands/ipfailover_remove.md +42 -0
- data/docs/subcommands/k8s_create.md +39 -0
- data/docs/subcommands/k8s_delete.md +26 -0
- data/docs/subcommands/k8s_list.md +26 -0
- data/docs/subcommands/kubeconfig_get.md +30 -0
- data/docs/subcommands/label_add.md +45 -0
- data/docs/subcommands/label_list.md +35 -0
- data/docs/subcommands/label_remove.md +37 -0
- data/docs/subcommands/lan_create.md +36 -0
- data/docs/subcommands/lan_delete.md +30 -0
- data/docs/subcommands/lan_list.md +30 -0
- data/docs/subcommands/loadbalancer_create.md +43 -0
- data/docs/subcommands/loadbalancer_delete.md +30 -0
- data/docs/subcommands/loadbalancer_get.md +34 -0
- data/docs/subcommands/loadbalancer_list.md +30 -0
- data/docs/subcommands/loadbalancer_nic_add.md +34 -0
- data/docs/subcommands/loadbalancer_nic_remove.md +34 -0
- data/docs/subcommands/location_list.md +26 -0
- data/docs/subcommands/nic_create.md +51 -0
- data/docs/subcommands/nic_delete.md +34 -0
- data/docs/subcommands/nic_list.md +34 -0
- data/docs/subcommands/node_delete.md +34 -0
- data/docs/subcommands/node_list.md +34 -0
- data/docs/subcommands/node_replace.md +36 -0
- data/docs/subcommands/nodepool_create.md +87 -0
- data/docs/subcommands/nodepool_delete.md +30 -0
- data/docs/subcommands/nodepool_list.md +30 -0
- data/docs/subcommands/pcc_create.md +38 -0
- data/docs/subcommands/pcc_delete.md +26 -0
- data/docs/subcommands/pcc_list.md +26 -0
- data/docs/subcommands/request_list.md +32 -0
- data/docs/subcommands/request_status.md +30 -0
- data/docs/subcommands/request_wait.md +30 -0
- data/docs/subcommands/resource_list.md +34 -0
- data/docs/subcommands/s3key_create.md +30 -0
- data/docs/subcommands/s3key_delete.md +30 -0
- data/docs/subcommands/s3key_list.md +30 -0
- data/docs/subcommands/server_create.md +55 -0
- data/docs/subcommands/server_delete.md +32 -0
- data/docs/subcommands/server_list.md +30 -0
- data/docs/subcommands/server_reboot.md +30 -0
- data/docs/subcommands/server_start.md +30 -0
- data/docs/subcommands/server_stop.md +30 -0
- data/docs/subcommands/share_create.md +40 -0
- data/docs/subcommands/share_delete.md +30 -0
- data/docs/subcommands/share_list.md +30 -0
- data/docs/subcommands/snapshot_create.md +34 -0
- data/docs/subcommands/snapshot_delete.md +26 -0
- data/docs/subcommands/snapshot_list.md +26 -0
- data/docs/subcommands/snapshot_restore.md +38 -0
- data/docs/subcommands/user_create.md +49 -0
- data/docs/subcommands/user_delete.md +26 -0
- data/docs/subcommands/user_list.md +29 -0
- data/docs/subcommands/user_ssourl.md +30 -0
- data/docs/subcommands/volume_attach.md +34 -0
- data/docs/subcommands/volume_create.md +63 -0
- data/docs/subcommands/volume_delete.md +30 -0
- data/docs/subcommands/volume_detach.md +36 -0
- data/docs/subcommands/volume_list.md +33 -0
- data/docs/summary.md +89 -0
- data/docs/templates/subcommand_doc.mustache +26 -0
- data/docs/templates/summary.mustache +10 -0
- data/knife-ionoscloud.gemspec +27 -0
- data/lib/chef/knife/ionoscloud_backupunit_create.rb +63 -0
- data/lib/chef/knife/ionoscloud_backupunit_delete.rb +55 -0
- data/lib/chef/knife/ionoscloud_backupunit_list.rb +41 -0
- data/lib/chef/knife/ionoscloud_backupunit_ssourl.rb +39 -0
- data/lib/chef/knife/ionoscloud_base.rb +76 -0
- data/lib/chef/knife/ionoscloud_composite_server_create.rb +217 -0
- data/lib/chef/knife/ionoscloud_contract_list.rb +50 -0
- data/lib/chef/knife/ionoscloud_datacenter_create.rb +66 -0
- data/lib/chef/knife/ionoscloud_datacenter_delete.rb +56 -0
- data/lib/chef/knife/ionoscloud_datacenter_list.rb +50 -0
- data/lib/chef/knife/ionoscloud_firewall_create.rb +135 -0
- data/lib/chef/knife/ionoscloud_firewall_delete.rb +76 -0
- data/lib/chef/knife/ionoscloud_firewall_list.rb +72 -0
- data/lib/chef/knife/ionoscloud_group_create.rb +89 -0
- data/lib/chef/knife/ionoscloud_group_delete.rb +61 -0
- data/lib/chef/knife/ionoscloud_group_get.rb +46 -0
- data/lib/chef/knife/ionoscloud_group_list.rb +62 -0
- data/lib/chef/knife/ionoscloud_group_user_add.rb +72 -0
- data/lib/chef/knife/ionoscloud_group_user_remove.rb +72 -0
- data/lib/chef/knife/ionoscloud_image_list.rb +47 -0
- data/lib/chef/knife/ionoscloud_ipblock_create.rb +63 -0
- data/lib/chef/knife/ionoscloud_ipblock_delete.rb +50 -0
- data/lib/chef/knife/ionoscloud_ipblock_list.rb +42 -0
- data/lib/chef/knife/ionoscloud_ipfailover_add.rb +76 -0
- data/lib/chef/knife/ionoscloud_ipfailover_remove.rb +76 -0
- data/lib/chef/knife/ionoscloud_k8s_create.rb +79 -0
- data/lib/chef/knife/ionoscloud_k8s_delete.rb +67 -0
- data/lib/chef/knife/ionoscloud_k8s_list.rb +45 -0
- data/lib/chef/knife/ionoscloud_kubeconfig_get.rb +37 -0
- data/lib/chef/knife/ionoscloud_label_add.rb +84 -0
- data/lib/chef/knife/ionoscloud_label_list.rb +83 -0
- data/lib/chef/knife/ionoscloud_label_remove.rb +77 -0
- data/lib/chef/knife/ionoscloud_lan_create.rb +69 -0
- data/lib/chef/knife/ionoscloud_lan_delete.rb +54 -0
- data/lib/chef/knife/ionoscloud_lan_list.rb +46 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_create.rb +87 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_delete.rb +68 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_get.rb +51 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_list.rb +50 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_nic_add.rb +75 -0
- data/lib/chef/knife/ionoscloud_loadbalancer_nic_remove.rb +76 -0
- data/lib/chef/knife/ionoscloud_location_list.rb +38 -0
- data/lib/chef/knife/ionoscloud_nic_create.rb +104 -0
- data/lib/chef/knife/ionoscloud_nic_delete.rb +62 -0
- data/lib/chef/knife/ionoscloud_nic_list.rb +57 -0
- data/lib/chef/knife/ionoscloud_node_delete.rb +65 -0
- data/lib/chef/knife/ionoscloud_node_list.rb +55 -0
- data/lib/chef/knife/ionoscloud_node_replace.rb +54 -0
- data/lib/chef/knife/ionoscloud_nodepool_create.rb +163 -0
- data/lib/chef/knife/ionoscloud_nodepool_delete.rb +60 -0
- data/lib/chef/knife/ionoscloud_nodepool_list.rb +51 -0
- data/lib/chef/knife/ionoscloud_pcc_create.rb +68 -0
- data/lib/chef/knife/ionoscloud_pcc_delete.rb +57 -0
- data/lib/chef/knife/ionoscloud_pcc_list.rb +41 -0
- data/lib/chef/knife/ionoscloud_request_list.rb +94 -0
- data/lib/chef/knife/ionoscloud_request_status.rb +37 -0
- data/lib/chef/knife/ionoscloud_request_wait.rb +41 -0
- data/lib/chef/knife/ionoscloud_resource_list.rb +81 -0
- data/lib/chef/knife/ionoscloud_s3key_create.rb +45 -0
- data/lib/chef/knife/ionoscloud_s3key_delete.rb +57 -0
- data/lib/chef/knife/ionoscloud_s3key_list.rb +46 -0
- data/lib/chef/knife/ionoscloud_server_create.rb +104 -0
- data/lib/chef/knife/ionoscloud_server_delete.rb +62 -0
- data/lib/chef/knife/ionoscloud_server_list.rb +58 -0
- data/lib/chef/knife/ionoscloud_server_reboot.rb +45 -0
- data/lib/chef/knife/ionoscloud_server_start.rb +43 -0
- data/lib/chef/knife/ionoscloud_server_stop.rb +44 -0
- data/lib/chef/knife/ionoscloud_share_create.rb +71 -0
- data/lib/chef/knife/ionoscloud_share_delete.rb +55 -0
- data/lib/chef/knife/ionoscloud_share_list.rb +47 -0
- data/lib/chef/knife/ionoscloud_snapshot_create.rb +58 -0
- data/lib/chef/knife/ionoscloud_snapshot_delete.rb +54 -0
- data/lib/chef/knife/ionoscloud_snapshot_list.rb +45 -0
- data/lib/chef/knife/ionoscloud_snapshot_restore.rb +69 -0
- data/lib/chef/knife/ionoscloud_user_create.rb +83 -0
- data/lib/chef/knife/ionoscloud_user_delete.rb +56 -0
- data/lib/chef/knife/ionoscloud_user_list.rb +60 -0
- data/lib/chef/knife/ionoscloud_user_ssourl.rb +37 -0
- data/lib/chef/knife/ionoscloud_volume_attach.rb +52 -0
- data/lib/chef/knife/ionoscloud_volume_create.rb +133 -0
- data/lib/chef/knife/ionoscloud_volume_delete.rb +67 -0
- data/lib/chef/knife/ionoscloud_volume_detach.rb +77 -0
- data/lib/chef/knife/ionoscloud_volume_list.rb +70 -0
- data/lib/knife-ionoscloud/version.rb +6 -0
- data/spec/chef/knife/ionoscloud_backupunit_create_spec.rb +65 -0
- data/spec/chef/knife/ionoscloud_backupunit_delete_spec.rb +101 -0
- data/spec/chef/knife/ionoscloud_backupunit_list_spec.rb +72 -0
- data/spec/chef/knife/ionoscloud_backupunit_ssourl_spec.rb +93 -0
- data/spec/chef/knife/ionoscloud_base_spec.rb +157 -0
- data/spec/chef/knife/ionoscloud_composite_server_create_spec.rb +111 -0
- data/spec/chef/knife/ionoscloud_contract_list_spec.rb +81 -0
- data/spec/chef/knife/ionoscloud_datacenter_create_spec.rb +72 -0
- data/spec/chef/knife/ionoscloud_datacenter_delete_spec.rb +102 -0
- data/spec/chef/knife/ionoscloud_datacenter_list_spec.rb +76 -0
- data/spec/chef/knife/ionoscloud_firewall_create_spec.rb +90 -0
- data/spec/chef/knife/ionoscloud_firewall_delete_spec.rb +117 -0
- data/spec/chef/knife/ionoscloud_firewall_list_spec.rb +90 -0
- data/spec/chef/knife/ionoscloud_group_create_spec.rb +76 -0
- data/spec/chef/knife/ionoscloud_group_delete_spec.rb +109 -0
- data/spec/chef/knife/ionoscloud_group_get_spec.rb +73 -0
- data/spec/chef/knife/ionoscloud_group_list_spec.rb +115 -0
- data/spec/chef/knife/ionoscloud_group_user_add_spec.rb +134 -0
- data/spec/chef/knife/ionoscloud_group_user_remove_spec.rb +130 -0
- data/spec/chef/knife/ionoscloud_image_list_spec.rb +75 -0
- data/spec/chef/knife/ionoscloud_ipblock_create_spec.rb +72 -0
- data/spec/chef/knife/ionoscloud_ipblock_delete_spec.rb +102 -0
- data/spec/chef/knife/ionoscloud_ipblock_list_spec.rb +74 -0
- data/spec/chef/knife/ionoscloud_ipfailover_add_spec.rb +83 -0
- data/spec/chef/knife/ionoscloud_ipfailover_remove_spec.rb +122 -0
- data/spec/chef/knife/ionoscloud_k8s_create_spec.rb +83 -0
- data/spec/chef/knife/ionoscloud_k8s_delete_spec.rb +172 -0
- data/spec/chef/knife/ionoscloud_k8s_list_spec.rb +73 -0
- data/spec/chef/knife/ionoscloud_kubeconfig_get_spec.rb +91 -0
- data/spec/chef/knife/ionoscloud_label_add_spec.rb +287 -0
- data/spec/chef/knife/ionoscloud_label_list_spec.rb +337 -0
- data/spec/chef/knife/ionoscloud_label_remove_spec.rb +391 -0
- data/spec/chef/knife/ionoscloud_lan_create_spec.rb +77 -0
- data/spec/chef/knife/ionoscloud_lan_delete_spec.rb +103 -0
- data/spec/chef/knife/ionoscloud_lan_list_spec.rb +73 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_create_spec.rb +82 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_delete_spec.rb +107 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_get_spec.rb +68 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_list_spec.rb +74 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_nic_add_spec.rb +128 -0
- data/spec/chef/knife/ionoscloud_loadbalancer_nic_remove_spec.rb +124 -0
- data/spec/chef/knife/ionoscloud_location_list_spec.rb +67 -0
- data/spec/chef/knife/ionoscloud_nic_create_spec.rb +85 -0
- data/spec/chef/knife/ionoscloud_nic_delete_spec.rb +108 -0
- data/spec/chef/knife/ionoscloud_nic_list_spec.rb +83 -0
- data/spec/chef/knife/ionoscloud_node_delete_spec.rb +107 -0
- data/spec/chef/knife/ionoscloud_node_list_spec.rb +75 -0
- data/spec/chef/knife/ionoscloud_node_replace_spec.rb +94 -0
- data/spec/chef/knife/ionoscloud_nodepool_create_spec.rb +99 -0
- data/spec/chef/knife/ionoscloud_nodepool_delete_spec.rb +106 -0
- data/spec/chef/knife/ionoscloud_nodepool_list_spec.rb +76 -0
- data/spec/chef/knife/ionoscloud_pcc_create_spec.rb +70 -0
- data/spec/chef/knife/ionoscloud_pcc_delete_spec.rb +106 -0
- data/spec/chef/knife/ionoscloud_pcc_list_spec.rb +69 -0
- data/spec/chef/knife/ionoscloud_request_list_spec.rb +165 -0
- data/spec/chef/knife/ionoscloud_request_status_spec.rb +92 -0
- data/spec/chef/knife/ionoscloud_request_wait_spec.rb +74 -0
- data/spec/chef/knife/ionoscloud_resource_list_spec.rb +155 -0
- data/spec/chef/knife/ionoscloud_s3key_create_spec.rb +64 -0
- data/spec/chef/knife/ionoscloud_s3key_delete_spec.rb +103 -0
- data/spec/chef/knife/ionoscloud_s3key_list_spec.rb +70 -0
- data/spec/chef/knife/ionoscloud_server_create_spec.rb +84 -0
- data/spec/chef/knife/ionoscloud_server_delete_spec.rb +108 -0
- data/spec/chef/knife/ionoscloud_server_list_spec.rb +85 -0
- data/spec/chef/knife/ionoscloud_server_reboot_spec.rb +95 -0
- data/spec/chef/knife/ionoscloud_server_start_spec.rb +95 -0
- data/spec/chef/knife/ionoscloud_server_stop_spec.rb +95 -0
- data/spec/chef/knife/ionoscloud_share_create_spec.rb +68 -0
- data/spec/chef/knife/ionoscloud_share_delete_spec.rb +103 -0
- data/spec/chef/knife/ionoscloud_share_list_spec.rb +70 -0
- data/spec/chef/knife/ionoscloud_snapshot_create_spec.rb +74 -0
- data/spec/chef/knife/ionoscloud_snapshot_delete_spec.rb +103 -0
- data/spec/chef/knife/ionoscloud_snapshot_list_spec.rb +73 -0
- data/spec/chef/knife/ionoscloud_snapshot_restore_spec.rb +78 -0
- data/spec/chef/knife/ionoscloud_user_create_spec.rb +73 -0
- data/spec/chef/knife/ionoscloud_user_delete_spec.rb +104 -0
- data/spec/chef/knife/ionoscloud_user_list_spec.rb +103 -0
- data/spec/chef/knife/ionoscloud_user_ssourl_spec.rb +93 -0
- data/spec/chef/knife/ionoscloud_volume_attach_spec.rb +99 -0
- data/spec/chef/knife/ionoscloud_volume_create_spec.rb +143 -0
- data/spec/chef/knife/ionoscloud_volume_delete_spec.rb +108 -0
- data/spec/chef/knife/ionoscloud_volume_detach_spec.rb +110 -0
- data/spec/chef/knife/ionoscloud_volume_list_spec.rb +118 -0
- data/spec/spec_helper.rb +702 -0
- data/spec/test.sh +3 -0
- data/summary.md +0 -0
- metadata +460 -0
@@ -0,0 +1,337 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_label_list'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudLabelList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudLabelList do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudLabelList.new }
|
9
|
+
|
10
|
+
@labels = labels_mock
|
11
|
+
@label_list = label_list = [
|
12
|
+
subject.ui.color('Resource ID', :bold),
|
13
|
+
subject.ui.color('Resource Type', :bold),
|
14
|
+
subject.ui.color('Label key', :bold),
|
15
|
+
subject.ui.color('Value', :bold),
|
16
|
+
@labels.items.first.properties.resource_id,
|
17
|
+
@labels.items.first.properties.resource_type,
|
18
|
+
@labels.items.first.properties.key,
|
19
|
+
@labels.items.first.properties.value,
|
20
|
+
@labels.items[1].properties.resource_id,
|
21
|
+
@labels.items[1].properties.resource_type,
|
22
|
+
@labels.items[1].properties.key,
|
23
|
+
@labels.items[1].properties.value,
|
24
|
+
]
|
25
|
+
|
26
|
+
@label_resources = label_resources_mock
|
27
|
+
@label_resource_list = label_resource_list = [
|
28
|
+
subject.ui.color('Resource ID', :bold),
|
29
|
+
subject.ui.color('Resource Type', :bold),
|
30
|
+
subject.ui.color('Label key', :bold),
|
31
|
+
subject.ui.color('Value', :bold),
|
32
|
+
'resource_id',
|
33
|
+
'resource_type',
|
34
|
+
@label_resources.items.first.properties.key,
|
35
|
+
@label_resources.items.first.properties.value,
|
36
|
+
'resource_id',
|
37
|
+
'resource_type',
|
38
|
+
@label_resources.items[1].properties.key,
|
39
|
+
@label_resources.items[1].properties.value,
|
40
|
+
]
|
41
|
+
|
42
|
+
allow(subject).to receive(:puts)
|
43
|
+
allow(subject).to receive(:print)
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#run' do
|
47
|
+
it 'should call LabelApi.datacenters_labels_get when the type is datacenter and output based on what it receives' do
|
48
|
+
subject_config = {
|
49
|
+
ionoscloud_username: 'email',
|
50
|
+
ionoscloud_password: 'password',
|
51
|
+
type: 'datacenter',
|
52
|
+
resource_id: 'resource_id',
|
53
|
+
}
|
54
|
+
|
55
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
56
|
+
|
57
|
+
expected_output = @label_resource_list.map { |el| el == 'resource_type' ? subject_config[:type] : el }
|
58
|
+
|
59
|
+
expect(subject.ui).to receive(:list).with(expected_output, :uneven_columns_across, 4)
|
60
|
+
|
61
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
62
|
+
mock_call_api(
|
63
|
+
subject,
|
64
|
+
[
|
65
|
+
{
|
66
|
+
method: 'GET',
|
67
|
+
path: "/datacenters/#{subject_config[:resource_id]}/labels",
|
68
|
+
operation: :'LabelApi.datacenters_labels_get',
|
69
|
+
return_type: 'LabelResources',
|
70
|
+
result: @label_resources,
|
71
|
+
},
|
72
|
+
],
|
73
|
+
)
|
74
|
+
|
75
|
+
expect { subject.run }.not_to raise_error(Exception)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should call LabelApi.datacenters_servers_labels_get when the type is server and output based on what it receives' do
|
79
|
+
subject_config = {
|
80
|
+
ionoscloud_username: 'email',
|
81
|
+
ionoscloud_password: 'password',
|
82
|
+
type: 'server',
|
83
|
+
datacenter_id: 'datacenter_id',
|
84
|
+
resource_id: 'resource_id',
|
85
|
+
}
|
86
|
+
|
87
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
88
|
+
|
89
|
+
expected_output = @label_resource_list.map { |el| el == 'resource_type' ? subject_config[:type] : el }
|
90
|
+
|
91
|
+
expect(subject.ui).to receive(:list).with(expected_output, :uneven_columns_across, 4)
|
92
|
+
|
93
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
94
|
+
mock_call_api(
|
95
|
+
subject,
|
96
|
+
[
|
97
|
+
{
|
98
|
+
method: 'GET',
|
99
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:resource_id]}/labels",
|
100
|
+
operation: :'LabelApi.datacenters_servers_labels_get',
|
101
|
+
return_type: 'LabelResources',
|
102
|
+
result: @label_resources,
|
103
|
+
},
|
104
|
+
],
|
105
|
+
)
|
106
|
+
|
107
|
+
expect { subject.run }.not_to raise_error(Exception)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should call LabelApi.datacenters_volumes_labels_get when the type is volume and output based on what it receives' do
|
111
|
+
subject_config = {
|
112
|
+
ionoscloud_username: 'email',
|
113
|
+
ionoscloud_password: 'password',
|
114
|
+
type: 'volume',
|
115
|
+
datacenter_id: 'datacenter_id',
|
116
|
+
resource_id: 'resource_id',
|
117
|
+
}
|
118
|
+
|
119
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
120
|
+
|
121
|
+
expected_output = @label_resource_list.map { |el| el == 'resource_type' ? subject_config[:type] : el }
|
122
|
+
|
123
|
+
expect(subject.ui).to receive(:list).with(expected_output, :uneven_columns_across, 4)
|
124
|
+
|
125
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
126
|
+
mock_call_api(
|
127
|
+
subject,
|
128
|
+
[
|
129
|
+
{
|
130
|
+
method: 'GET',
|
131
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{subject_config[:resource_id]}/labels",
|
132
|
+
operation: :'LabelApi.datacenters_volumes_labels_get',
|
133
|
+
return_type: 'LabelResources',
|
134
|
+
result: @label_resources,
|
135
|
+
},
|
136
|
+
],
|
137
|
+
)
|
138
|
+
|
139
|
+
expect { subject.run }.not_to raise_error(Exception)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should call LabelApi.ipblocks_labels_get when the type is ipblock and output based on what it receives' do
|
143
|
+
subject_config = {
|
144
|
+
ionoscloud_username: 'email',
|
145
|
+
ionoscloud_password: 'password',
|
146
|
+
type: 'ipblock',
|
147
|
+
resource_id: 'resource_id',
|
148
|
+
}
|
149
|
+
|
150
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
151
|
+
|
152
|
+
expected_output = @label_resource_list.map { |el| el == 'resource_type' ? subject_config[:type] : el }
|
153
|
+
|
154
|
+
expect(subject.ui).to receive(:list).with(expected_output, :uneven_columns_across, 4)
|
155
|
+
|
156
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
157
|
+
mock_call_api(
|
158
|
+
subject,
|
159
|
+
[
|
160
|
+
{
|
161
|
+
method: 'GET',
|
162
|
+
path: "/ipblocks/#{subject_config[:resource_id]}/labels",
|
163
|
+
operation: :'LabelApi.ipblocks_labels_get',
|
164
|
+
return_type: 'LabelResources',
|
165
|
+
result: @label_resources,
|
166
|
+
},
|
167
|
+
],
|
168
|
+
)
|
169
|
+
|
170
|
+
expect { subject.run }.not_to raise_error(Exception)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should call LabelApi.snapshots_labels_get when the type is snapshot and output based on what it receives' do
|
174
|
+
subject_config = {
|
175
|
+
ionoscloud_username: 'email',
|
176
|
+
ionoscloud_password: 'password',
|
177
|
+
type: 'snapshot',
|
178
|
+
resource_id: 'resource_id',
|
179
|
+
}
|
180
|
+
|
181
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
182
|
+
|
183
|
+
expected_output = @label_resource_list.map { |el| el == 'resource_type' ? subject_config[:type] : el }
|
184
|
+
|
185
|
+
expect(subject.ui).to receive(:list).with(expected_output, :uneven_columns_across, 4)
|
186
|
+
|
187
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
188
|
+
mock_call_api(
|
189
|
+
subject,
|
190
|
+
[
|
191
|
+
{
|
192
|
+
method: 'GET',
|
193
|
+
path: "/snapshots/#{subject_config[:resource_id]}/labels",
|
194
|
+
operation: :'LabelApi.snapshots_labels_get',
|
195
|
+
return_type: 'LabelResources',
|
196
|
+
result: @label_resources,
|
197
|
+
},
|
198
|
+
],
|
199
|
+
)
|
200
|
+
|
201
|
+
expect { subject.run }.not_to raise_error(Exception)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should call LabelApi.labels_get when the type is not one of [datacenter, server, volume, ipblock, snapshot]' do
|
205
|
+
subject_config = {
|
206
|
+
ionoscloud_username: 'email',
|
207
|
+
ionoscloud_password: 'password',
|
208
|
+
type: 'invalid_type',
|
209
|
+
resource_id: @labels.items.first.properties.resource_id,
|
210
|
+
}
|
211
|
+
|
212
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
213
|
+
|
214
|
+
expect(subject.ui).to receive(:warn).with("#{subject_config[:type]} is not a valid Resource Type. Returning all available labels.")
|
215
|
+
expect(subject.ui).to receive(:list).with(@label_resource_list, :uneven_columns_across, 4)
|
216
|
+
|
217
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
218
|
+
mock_call_api(
|
219
|
+
subject,
|
220
|
+
[
|
221
|
+
{
|
222
|
+
method: 'GET',
|
223
|
+
path: '/labels',
|
224
|
+
operation: :'LabelApi.labels_get',
|
225
|
+
return_type: 'Labels',
|
226
|
+
result: @labels,
|
227
|
+
},
|
228
|
+
],
|
229
|
+
)
|
230
|
+
|
231
|
+
expect { subject.run }.not_to raise_error(Exception)
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should call LabelApi.labels_get when the type is missing' do
|
235
|
+
subject_config = {
|
236
|
+
ionoscloud_username: 'email',
|
237
|
+
ionoscloud_password: 'password',
|
238
|
+
resource_id: @labels.items.first.properties.resource_id,
|
239
|
+
}
|
240
|
+
|
241
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
242
|
+
|
243
|
+
expect(subject.ui).to receive(:list).with(@label_list, :uneven_columns_across, 4)
|
244
|
+
|
245
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
246
|
+
mock_call_api(
|
247
|
+
subject,
|
248
|
+
[
|
249
|
+
{
|
250
|
+
method: 'GET',
|
251
|
+
path: '/labels',
|
252
|
+
operation: :'LabelApi.labels_get',
|
253
|
+
return_type: 'Labels',
|
254
|
+
result: @labels,
|
255
|
+
},
|
256
|
+
],
|
257
|
+
)
|
258
|
+
|
259
|
+
expect { subject.run }.not_to raise_error(Exception)
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should not call anything when the type is one of [datacenter, server, volume, ipblock, snapshot] and resource_id is not given' do
|
263
|
+
types = [
|
264
|
+
'datacenter',
|
265
|
+
'server',
|
266
|
+
'volume',
|
267
|
+
'ipblock',
|
268
|
+
'snapshot',
|
269
|
+
].each do |resource_type|
|
270
|
+
subject_config = {
|
271
|
+
ionoscloud_username: 'email',
|
272
|
+
ionoscloud_password: 'password',
|
273
|
+
type: 'server',
|
274
|
+
datacenter_id: 'datacenter_id',
|
275
|
+
key: 'key',
|
276
|
+
value: 'value',
|
277
|
+
}
|
278
|
+
|
279
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
280
|
+
|
281
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{[:resource_id]}")
|
282
|
+
expect(subject.api_client).not_to receive(:call_api)
|
283
|
+
|
284
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
285
|
+
expect(error.status).to eq(1)
|
286
|
+
end
|
287
|
+
|
288
|
+
subject_config.each { |value| subject.config[value] = nil }
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'should not call anything when the type is server or volume and datacenter_id is not given' do
|
293
|
+
types = [
|
294
|
+
'server',
|
295
|
+
'volume',
|
296
|
+
].each do |resource_type|
|
297
|
+
subject_config = {
|
298
|
+
ionoscloud_username: 'email',
|
299
|
+
ionoscloud_password: 'password',
|
300
|
+
type: 'server',
|
301
|
+
resource_id: 'resource_id',
|
302
|
+
key: 'key',
|
303
|
+
value: 'value',
|
304
|
+
}
|
305
|
+
|
306
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
307
|
+
|
308
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{[:datacenter_id]}")
|
309
|
+
expect(subject.api_client).not_to receive(:call_api)
|
310
|
+
|
311
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
312
|
+
expect(error.status).to eq(1)
|
313
|
+
end
|
314
|
+
|
315
|
+
subject_config.each { |value| subject.config[value] = nil }
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'should not make any call if any required option is missing' do
|
320
|
+
required_options = subject.instance_variable_get(:@required_options)
|
321
|
+
|
322
|
+
arrays_without_one_element(required_options).each do |test_case|
|
323
|
+
|
324
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
325
|
+
|
326
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
327
|
+
expect(subject.api_client).not_to receive(:call_api)
|
328
|
+
|
329
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
330
|
+
expect(error.status).to eq(1)
|
331
|
+
end
|
332
|
+
|
333
|
+
required_options.each { |value| subject.config[value] = nil }
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
@@ -0,0 +1,391 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_label_remove'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudLabelRemove.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudLabelRemove do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudLabelRemove.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call LabelApi.datacenters_labels_delete when the type is datacenter and output based on what it receives' do
|
16
|
+
label = label_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
type: 'datacenter',
|
21
|
+
resource_id: label.properties.resource_id,
|
22
|
+
key: label.properties.key,
|
23
|
+
}
|
24
|
+
|
25
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
26
|
+
subject.name_args = [label.id]
|
27
|
+
|
28
|
+
expect(subject.ui).to receive(:warn).with("Removed Label #{label.id} from #{subject_config[:type]} #{subject_config[:resource_id]}.")
|
29
|
+
|
30
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
31
|
+
mock_call_api(
|
32
|
+
subject,
|
33
|
+
[
|
34
|
+
{
|
35
|
+
method: 'DELETE',
|
36
|
+
path: "/datacenters/#{subject_config[:resource_id]}/labels/#{label.id}",
|
37
|
+
operation: :'LabelApi.datacenters_labels_delete',
|
38
|
+
result: label,
|
39
|
+
},
|
40
|
+
],
|
41
|
+
)
|
42
|
+
|
43
|
+
expect { subject.run }.not_to raise_error(Exception)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should print when LabelApi.datacenters_labels_delete returns 404' do
|
47
|
+
label = label_mock
|
48
|
+
subject_config = {
|
49
|
+
ionoscloud_username: 'email',
|
50
|
+
ionoscloud_password: 'password',
|
51
|
+
type: 'datacenter',
|
52
|
+
resource_id: label.properties.resource_id,
|
53
|
+
key: label.properties.key,
|
54
|
+
}
|
55
|
+
|
56
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
57
|
+
subject.name_args = [label.id]
|
58
|
+
|
59
|
+
expect(subject.ui).to receive(:error).with("Label #{label.id} not found. Skipping.")
|
60
|
+
|
61
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
62
|
+
mock_call_api(
|
63
|
+
subject,
|
64
|
+
[
|
65
|
+
{
|
66
|
+
method: 'DELETE',
|
67
|
+
path: "/datacenters/#{subject_config[:resource_id]}/labels/#{label.id}",
|
68
|
+
operation: :'LabelApi.datacenters_labels_delete',
|
69
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
70
|
+
},
|
71
|
+
],
|
72
|
+
)
|
73
|
+
|
74
|
+
expect { subject.run }.not_to raise_error(Exception)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should call LabelApi.datacenters_servers_labels_delete when the type is datacenter and output based on what it receives' do
|
78
|
+
label = label_mock
|
79
|
+
subject_config = {
|
80
|
+
ionoscloud_username: 'email',
|
81
|
+
ionoscloud_password: 'password',
|
82
|
+
type: 'server',
|
83
|
+
datacenter_id: 'datacenter_id',
|
84
|
+
resource_id: label.properties.resource_id,
|
85
|
+
key: label.properties.key,
|
86
|
+
}
|
87
|
+
|
88
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
89
|
+
subject.name_args = [label.id]
|
90
|
+
|
91
|
+
expect(subject.ui).to receive(:warn).with("Removed Label #{label.id} from #{subject_config[:type]} #{subject_config[:resource_id]}.")
|
92
|
+
|
93
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
94
|
+
mock_call_api(
|
95
|
+
subject,
|
96
|
+
[
|
97
|
+
{
|
98
|
+
method: 'DELETE',
|
99
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:resource_id]}/labels/#{label.id}",
|
100
|
+
operation: :'LabelApi.datacenters_servers_labels_delete',
|
101
|
+
result: label,
|
102
|
+
},
|
103
|
+
],
|
104
|
+
)
|
105
|
+
|
106
|
+
expect { subject.run }.not_to raise_error(Exception)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should print when LabelApi.datacenters_servers_labels_delete returns 404' do
|
110
|
+
label = label_mock
|
111
|
+
subject_config = {
|
112
|
+
ionoscloud_username: 'email',
|
113
|
+
ionoscloud_password: 'password',
|
114
|
+
type: 'server',
|
115
|
+
datacenter_id: 'datacenter_id',
|
116
|
+
resource_id: label.properties.resource_id,
|
117
|
+
key: label.properties.key,
|
118
|
+
}
|
119
|
+
|
120
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
121
|
+
subject.name_args = [label.id]
|
122
|
+
|
123
|
+
expect(subject.ui).to receive(:error).with("Label #{label.id} not found. Skipping.")
|
124
|
+
|
125
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
126
|
+
mock_call_api(
|
127
|
+
subject,
|
128
|
+
[
|
129
|
+
{
|
130
|
+
method: 'DELETE',
|
131
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/servers/#{subject_config[:resource_id]}/labels/#{label.id}",
|
132
|
+
operation: :'LabelApi.datacenters_servers_labels_delete',
|
133
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
134
|
+
},
|
135
|
+
],
|
136
|
+
)
|
137
|
+
|
138
|
+
expect { subject.run }.not_to raise_error(Exception)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should call LabelApi.datacenters_volumes_labels_delete when the type is datacenter and output based on what it receives' do
|
142
|
+
label = label_mock
|
143
|
+
subject_config = {
|
144
|
+
ionoscloud_username: 'email',
|
145
|
+
ionoscloud_password: 'password',
|
146
|
+
type: 'volume',
|
147
|
+
datacenter_id: 'datacenter_id',
|
148
|
+
resource_id: label.properties.resource_id,
|
149
|
+
key: label.properties.key,
|
150
|
+
}
|
151
|
+
|
152
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
153
|
+
subject.name_args = [label.id]
|
154
|
+
|
155
|
+
expect(subject.ui).to receive(:warn).with("Removed Label #{label.id} from #{subject_config[:type]} #{subject_config[:resource_id]}.")
|
156
|
+
|
157
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
158
|
+
mock_call_api(
|
159
|
+
subject,
|
160
|
+
[
|
161
|
+
{
|
162
|
+
method: 'DELETE',
|
163
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{subject_config[:resource_id]}/labels/#{label.id}",
|
164
|
+
operation: :'LabelApi.datacenters_volumes_labels_delete',
|
165
|
+
result: label,
|
166
|
+
},
|
167
|
+
],
|
168
|
+
)
|
169
|
+
|
170
|
+
expect { subject.run }.not_to raise_error(Exception)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should print when LabelApi.datacenters_volumes_labels_delete returns 404' do
|
174
|
+
label = label_mock
|
175
|
+
subject_config = {
|
176
|
+
ionoscloud_username: 'email',
|
177
|
+
ionoscloud_password: 'password',
|
178
|
+
type: 'volume',
|
179
|
+
datacenter_id: 'datacenter_id',
|
180
|
+
resource_id: label.properties.resource_id,
|
181
|
+
key: label.properties.key,
|
182
|
+
}
|
183
|
+
|
184
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
185
|
+
subject.name_args = [label.id]
|
186
|
+
|
187
|
+
expect(subject.ui).to receive(:error).with("Label #{label.id} not found. Skipping.")
|
188
|
+
|
189
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
190
|
+
mock_call_api(
|
191
|
+
subject,
|
192
|
+
[
|
193
|
+
{
|
194
|
+
method: 'DELETE',
|
195
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/volumes/#{subject_config[:resource_id]}/labels/#{label.id}",
|
196
|
+
operation: :'LabelApi.datacenters_volumes_labels_delete',
|
197
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
198
|
+
},
|
199
|
+
],
|
200
|
+
)
|
201
|
+
|
202
|
+
expect { subject.run }.not_to raise_error(Exception)
|
203
|
+
end
|
204
|
+
it 'should call LabelApi.ipblocks_labels_delete when the type is ipblock and output based on what it receives' do
|
205
|
+
label = label_mock
|
206
|
+
subject_config = {
|
207
|
+
ionoscloud_username: 'email',
|
208
|
+
ionoscloud_password: 'password',
|
209
|
+
type: 'ipblock',
|
210
|
+
resource_id: label.properties.resource_id,
|
211
|
+
key: label.properties.key,
|
212
|
+
}
|
213
|
+
|
214
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
215
|
+
subject.name_args = [label.id]
|
216
|
+
|
217
|
+
expect(subject.ui).to receive(:warn).with("Removed Label #{label.id} from #{subject_config[:type]} #{subject_config[:resource_id]}.")
|
218
|
+
|
219
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
220
|
+
mock_call_api(
|
221
|
+
subject,
|
222
|
+
[
|
223
|
+
{
|
224
|
+
method: 'DELETE',
|
225
|
+
path: "/ipblocks/#{subject_config[:resource_id]}/labels/#{label.id}",
|
226
|
+
operation: :'LabelApi.ipblocks_labels_delete',
|
227
|
+
result: label,
|
228
|
+
},
|
229
|
+
],
|
230
|
+
)
|
231
|
+
|
232
|
+
expect { subject.run }.not_to raise_error(Exception)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should print when LabelApi.ipblocks_labels_delete returns 404' do
|
236
|
+
label = label_mock
|
237
|
+
subject_config = {
|
238
|
+
ionoscloud_username: 'email',
|
239
|
+
ionoscloud_password: 'password',
|
240
|
+
type: 'ipblock',
|
241
|
+
resource_id: label.properties.resource_id,
|
242
|
+
key: label.properties.key,
|
243
|
+
}
|
244
|
+
|
245
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
246
|
+
subject.name_args = [label.id]
|
247
|
+
|
248
|
+
expect(subject.ui).to receive(:error).with("Label #{label.id} not found. Skipping.")
|
249
|
+
|
250
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
251
|
+
mock_call_api(
|
252
|
+
subject,
|
253
|
+
[
|
254
|
+
{
|
255
|
+
method: 'DELETE',
|
256
|
+
path: "/ipblocks/#{subject_config[:resource_id]}/labels/#{label.id}",
|
257
|
+
operation: :'LabelApi.ipblocks_labels_delete',
|
258
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
259
|
+
},
|
260
|
+
],
|
261
|
+
)
|
262
|
+
|
263
|
+
expect { subject.run }.not_to raise_error(Exception)
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'should call LabelApi.snapshots_labels_delete when the type is snapshot and output based on what it receives' do
|
267
|
+
label = label_mock
|
268
|
+
subject_config = {
|
269
|
+
ionoscloud_username: 'email',
|
270
|
+
ionoscloud_password: 'password',
|
271
|
+
type: 'snapshot',
|
272
|
+
resource_id: label.properties.resource_id,
|
273
|
+
key: label.properties.key,
|
274
|
+
}
|
275
|
+
|
276
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
277
|
+
subject.name_args = [label.id]
|
278
|
+
|
279
|
+
expect(subject.ui).to receive(:warn).with("Removed Label #{label.id} from #{subject_config[:type]} #{subject_config[:resource_id]}.")
|
280
|
+
|
281
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
282
|
+
mock_call_api(
|
283
|
+
subject,
|
284
|
+
[
|
285
|
+
{
|
286
|
+
method: 'DELETE',
|
287
|
+
path: "/snapshots/#{subject_config[:resource_id]}/labels/#{label.id}",
|
288
|
+
operation: :'LabelApi.snapshots_labels_delete',
|
289
|
+
result: label,
|
290
|
+
},
|
291
|
+
],
|
292
|
+
)
|
293
|
+
|
294
|
+
expect { subject.run }.not_to raise_error(Exception)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should print when LabelApi.snapshots_labels_delete returns 404' do
|
298
|
+
label = label_mock
|
299
|
+
subject_config = {
|
300
|
+
ionoscloud_username: 'email',
|
301
|
+
ionoscloud_password: 'password',
|
302
|
+
type: 'snapshot',
|
303
|
+
resource_id: label.properties.resource_id,
|
304
|
+
key: label.properties.key,
|
305
|
+
}
|
306
|
+
|
307
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
308
|
+
subject.name_args = [label.id]
|
309
|
+
|
310
|
+
expect(subject.ui).to receive(:error).with("Label #{label.id} not found. Skipping.")
|
311
|
+
|
312
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
313
|
+
mock_call_api(
|
314
|
+
subject,
|
315
|
+
[
|
316
|
+
{
|
317
|
+
method: 'DELETE',
|
318
|
+
path: "/snapshots/#{subject_config[:resource_id]}/labels/#{label.id}",
|
319
|
+
operation: :'LabelApi.snapshots_labels_delete',
|
320
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
321
|
+
},
|
322
|
+
],
|
323
|
+
)
|
324
|
+
|
325
|
+
expect { subject.run }.not_to raise_error(Exception)
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'should not call anything when the type is not one of [datacenter, server, volume, ipblock, snapshot]' do
|
329
|
+
subject_config = {
|
330
|
+
ionoscloud_username: 'email',
|
331
|
+
ionoscloud_password: 'password',
|
332
|
+
type: 'invalid_type',
|
333
|
+
resource_id: 'resource_id',
|
334
|
+
key: 'key',
|
335
|
+
}
|
336
|
+
|
337
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
338
|
+
|
339
|
+
expect(subject.ui).to receive(:error).with("#{subject_config[:type]} is not a valid Resource Type.")
|
340
|
+
expect(subject.api_client).not_to receive(:call_api)
|
341
|
+
|
342
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
343
|
+
expect(error.status).to eq(1)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'should not call anything when the type is server or volume and datacenter_id is not given' do
|
348
|
+
types = [
|
349
|
+
'server',
|
350
|
+
'volume',
|
351
|
+
].each do |resource_type|
|
352
|
+
subject_config = {
|
353
|
+
ionoscloud_username: 'email',
|
354
|
+
ionoscloud_password: 'password',
|
355
|
+
type: 'server',
|
356
|
+
resource_id: 'resource_id',
|
357
|
+
key: 'key',
|
358
|
+
}
|
359
|
+
|
360
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
361
|
+
|
362
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{[:datacenter_id]}")
|
363
|
+
expect(subject.api_client).not_to receive(:call_api)
|
364
|
+
|
365
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
366
|
+
expect(error.status).to eq(1)
|
367
|
+
end
|
368
|
+
|
369
|
+
subject_config.each { |value| subject.config[value] = nil }
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'should not make any call if any required option is missing' do
|
374
|
+
required_options = subject.instance_variable_get(:@required_options)
|
375
|
+
|
376
|
+
arrays_without_one_element(required_options).each do |test_case|
|
377
|
+
|
378
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
379
|
+
|
380
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
381
|
+
expect(subject.api_client).not_to receive(:call_api)
|
382
|
+
|
383
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
384
|
+
expect(error.status).to eq(1)
|
385
|
+
end
|
386
|
+
|
387
|
+
required_options.each { |value| subject.config[value] = nil }
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|