diff options
author | PrajaktaPurohit <prajakta@opscode.com> | 2014-01-19 18:07:17 -0800 |
---|---|---|
committer | Prajakta Purohit <prajakta@opscode.com> | 2014-02-07 15:31:10 -0800 |
commit | a4cdce667a1bc1828eea875bdf3f49af6d96da70 (patch) | |
tree | ccf5fb1bf44f0eda5ad0470f0957dd31864c62f0 /spec/unit/knife_spec.rb | |
parent | 29e732d97ec7e28b2111aca9f93edfd1bc257c2d (diff) | |
download | chef-a4cdce667a1bc1828eea875bdf3f49af6d96da70.tar.gz |
- Adding X-Remote-Request-Id to the set of headers for every request from CCR and
knife that will be sent to erchef
- Each knife request has a different X-Remote-Request-Id, where as it
remains the same for all requests originating from the same chef-client
run.
- Adding and fixing tests
Diffstat (limited to 'spec/unit/knife_spec.rb')
-rw-r--r-- | spec/unit/knife_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index daace18106..8bf85bf604 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -22,6 +22,7 @@ module KnifeSpecs end require 'spec_helper' +require 'uri' describe Chef::Knife do before(:each) do @@ -141,6 +142,60 @@ describe Chef::Knife do end + describe "the headers include X-Remote-Request-Id" do + + let(:headers) {{"Accept"=>"application/json", + "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + 'X-Chef-Version' => Chef::VERSION, + "Host"=>"api.opscode.piab:443", + "X-REMOTE-REQUEST-ID"=>request_id}} + + let(:request_id) {"1234"} + + let(:request_mock) { {} } + + let(:rest) do + Net::HTTP.stub(:new).and_return(http_client) + Chef::RequestID.instance.stub(:request_id).and_return(request_id) + Chef::Config.stub(:chef_server_url).and_return("https://api.opscode.piab") + command = Chef::Knife.run(%w{test yourself}) + rest = command.noauth_rest + rest + end + + let!(:http_client) do + http_client = Net::HTTP.new(url.host, url.port) + http_client.stub(:request).and_yield(http_response).and_return(http_response) + http_client + end + + let(:url) { URI.parse("https://api.opscode.piab") } + + let(:http_response) do + http_response = Net::HTTPSuccess.new("1.1", "200", "successful rest req") + http_response.stub(:read_body) + http_response.stub(:body).and_return(body) + http_response["Content-Length"] = body.bytesize.to_s + http_response + end + + let(:body) { "ninja" } + + before(:each) do + Chef::Config[:chef_server_url] = "https://api.opscode.piab" + if KnifeSpecs.const_defined?(:TestYourself) + KnifeSpecs.send :remove_const, :TestYourself + end + Kernel.load(File.join(CHEF_SPEC_DATA, 'knife_subcommand', 'test_yourself.rb')) + Chef::Knife.subcommands.each { |name, klass| Chef::Knife.subcommands.delete(name) unless klass.kind_of?(Class) } + end + + it "confirms that the headers include X-Remote-Request-Id" do + Net::HTTP::Get.should_receive(:new).with("/monkey", headers).and_return(request_mock) + rest.get_rest("monkey") + end + end + describe "when running a command" do before(:each) do if KnifeSpecs.const_defined?(:TestYourself) |