knife-google 3.3.6 → 3.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/knife-google/version.rb +1 -1
- metadata +2 -33
- data/.expeditor/config.yml +0 -41
- data/.expeditor/update_version.sh +0 -12
- data/.github/CODEOWNERS +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -21
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- data/.gitignore +0 -26
- data/.rspec +0 -3
- data/.travis.yml +0 -27
- data/CHANGELOG.md +0 -252
- data/Gemfile +0 -30
- data/README.md +0 -305
- data/RELEASE_NOTES.md +0 -18
- data/Rakefile +0 -35
- data/TESTING.md +0 -48
- data/VERSION +0 -1
- data/knife-google.gemspec +0 -25
- data/spec/cloud/google_service_helpers_spec.rb +0 -119
- data/spec/cloud/google_service_spec.rb +0 -1021
- data/spec/google_disk_create_spec.rb +0 -86
- data/spec/google_disk_delete_spec.rb +0 -78
- data/spec/google_disk_list_spec.rb +0 -107
- data/spec/google_project_quotas_spec.rb +0 -77
- data/spec/google_region_list_spec.rb +0 -79
- data/spec/google_region_quotas_spec.rb +0 -122
- data/spec/google_server_create_spec.rb +0 -243
- data/spec/google_server_delete_spec.rb +0 -53
- data/spec/google_server_list_spec.rb +0 -91
- data/spec/google_server_show_spec.rb +0 -74
- data/spec/google_zone_list_spec.rb +0 -73
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_disk_create"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleDiskCreate do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new(%w{disk1}) }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
before do
|
41
|
-
allow(command).to receive(:check_for_missing_config_values!)
|
42
|
-
allow(command).to receive(:valid_disk_size?).and_return(true)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "checks for missing config values" do
|
46
|
-
expect(command).to receive(:check_for_missing_config_values!).with(:gce_zone, :disk_size, :disk_type)
|
47
|
-
|
48
|
-
command.validate_params!
|
49
|
-
end
|
50
|
-
|
51
|
-
it "does not raise an exception if all params are good" do
|
52
|
-
expect { command.validate_params! }.not_to raise_error
|
53
|
-
end
|
54
|
-
|
55
|
-
it "raises an exception if the disk size is invalid" do
|
56
|
-
expect(command).to receive(:valid_disk_size?).and_return(false)
|
57
|
-
expect { command.validate_params! }.to raise_error(RuntimeError, "Disk size must be between 10 and 10,000")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "raises an exception if the gce_project is missing" do
|
61
|
-
ui = double("ui")
|
62
|
-
expect(tester).to receive(:ui).and_return(ui)
|
63
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
64
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
65
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when no disk name is provided" do
|
69
|
-
let(:command) { described_class.new }
|
70
|
-
it "raises an exception" do
|
71
|
-
expect { command.validate_params! }.to raise_error(RuntimeError, "Please specify a disk name.")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#execute_command" do
|
77
|
-
it "calls the service to create the disk" do
|
78
|
-
expect(command).to receive(:locate_config_value).with(:disk_size).and_return("size")
|
79
|
-
expect(command).to receive(:locate_config_value).with(:disk_type).and_return("type")
|
80
|
-
expect(command).to receive(:locate_config_value).with(:disk_source).and_return("source")
|
81
|
-
expect(service).to receive(:create_disk).with("disk1", "size", "type", "source")
|
82
|
-
|
83
|
-
command.execute_command
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_disk_delete"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleDiskDelete do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new(%w{disk1 disk2}) }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
before do
|
41
|
-
allow(command).to receive(:check_for_missing_config_values!)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "checks for missing config values" do
|
45
|
-
expect(command).to receive(:check_for_missing_config_values!).with(:gce_zone)
|
46
|
-
|
47
|
-
command.validate_params!
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not raise an exception if all params are good" do
|
51
|
-
expect { command.validate_params! }.not_to raise_error
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises an exception if the gce_project is missing" do
|
55
|
-
ui = double("ui")
|
56
|
-
expect(tester).to receive(:ui).and_return(ui)
|
57
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
58
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
59
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when no disk name is provided" do
|
63
|
-
let(:command) { described_class.new }
|
64
|
-
it "raises an exception" do
|
65
|
-
expect { command.validate_params! }.to raise_error(RuntimeError, "You must specify at least one disk to delete.")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#execute_command" do
|
71
|
-
it "calls the service to delete each disk" do
|
72
|
-
expect(service).to receive(:delete_disk).with("disk1")
|
73
|
-
expect(service).to receive(:delete_disk).with("disk2")
|
74
|
-
|
75
|
-
command.execute_command
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_disk_list"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleDiskList do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
it "checks for missing config values" do
|
41
|
-
expect(command).to receive(:check_for_missing_config_values!).with(:gce_zone)
|
42
|
-
|
43
|
-
command.validate_params!
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises an exception if the gce_project is missing" do
|
47
|
-
ui = double("ui")
|
48
|
-
expect(tester).to receive(:ui).and_return(ui)
|
49
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
50
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
51
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#query_resource" do
|
56
|
-
it "uses the service to list disks" do
|
57
|
-
expect(service).to receive(:list_disks).and_return("disks")
|
58
|
-
expect(command.query_resource).to eq("disks")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#format_status_value" do
|
63
|
-
it "returns green when the status is ready" do
|
64
|
-
expect(command.ui).to receive(:color).with("ready", :green)
|
65
|
-
command.format_status_value("ready")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns red when the status is stopped" do
|
69
|
-
expect(command.ui).to receive(:color).with("stopped", :red)
|
70
|
-
command.format_status_value("stopped")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#format_disk_type" do
|
75
|
-
it "returns a properly-formatted disk type" do
|
76
|
-
expect(command.format_disk_type("a/b/c/disk_type")).to eq("disk_type")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "#format_source_image" do
|
81
|
-
it "returns 'unknown' if the source is nil" do
|
82
|
-
expect(command.format_source_image(nil)).to eq("unknown")
|
83
|
-
end
|
84
|
-
|
85
|
-
it "returns 'unknown' if the source is empty" do
|
86
|
-
expect(command.format_source_image([])).to eq("unknown")
|
87
|
-
end
|
88
|
-
|
89
|
-
it "returns a properly-formatted image URL" do
|
90
|
-
expect(command.format_source_image("/1/2/3/4/5/6/image_name")).to eq("4/5/6/image_name")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#format_users" do
|
95
|
-
it "returns 'unknown' if the source is nil" do
|
96
|
-
expect(command.format_users(nil)).to eq("none")
|
97
|
-
end
|
98
|
-
|
99
|
-
it "returns 'unknown' if the source is empty" do
|
100
|
-
expect(command.format_users([])).to eq("none")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "returns a properly-formatted user URL" do
|
104
|
-
expect(command.format_users(["/1/2/3/4/5/6/user1", "/1/2/3/4/5/6/user2"])).to eq("3/4/5/6/user1, 3/4/5/6/user2")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_project_quotas"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleProjectQuotas do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
it "checks for missing config values" do
|
41
|
-
expect(command).to receive(:check_for_missing_config_values!)
|
42
|
-
|
43
|
-
command.validate_params!
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises an exception if the gce_project is missing" do
|
47
|
-
ui = double("ui")
|
48
|
-
expect(tester).to receive(:ui).and_return(ui)
|
49
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
50
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
51
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#query_resource" do
|
56
|
-
it "uses the service to list project quotas" do
|
57
|
-
expect(service).to receive(:list_project_quotas).and_return("quotas")
|
58
|
-
expect(command.query_resource).to eq("quotas")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#format_name" do
|
63
|
-
it "returns a properly-formatted name" do
|
64
|
-
expect(command.format_name("something_cool_here")).to eq("Something Cool Here")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#format_number" do
|
69
|
-
it "returns an integer as a string if the number is a whole number" do
|
70
|
-
expect(command.format_number(2.0)).to eq("2")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns the number as-is if it is not a whole number" do
|
74
|
-
expect(command.format_number(2.5)).to eq("2.5")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_region_list"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleRegionList do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
it "checks for missing config values" do
|
41
|
-
expect(command).to receive(:check_for_missing_config_values!)
|
42
|
-
|
43
|
-
command.validate_params!
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises an exception if the gce_project is missing" do
|
47
|
-
ui = double("ui")
|
48
|
-
expect(tester).to receive(:ui).and_return(ui)
|
49
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
50
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
51
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#query_resource" do
|
56
|
-
it "uses the service to list regions" do
|
57
|
-
expect(service).to receive(:list_regions).and_return("regions")
|
58
|
-
expect(command.query_resource).to eq("regions")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#format_status_value" do
|
63
|
-
it "returns green when the status is up" do
|
64
|
-
expect(command.ui).to receive(:color).with("up", :green)
|
65
|
-
command.format_status_value("up")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns red when the status is stopped" do
|
69
|
-
expect(command.ui).to receive(:color).with("stopped", :red)
|
70
|
-
command.format_status_value("stopped")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#format_zones" do
|
75
|
-
it "returns properly-formatted zones" do
|
76
|
-
expect(command.format_zones(["a/b/zone1", "c/d/zone2"])).to eq("zone1, zone2")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/google_region_quotas"
|
22
|
-
require "support/shared_examples_for_command"
|
23
|
-
|
24
|
-
class Tester
|
25
|
-
include Chef::Knife::Cloud::GoogleServiceHelpers
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Chef::Knife::Cloud::GoogleRegionQuotas do
|
29
|
-
let(:tester) { Tester.new }
|
30
|
-
let(:command) { described_class.new }
|
31
|
-
let(:service) { double("service") }
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(command).to receive(:service).and_return(service)
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like Chef::Knife::Cloud::Command, described_class.new
|
38
|
-
|
39
|
-
describe "#validate_params!" do
|
40
|
-
it "checks for missing config values" do
|
41
|
-
expect(command).to receive(:check_for_missing_config_values!)
|
42
|
-
|
43
|
-
command.validate_params!
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises an exception if the gce_project is missing" do
|
47
|
-
ui = double("ui")
|
48
|
-
expect(tester).to receive(:ui).and_return(ui)
|
49
|
-
expect(tester).to receive(:locate_config_value).with(:gce_project).and_return(nil)
|
50
|
-
expect(ui).to receive(:error).with("The following required parameters are missing: gce_project")
|
51
|
-
expect { tester.check_for_missing_config_values! }.to raise_error(RuntimeError)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#execute_command" do
|
56
|
-
let(:ui) { double("ui") }
|
57
|
-
let(:regions) { [region1] }
|
58
|
-
|
59
|
-
before do
|
60
|
-
allow(command).to receive(:ui).and_return(ui)
|
61
|
-
allow(ui).to receive(:msg)
|
62
|
-
allow(ui).to receive(:color)
|
63
|
-
allow(ui).to receive(:list)
|
64
|
-
expect(service).to receive(:list_regions).and_return(regions)
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when the quota information for the region is nil" do
|
68
|
-
let(:region1) { double("region1", name: "my-region", quotas: nil) }
|
69
|
-
|
70
|
-
it "prints a warning and does not output a list" do
|
71
|
-
expect(ui).to receive(:warn).with("No quota information available for this region.")
|
72
|
-
expect(ui).not_to receive(:list)
|
73
|
-
command.execute_command
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when the quota information for the region is empty" do
|
78
|
-
let(:region1) { double("region1", name: "my-region", quotas: []) }
|
79
|
-
|
80
|
-
it "prints a warning and does not output a list" do
|
81
|
-
expect(ui).to receive(:warn).with("No quota information available for this region.")
|
82
|
-
expect(ui).not_to receive(:list)
|
83
|
-
command.execute_command
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when there is quota information available" do
|
88
|
-
let(:quota1) { double("quota1", metric: "metric1", limit: "limit1", usage: "usage1") }
|
89
|
-
let(:quota2) { double("quota2", metric: "metric2", limit: "limit2", usage: "usage2") }
|
90
|
-
let(:region1) { double("region1", name: "my-region", quotas: [quota1, quota2]) }
|
91
|
-
|
92
|
-
it "formats the output and outputs a list" do
|
93
|
-
expect(command).to receive(:format_name).with("metric1")
|
94
|
-
expect(command).to receive(:format_name).with("metric2")
|
95
|
-
expect(command).to receive(:format_number).with("limit1")
|
96
|
-
expect(command).to receive(:format_number).with("limit2")
|
97
|
-
expect(command).to receive(:format_number).with("usage1")
|
98
|
-
expect(command).to receive(:format_number).with("usage2")
|
99
|
-
expect(ui).to receive(:list).and_return("list_output")
|
100
|
-
expect(ui).to receive(:msg).with("list_output")
|
101
|
-
|
102
|
-
command.execute_command
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "#format_name" do
|
108
|
-
it "returns a properly-formatted name" do
|
109
|
-
expect(command.format_name("something_cool_here")).to eq("Something Cool Here")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "#format_number" do
|
114
|
-
it "returns an integer as a string if the number is a whole number" do
|
115
|
-
expect(command.format_number(2.0)).to eq("2")
|
116
|
-
end
|
117
|
-
|
118
|
-
it "returns the number as-is if it is not a whole number" do
|
119
|
-
expect(command.format_number(2.5)).to eq("2.5")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|