diff options
author | Thom May <thom@chef.io> | 2017-03-29 09:34:09 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2017-03-29 13:25:00 +0100 |
commit | d6dc0b04c6f3c3d8a1461778c0c2604f879b505b (patch) | |
tree | 129eacaa80dd104f542d60b775fd1b665ebb425c /spec/unit/http | |
parent | 50808ca1b1691e45c4017e6e117764ddd617e93f (diff) | |
download | chef-d6dc0b04c6f3c3d8a1461778c0c2604f879b505b.tar.gz |
Retry API requests if using an unsupported versiontm/retryable_api
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'spec/unit/http')
-rw-r--r-- | spec/unit/http/api_versions_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/http/authenticator_spec.rb | 20 |
2 files changed, 30 insertions, 0 deletions
diff --git a/spec/unit/http/api_versions_spec.rb b/spec/unit/http/api_versions_spec.rb index 37f1259d86..91d46763c2 100644 --- a/spec/unit/http/api_versions_spec.rb +++ b/spec/unit/http/api_versions_spec.rb @@ -45,6 +45,7 @@ describe Chef::HTTP::APIVersions do let(:response) do m = double("HttpResponse", :body => response_body) allow(m).to receive(:key?).with("x-ops-server-api-version").and_return(true) + allow(m).to receive(:code).and_return(return_value) allow(m).to receive(:[]) do |key| response_headers[key] end @@ -66,4 +67,13 @@ describe Chef::HTTP::APIVersions do run_api_version_handler expect(Chef::ServerAPIVersions.instance.min_server_version).to eq(0) end + + context "with an unacceptable api version" do + let (:return_value) { "406" } + it "resets the list of supported versions" do + Chef::ServerAPIVersions.instance.set_versions({ "min_version" => 1, "max_version" => 3 }) + run_api_version_handler + expect(Chef::ServerAPIVersions.instance.min_server_version).to eq(0) + end + end end diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb index 7fd2bdc821..5de39523cf 100644 --- a/spec/unit/http/authenticator_spec.rb +++ b/spec/unit/http/authenticator_spec.rb @@ -38,6 +38,26 @@ describe Chef::HTTP::Authenticator do to include({ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION }) end + context "when version_class is provided" do + class V0Class; extend Chef::Mixin::VersionedAPI; minimum_api_version 0; end + class V2Class; extend Chef::Mixin::VersionedAPI; minimum_api_version 2; end + + class AuthFactoryClass + extend Chef::Mixin::VersionedAPIFactory + add_versioned_api_class V0Class + add_versioned_api_class V2Class + end + + let(:class_instance) { Chef::HTTP::Authenticator.new({ version_class: AuthFactoryClass }) } + + it "uses it to select the correct http version" do + Chef::ServerAPIVersions.instance.reset! + expect(AuthFactoryClass).to receive(:best_request_version).and_call_original + expect(class_instance.handle_request(method, url, headers, data)[2]). + to include({ "X-Ops-Server-API-Version" => "2" }) + end + end + context "when api_version is set to something other than the default" do let(:class_instance) { Chef::HTTP::Authenticator.new({ :api_version => "-10" }) } |