diff options
author | Mike Javorski <mike.javorski@gmail.com> | 2013-02-05 10:02:04 -0800 |
---|---|---|
committer | Mike Javorski <mike.javorski@gmail.com> | 2013-02-06 19:19:04 -0800 |
commit | 44f249531ad23df7610d3db98bf5dc2615c5d219 (patch) | |
tree | aee8b51cac86cc828982ac67b60f48e084b87f5f | |
parent | 505c11d9c53dc19c8604266608782292eeaf8bef (diff) | |
download | ohai-44f249531ad23df7610d3db98bf5dc2615c5d219.tar.gz |
Add proper response codes to http request mocks
-rw-r--r-- | spec/unit/plugins/ec2_spec.rb | 48 | ||||
-rw-r--r-- | spec/unit/plugins/eucalyptus_spec.rb | 18 |
2 files changed, 33 insertions, 33 deletions
diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb index 51f15792..4c9b9144 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -47,16 +47,16 @@ describe Ohai::System, "plugin ec2" do it "should recursively fetch all the ec2 metadata" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/"). - and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups")) + and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/instance_type"). - and_return(mock("Net::HTTP Response", :body => "c1.medium")) + and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/ami_id"). - and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934")) + and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/security-groups"). - and_return(mock("Net::HTTP Response", :body => "group1\ngroup2")) + and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/user-data/"). and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) @@ -71,22 +71,22 @@ describe Ohai::System, "plugin ec2" do it "should parse ec2 network/ directory as a multi-level hash" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/"). - and_return(mock("Net::HTTP Response", :body => "network/")) + and_return(mock("Net::HTTP Response", :body => "network/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/"). - and_return(mock("Net::HTTP Response", :body => "interfaces/")) + and_return(mock("Net::HTTP Response", :body => "interfaces/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/interfaces/"). - and_return(mock("Net::HTTP Response", :body => "macs/")) + and_return(mock("Net::HTTP Response", :body => "macs/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/interfaces/macs/"). - and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/")) + and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/"). - and_return(mock("Net::HTTP Response", :body => "public_hostname")) + and_return(mock("Net::HTTP Response", :body => "public_hostname", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname"). - and_return(mock("Net::HTTP Response", :body => "server17.opscode.com")) + and_return(mock("Net::HTTP Response", :body => "server17.opscode.com", :code => "200")) @ohai._require_plugin("ec2") @ohai[:ec2].should_not be_nil @@ -96,16 +96,16 @@ describe Ohai::System, "plugin ec2" do it "should parse ec2 iam/ directory and its JSON files properly" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/"). - and_return(mock("Net::HTTP Response", :body => "iam/")) + and_return(mock("Net::HTTP Response", :body => "iam/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/iam/"). - and_return(mock("Net::HTTP Response", :body => "security-credentials/")) + and_return(mock("Net::HTTP Response", :body => "security-credentials/", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/iam/security-credentials/"). - and_return(mock("Net::HTTP Response", :body => "MyRole")) + and_return(mock("Net::HTTP Response", :body => "MyRole", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/iam/security-credentials/MyRole"). - and_return(mock("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}")) + and_return(mock("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200")) @ohai._require_plugin("ec2") @ohai[:ec2].should_not be_nil @@ -116,7 +116,7 @@ describe Ohai::System, "plugin ec2" do it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/"). - and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../")) + and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../", :code => "200")) @http_client.should_not_receive(:get). with("/2012-01-12/meta-data/.") @@ -131,16 +131,16 @@ describe Ohai::System, "plugin ec2" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/path1/"). - and_return(mock("Net::HTTP Response", :body => "")) + and_return(mock("Net::HTTP Response", :body => "", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/path2/"). - and_return(mock("Net::HTTP Response", :body => "")) + and_return(mock("Net::HTTP Response", :body => "", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/path3/"). - and_return(mock("Net::HTTP Response", :body => "")) + and_return(mock("Net::HTTP Response", :body => "", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/path4/"). - and_return(mock("Net::HTTP Response", :body => "")) + and_return(mock("Net::HTTP Response", :body => "", :code => "200")) @ohai._require_plugin("ec2") @@ -164,7 +164,7 @@ describe Ohai::System, "plugin ec2" do @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"} end end - + describe "with ec2 cloud file" do it_should_behave_like "ec2" @@ -178,16 +178,16 @@ describe Ohai::System, "plugin ec2" do describe "without cloud file" do it_should_behave_like "!ec2" - + before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false) File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false) end end - + describe "with rackspace cloud file" do it_should_behave_like "!ec2" - + before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('') @@ -195,5 +195,5 @@ describe Ohai::System, "plugin ec2" do File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('') end end - + end diff --git a/spec/unit/plugins/eucalyptus_spec.rb b/spec/unit/plugins/eucalyptus_spec.rb index d78b9951..7a108d4b 100644 --- a/spec/unit/plugins/eucalyptus_spec.rb +++ b/spec/unit/plugins/eucalyptus_spec.rb @@ -40,16 +40,16 @@ describe Ohai::System, "plugin eucalyptus" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/"). - and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups")) + and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/instance_type"). - and_return(mock("Net::HTTP Response", :body => "c1.medium")) + and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/ami_id"). - and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934")) + and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/meta-data/security-groups"). - and_return(mock("Net::HTTP Response", :body => "group1\ngroup2")) + and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200")) @http_client.should_receive(:get). with("/2012-01-12/user-data/"). and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) @@ -84,7 +84,7 @@ describe Ohai::System, "plugin eucalyptus" do @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } } end end - + describe "with eucalyptus cloud file" do it_should_behave_like "eucalyptus" @@ -98,16 +98,16 @@ describe Ohai::System, "plugin eucalyptus" do describe "without cloud file" do it_should_behave_like "!eucalyptus" - + before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false) File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false) end end - + describe "with ec2 cloud file" do it_should_behave_like "!eucalyptus" - + before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('') @@ -115,5 +115,5 @@ describe Ohai::System, "plugin eucalyptus" do File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('') end end - + end |