deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [11/15] Gogrid tests: use credentials from config file
Date Tue, 28 Aug 2012 00:16:55 GMT
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6778198/server/tests/drivers/gogrid/fixtures/test_0006_must_return_nil_when_retrieving_a_single_nonexistent_image.yml
----------------------------------------------------------------------
diff --git a/server/tests/drivers/gogrid/fixtures/test_0006_must_return_nil_when_retrieving_a_single_nonexistent_image.yml
b/server/tests/drivers/gogrid/fixtures/test_0006_must_return_nil_when_retrieving_a_single_nonexistent_image.yml
new file mode 100644
index 0000000..2b6b212
--- /dev/null
+++ b/server/tests/drivers/gogrid/fixtures/test_0006_must_return_nil_when_retrieving_a_single_nonexistent_image.yml
@@ -0,0 +1,37 @@
+--- 
+recorded_with: VCR 2.2.4
+http_interactions: 
+- request: 
+    method: get
+    uri: https://api.gogrid.com/api/grid/image/get?api_key=b5e87458eb2d3297&format=json&id=unknown&sig=f6f5f58de1399256aabfaa34a201a782&v=1.9
+    body: 
+      string: ""
+    headers: 
+      Accept: 
+      - "*/*"
+  response: 
+    status: 
+      code: 400
+      message: Bad Request
+    headers: 
+      Content-Length: 
+      - "221"
+      Accept-Ranges: 
+      - bytes
+      Server: 
+      - Apache-Coyote/1.1
+      Content-Type: 
+      - text/html
+      Connection: 
+      - close
+      - close
+      Date: 
+      - Sat, 25 Aug 2012 00:35:09 GMT
+      Set-Cookie: 
+      - JSESSIONID=62FB4862E9F9407A56FAE949E6B75736; Path=/api; Secure
+      X-Mashery-Responder: 
+      - mashery-web4-lax.mashery.com
+    body: 
+      string: "{\"summary\":{\"total\":1,\"start\":0,\"returned\":1},\"status\":\"failure\",\"method\":\"/grid/image/get\",\"list\":[{\"message\":\"No
object found that matches your input criteria.\",\"object\":\"error\",\"errorcode\":\"IllegalArgumentException\"}]}"
+    http_version: 
+  recorded_at: Sat, 25 Aug 2012 00:35:09 GMT

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6778198/server/tests/drivers/gogrid/hardware_profiles_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/gogrid/hardware_profiles_test.rb b/server/tests/drivers/gogrid/hardware_profiles_test.rb
index 2fbc0b3..67bb9a7 100644
--- a/server/tests/drivers/gogrid/hardware_profiles_test.rb
+++ b/server/tests/drivers/gogrid/hardware_profiles_test.rb
@@ -6,7 +6,6 @@ require_relative 'common'
 describe 'GoGrid Hardware Profiles' do
 
   before do
-    Time.be(DateTime.parse("2012-08-23 11:58:00 +0000").to_s)
     @driver = Deltacloud::new(:gogrid, credentials)
     VCR.insert_cassette __name__
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6778198/server/tests/drivers/gogrid/images_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/gogrid/images_test.rb b/server/tests/drivers/gogrid/images_test.rb
index a726595..ccc478c 100644
--- a/server/tests/drivers/gogrid/images_test.rb
+++ b/server/tests/drivers/gogrid/images_test.rb
@@ -6,7 +6,6 @@ require_relative 'common'
 describe 'GoGridDriver Images' do
 
   before do
-    Time.be(DateTime.parse("2012-08-23 11:45:00 +0000").to_s)
     @driver = Deltacloud::new(:gogrid, credentials)
     VCR.insert_cassette __name__
   end
@@ -27,19 +26,32 @@ describe 'GoGridDriver Images' do
   end
 
   it 'must allow to filter images' do
-    @driver.images(:id => '9928').wont_be_empty
-    @driver.images(:id => '9928').must_be_kind_of Array
-    @driver.images(:id => '9928').size.must_equal 1
-    @driver.images(:id => '9928').first.id.must_equal '9928'
-    @driver.images(:id => '9928').first.name.must_equal 'CentOS 5.6 (32-bit) w/ None'
+    img = @driver.images.first
+    img.wont_be_nil
+
+    imgs = @driver.images(:id => img.id)
+    imgs.wont_be_empty
+    imgs.must_be_kind_of Array
+    imgs.size.must_equal 1
+    imgs.first.id.must_equal img.id
+    imgs.first.name.must_equal img.name
+  end
+
+  it 'must return an empty array for nonexistent image' do
     @driver.images(:id => 'unknown').must_be_empty
   end
 
   it 'must allow to retrieve single image' do
-    @driver.image(:id => '9928').wont_be_nil
-    @driver.image(:id => '9928').must_be_kind_of Image
-    @driver.image(:id => '9928').id.must_equal '9928'
-    @driver.image(:id => 'unknown').must_be_nil
+    some_img = @driver.images.first
+    some_img.wont_be_nil
+    by_id = @driver.image(:id => some_img.id)
+
+    by_id.wont_be_nil
+    by_id.must_be_kind_of Image
+    by_id.id.must_equal some_img.id
   end
 
+  it 'must return nil when retrieving a single nonexistent image' do
+    @driver.image(:id => 'unknown').must_be_nil
+  end
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6778198/server/tests/drivers/gogrid/instances_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/gogrid/instances_test.rb b/server/tests/drivers/gogrid/instances_test.rb
index a4dbd66..a967122 100644
--- a/server/tests/drivers/gogrid/instances_test.rb
+++ b/server/tests/drivers/gogrid/instances_test.rb
@@ -5,8 +5,9 @@ require_relative 'common'
 
 describe 'GoGridDriver Instances' do
 
+  INSTANCE_ID = "test-instance"
+
   before do
-    Time.be(DateTime.parse("2012-08-23 12:12:00 +0000").to_s)
     @driver = Deltacloud::new(:gogrid, credentials)
     VCR.insert_cassette __name__
   end
@@ -15,6 +16,46 @@ describe 'GoGridDriver Instances' do
     VCR.eject_cassette
   end
 
+  def self.create_test_instance
+    driver = Deltacloud::new(:gogrid, credentials)
+    VCR.use_cassette "instances_create_test_instance" do
+      @@instance = driver.instance(:id => INSTANCE_ID)
+      @@instance ||= driver.create_instance(fixed_image_id,
+                                            :name=> INSTANCE_ID)
+    end
+  end
+
+  # Destroy test instance when all test are done
+  def self.__name__
+    # record_retries below calls this
+    "instances_test_class"
+  end
+
+  def self.destroy_test_instance
+    driver = Deltacloud::new(:gogrid, credentials)
+
+    # Go fast when running off a recording
+    opts = record_retries
+    opts[:time_between_retry] = VCR.configuration.default_cassette_options[:record] == :none
? 0 : 60
+    @@instance.wait_for!(driver, opts) do |i|
+      i.actions.include?(:destroy)
+    end
+
+    VCR.use_cassette "instances_destroy_test_instance" do
+      driver.destroy_instance(@@instance.id)
+      @@instance = nil
+    end
+  end
+
+  # Setup/teardown before/after all tests
+  create_test_instance
+
+  MiniTest::Unit::after_tests { destroy_test_instance }
+
+  let :instance do
+    @@instance
+  end
+
   it 'must throw error when wrong credentials' do
     Proc.new do
       @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
@@ -27,22 +68,26 @@ describe 'GoGridDriver Instances' do
   end
 
   it 'must allow to filter instances' do
-    @driver.instances(:id => 'test').wont_be_empty
-    @driver.instances(:id => 'test').must_be_kind_of Array
-    @driver.instances(:id => 'test').size.must_equal 1
-    @driver.instances(:id => 'test').first.id.must_equal 'test'
-    @driver.instances(:owner_id => '9bbf139b8b57d967').wont_be_empty
-    @driver.instances(:owner_id => '9bbf139b8b57d967').each do |inst|
-      inst.owner_id.must_equal '9bbf139b8b57d967'
+    by_id = @driver.instances(:id => instance.id)
+    by_id.wont_be_empty
+    by_id.must_be_kind_of Array
+    by_id.size.must_equal 1
+    by_id.first.id.must_equal instance.id
+
+    by_owner = @driver.instances(:owner_id => instance.owner_id)
+    by_owner.wont_be_empty
+    by_owner.each do |inst|
+      inst.owner_id.must_equal instance.owner_id
     end
+
     @driver.instances(:id => 'unknown').must_be_empty
   end
 
   it 'must allow to retrieve single instance' do
-    @driver.instance(:id => 'test').wont_be_nil
-    @driver.instance(:id => 'test').must_be_kind_of Instance
-    @driver.instance(:id => 'test').id.must_equal 'test'
-    @driver.instance(:id => 'unknown').must_be_nil
+    by_id = @driver.instance(:id => instance.id)
+    by_id.wont_be_nil
+    by_id.must_be_kind_of Instance
+    by_id.id.must_equal instance.id
+    @driver.instance(:id => "unknown").must_be_nil
   end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6778198/server/tests/drivers/gogrid/realms_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/gogrid/realms_test.rb b/server/tests/drivers/gogrid/realms_test.rb
index 7e4bbd3..442fae5 100644
--- a/server/tests/drivers/gogrid/realms_test.rb
+++ b/server/tests/drivers/gogrid/realms_test.rb
@@ -6,7 +6,6 @@ require_relative 'common'
 describe 'GoGridDriver Realms' do
 
   before do
-    Time.be(DateTime.parse("2012-08-23 11:30:00 +0000").to_s)
     @driver = Deltacloud::new(:gogrid, credentials)
     VCR.insert_cassette __name__
   end


Mime
View raw message