Skip to content

Commit

Permalink
Merge pull request #106 from ChaosCloud/abk
Browse files Browse the repository at this point in the history
make public_ip work for any case 'none' at 'instance_access_configs_for'
  • Loading branch information
JJ Asghar committed Oct 23, 2016
2 parents e320d6e + 81220d2 commit a9eedaf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .rspec
@@ -1,3 +1,3 @@
--color
-fdocumentation

--color
-fdocumentation

1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ sudo: false
rvm:
- 2.2.5
- 2.3.1
- ruby-head
branches:
only:
- master
Expand Down
4 changes: 3 additions & 1 deletion lib/chef/knife/cloud/google_service.rb
Expand Up @@ -408,7 +408,9 @@ def instance_network_interfaces_for(options)
end

def instance_access_configs_for(public_ip)
return [] if public_ip.nil? || public_ip == "NONE"
public_ip.downcase! if public_ip.respond_to?(:downcase)

return [] if public_ip.nil? || public_ip == "none"

access_config = Google::Apis::ComputeV1::AccessConfig.new
access_config.name = "External NAT"
Expand Down
28 changes: 28 additions & 0 deletions spec/cloud/google_service_spec.rb
Expand Up @@ -677,6 +677,34 @@
end
end

describe "#instance_access_configs_for" do
let(:interface) { double("interface" ) }

context "for None public_ip" do
it "empty public_ip none|None|NONE|~" do
expect(service.instance_access_configs_for("none")).to eq([])

expect(service.instance_access_configs_for("None")).to eq([])

expect(service.instance_access_configs_for("NONE")).to eq([])
end
end

context "for valid public_ip" do
it "valid public_ip" do
access_config = service.instance_access_configs_for("8.8.8.8")
expect(access_config.first.nat_ip).to eq("8.8.8.8")
end
end

context "for invalid public_ip" do
it "empty public_ip none|None|NONE|~" do
access_config = service.instance_access_configs_for("oh no not a valid IP")
expect(access_config.first.nat_ip).to eq(nil)
end
end
end

describe "#network_url_for" do
it "returns a properly-formatted network URL" do
expect(service.network_url_for("test_network")).to eq("projects/test_project/global/networks/test_network")
Expand Down

0 comments on commit a9eedaf

Please sign in to comment.