summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/http/api_versions_spec.rb10
-rw-r--r--spec/unit/http/authenticator_spec.rb20
-rw-r--r--spec/unit/mixin/versioned_api_spec.rb8
3 files changed, 38 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" }) }
diff --git a/spec/unit/mixin/versioned_api_spec.rb b/spec/unit/mixin/versioned_api_spec.rb
index c709871919..e8b65158c4 100644
--- a/spec/unit/mixin/versioned_api_spec.rb
+++ b/spec/unit/mixin/versioned_api_spec.rb
@@ -100,6 +100,14 @@ describe Chef::Mixin::VersionedAPIFactory do
end
end
+ describe "#possible_requests" do
+ it "returns the number of registered classes" do
+ factory_class.add_versioned_api_class V2Class
+ factory_class.add_versioned_api_class V3Class
+ expect(factory_class.possible_requests).to eq(2)
+ end
+ end
+
describe "#new" do
it "creates an instance of the versioned class" do
factory_class.add_versioned_api_class V2Class