diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-02-26 20:53:49 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-02-26 20:53:49 -0800 |
commit | b6d002bfa7997ca1e10780efa18f0e7497b8a158 (patch) | |
tree | 3089e635e1761893f204232e5fe273bbf46a7fae | |
parent | 7a2bae0dd881f1cdfd68d5e9f6cddbfc063bb2b7 (diff) | |
download | ohai-b6d002bfa7997ca1e10780efa18f0e7497b8a158.tar.gz |
Fix GCE specs and chefstyle
-rw-r--r-- | lib/ohai/mixin/gce_metadata.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/gce_spec.rb | 15 |
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb index deffee8d..53d4ec10 100644 --- a/lib/ohai/mixin/gce_metadata.rb +++ b/lib/ohai/mixin/gce_metadata.rb @@ -61,7 +61,7 @@ module Ohai def http_get(uri) conn = Net::HTTP.start(GCE_METADATA_ADDR) conn.read_timeout = 6 - conn.get(uri, initheader = { 'Metadata-Flavor' => 'Google' }) + conn.get(uri, initheader = { "Metadata-Flavor" => "Google" }) end def fetch_metadata(id = "") diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb index 4e1d4927..1d3ae838 100644 --- a/spec/unit/plugins/gce_spec.rb +++ b/spec/unit/plugins/gce_spec.rb @@ -25,15 +25,20 @@ describe Ohai::System, "plugin gce" do shared_examples_for "!gce" do it "should NOT attempt to fetch the gce metadata" do - expect(@plugin).not_to receive(:http_client) + expect(@plugin).not_to receive(:http_get) + @plugin.run + end + + it "should NOT set gce attributes" do + expect(@plugin[:gce]).to be_nil @plugin.run end end shared_examples_for "gce" do before(:each) do - @http_client = double("Net::HTTP client") - allow(@plugin).to receive(:http_client).and_return(@http_client) + @http_get = double("Net::HTTP client") + allow(@plugin).to receive(:http_get).and_return(double("Net::HTTP Response", :body => '{"instance":{"hostname":"test-host"}}', :code => "200")) allow(IO).to receive(:select).and_return([[], [1], []]) t = double("connection") allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS) @@ -42,10 +47,6 @@ describe Ohai::System, "plugin gce" do end it "should recursively fetch and properly parse json metadata" do - expect(@http_client).to receive(:get). - with("/computeMetadata/v1beta1/?recursive=true/"). - and_return(double("Net::HTTP Response", :body => '{"instance":{"hostname":"test-host"}}', :code => "200")) - @plugin.run expect(@plugin[:gce]).not_to be_nil |