incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 1/5] mock driver: allow switching to storage-only driver
Date Sat, 22 Jan 2011 00:02:52 GMT
From: David Lutterkort <lutter@redhat.com>

---
 server/lib/deltacloud/drivers/mock/mock_driver.rb |    9 ++++++++-
 server/tests/drivers/mock/api_test.rb             |   14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 7787c5f..0f91355 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -25,8 +25,15 @@ module Deltacloud
     module Mock
 class MockDriver < Deltacloud::BaseDriver
 
+  # If the provider is set to storage, pretend to be a storage-only
+  # driver
   def supported_collections
-    DEFAULT_COLLECTIONS + [ :buckets, :keys]
+    endpoint = Thread.current[:provider] || ENV['API_PROVIDER']
+    if endpoint == 'storage'
+      [:buckets]
+    else
+      DEFAULT_COLLECTIONS + [:buckets, :keys]
+    end
   end
 
   ( REALMS = [
diff --git a/server/tests/drivers/mock/api_test.rb b/server/tests/drivers/mock/api_test.rb
index a7c451b..7dae8d1 100644
--- a/server/tests/drivers/mock/api_test.rb
+++ b/server/tests/drivers/mock/api_test.rb
@@ -34,5 +34,19 @@ module DeltacloudUnitTest
       JSON::parse(last_response.body)['api'].class.should == Hash
     end
 
+    def test_it_switches_drivers
+      begin
+        ENV.delete("API_PROVIDER")
+        do_xml_request '/api'
+        (last_xml_response/"api/link[rel = 'instances']").first.should_not == nil
+
+        # Switch to storage-only mock driver
+        ENV["API_PROVIDER"] = "storage"
+        do_xml_request '/api'
+        (last_xml_response/"api/link[rel = 'instances']").first.should == nil
+      ensure
+        ENV.delete("API_PROVIDER")
+      end
+    end
   end
 end
-- 
1.7.3.4


Mime
View raw message