You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/03/26 18:58:14 UTC
[28/30] Client: Complete revamp of deltacloud-client unit tests
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/methods/key_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/methods/key_test.rb b/client/tests/methods/key_test.rb
new file mode 100644
index 0000000..4376336
--- /dev/null
+++ b/client/tests/methods/key_test.rb
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Methods::Key do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #keys' do
+ @client.must_respond_to :keys
+ @client.keys.must_be_kind_of Array
+ @client.keys.each { |r| r.must_be_instance_of Deltacloud::Client::Key }
+ end
+
+ it 'supports filtering #keys by :id param' do
+ result = @client.keys(:id => 'test-key')
+ result.must_be_kind_of Array
+ result.size.must_equal 1
+ result.first.must_be_instance_of Deltacloud::Client::Key
+ result = @client.keys(:id => 'unknown')
+ result.must_be_kind_of Array
+ result.size.must_equal 0
+ end
+
+ it 'support #key' do
+ @client.must_respond_to :key
+ result = @client.key('test-key')
+ result.must_be_instance_of Deltacloud::Client::Key
+ lambda { @client.key(nil) }.must_raise Deltacloud::Client::NotFound
+ lambda { @client.key('foo') }.must_raise Deltacloud::Client::NotFound
+ end
+
+ it 'support #create_key and #destroy_key' do
+ @client.must_respond_to :create_key
+ result = @client.create_key('foo')
+ result.must_be_instance_of Deltacloud::Client::Key
+ result.name.must_equal 'foo'
+ result.public_key.wont_be_nil
+ @client.must_respond_to :destroy_key
+ @client.destroy_key(result._id)
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/methods/realm_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/methods/realm_test.rb b/client/tests/methods/realm_test.rb
new file mode 100644
index 0000000..f95ecd3
--- /dev/null
+++ b/client/tests/methods/realm_test.rb
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Methods::Realm do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #realms' do
+ @client.must_respond_to :realms
+ @client.realms.must_be_kind_of Array
+ @client.realms.each { |r| r.must_be_instance_of Deltacloud::Client::Realm }
+ end
+
+ it 'supports filtering #realms by :id' do
+ result = @client.realms(:id => 'eu')
+ result.must_be_kind_of Array
+ result.size.must_equal 1
+ result.first.must_be_instance_of Deltacloud::Client::Realm
+ end
+
+ it 'support #realm' do
+ @client.must_respond_to :realm
+ result = @client.realm('eu')
+ result.must_be_instance_of Deltacloud::Client::Realm
+ lambda { @client.realm(nil) }.must_raise Deltacloud::Client::NotFound
+ lambda { @client.realm('foo') }.must_raise Deltacloud::Client::NotFound
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/methods/storage_snapshot_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/methods/storage_snapshot_test.rb b/client/tests/methods/storage_snapshot_test.rb
new file mode 100644
index 0000000..8fd8f1a
--- /dev/null
+++ b/client/tests/methods/storage_snapshot_test.rb
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Methods::StorageSnapshot do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #storage_snapshots' do
+ @client.must_respond_to :storage_snapshots
+ @client.storage_snapshots.must_be_kind_of Array
+ @client.storage_snapshots.each { |r| r.must_be_instance_of Deltacloud::Client::StorageSnapshot }
+ end
+
+ it 'supports filtering #storage_snapshots by :id param' do
+ result = @client.storage_snapshots(:id => 'snap1')
+ result.must_be_kind_of Array
+ result.size.must_equal 1
+ result.first.must_be_instance_of Deltacloud::Client::StorageSnapshot
+ result = @client.storage_snapshots(:id => 'unknown')
+ result.must_be_kind_of Array
+ result.size.must_equal 0
+ end
+
+ it 'support #storage_snapshot' do
+ @client.must_respond_to :storage_snapshot
+ result = @client.storage_snapshot('snap1')
+ result.must_be_instance_of Deltacloud::Client::StorageSnapshot
+ lambda { @client.storage_snapshot(nil) }.must_raise Deltacloud::Client::NotFound
+ lambda { @client.storage_snapshot('foo') }.must_raise Deltacloud::Client::NotFound
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/methods/storage_volume_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/methods/storage_volume_test.rb b/client/tests/methods/storage_volume_test.rb
new file mode 100644
index 0000000..c5186b8
--- /dev/null
+++ b/client/tests/methods/storage_volume_test.rb
@@ -0,0 +1,81 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Methods::StorageVolume do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #storage_volumes' do
+ @client.must_respond_to :storage_volumes
+ @client.storage_volumes.must_be_kind_of Array
+ @client.storage_volumes.each { |r| r.must_be_instance_of Deltacloud::Client::StorageVolume }
+ end
+
+ it 'supports filtering #storage_volumes by :id param' do
+ result = @client.storage_volumes(:id => 'vol1')
+ result.must_be_kind_of Array
+ result.size.must_equal 1
+ result.first.must_be_instance_of Deltacloud::Client::StorageVolume
+ result = @client.storage_volumes(:id => 'unknown')
+ result.must_be_kind_of Array
+ result.size.must_equal 0
+ end
+
+ it 'support #storage_volume' do
+ @client.must_respond_to :storage_volume
+ result = @client.storage_volume('vol1')
+ result.must_be_instance_of Deltacloud::Client::StorageVolume
+ lambda { @client.storage_volume(nil) }.must_raise Deltacloud::Client::NotFound
+ lambda { @client.storage_volume('foo') }.must_raise Deltacloud::Client::NotFound
+ end
+
+ it 'support #create_volume and #destroy_volume' do
+ @client.must_respond_to :create_storage_volume
+ result = @client.create_storage_volume(:snapshot_id => 'snap1', :name => 'foo123', :capacity => '10')
+ result.must_be_instance_of Deltacloud::Client::StorageVolume
+ result.name.must_equal 'foo123'
+ result.capacity.must_equal '10'
+ @client.must_respond_to :destroy_storage_volume
+ @client.destroy_storage_volume(result._id).must_equal true
+ lambda { @client.storage_volume(result._id) }.must_raise Deltacloud::Client::NotFound
+ end
+
+ it 'support #attach_storage_volume and #detach_storage_volume' do
+ @client.must_respond_to :attach_storage_volume
+ result = @client.attach_storage_volume('vol1', 'inst1', '/dev/sdc')
+ result.must_be_instance_of Deltacloud::Client::StorageVolume
+ result.name.must_equal 'vol1'
+ result.state.must_equal 'IN-USE'
+ result.device.must_equal '/dev/sdc'
+ result.mount[:instance].must_equal 'inst1'
+ @client.must_respond_to :detach_storage_volume
+ result = @client.detach_storage_volume('vol1')
+ result.must_be_instance_of Deltacloud::Client::StorageVolume
+ result.name.must_equal 'vol1'
+ result.state.must_equal 'AVAILABLE'
+ result.device.must_be_nil
+ result.mount[:instance].must_be_nil
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/blob_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/blob_test.rb b/client/tests/models/blob_test.rb
new file mode 100644
index 0000000..5e838a1
--- /dev/null
+++ b/client/tests/models/blob_test.rb
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Blob do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #bucket' do
+ blob = @client.blob('bucket1', 'blob1')
+ blob.bucket.must_be_instance_of Deltacloud::Client::Bucket
+ blob.bucket._id.must_equal 'bucket1'
+ end
+
+ it 'support #[] on Provider' do
+ drv = @client.driver(:ec2)
+ drv['eu-west-1']['s3'].wont_be_empty
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/bucket_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/bucket_test.rb b/client/tests/models/bucket_test.rb
new file mode 100644
index 0000000..2f8dcf1
--- /dev/null
+++ b/client/tests/models/bucket_test.rb
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::StorageVolume do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #blobs' do
+ b = @client.bucket('bucket1')
+ b.must_respond_to :blobs
+ b.blobs.wont_be_empty
+ b.blobs.first.must_be_instance_of Deltacloud::Client::Blob
+ end
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/driver_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/driver_test.rb b/client/tests/models/driver_test.rb
new file mode 100644
index 0000000..e9aa543
--- /dev/null
+++ b/client/tests/models/driver_test.rb
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Driver do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #[] to get providers' do
+ @client.driver(:ec2).must_respond_to '[]'
+ @client.driver(:ec2)['eu-west-1'].wont_be_nil
+ @client.driver(:ec2)['eu-west-1'].must_be_instance_of Deltacloud::Client::Driver::Provider
+ @client.driver(:ec2)['eu-west-1'].entrypoints.wont_be_empty
+ @client.driver(:ec2)['foo'].must_be_nil
+ end
+
+ it 'support #[] on Provider' do
+ drv = @client.driver(:ec2)
+ drv['eu-west-1']['s3'].wont_be_empty
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/hardware_profile_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/hardware_profile_test.rb b/client/tests/models/hardware_profile_test.rb
new file mode 100644
index 0000000..0a72208
--- /dev/null
+++ b/client/tests/models/hardware_profile_test.rb
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::HardwareProfile do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'support #cpu' do
+ @client.hardware_profile('m1-small').must_respond_to :cpu
+ @client.hardware_profile('m1-small').cpu.wont_be_nil
+ @client.hardware_profile('m1-small').cpu.must_respond_to :default
+ @client.hardware_profile('m1-small').cpu.default.wont_be_empty
+ @client.hardware_profile('m1-small').cpu.must_respond_to :kind
+ @client.hardware_profile('m1-small').cpu.kind.wont_be_empty
+ @client.hardware_profile('m1-small').cpu.must_respond_to :unit
+ @client.hardware_profile('m1-small').cpu.unit.wont_be_empty
+ end
+
+ it 'support #memory' do
+ @client.hardware_profile('m1-small').must_respond_to :memory
+ @client.hardware_profile('m1-small').memory.wont_be_nil
+ @client.hardware_profile('m1-small').memory.must_respond_to :default
+ @client.hardware_profile('m1-small').memory.default.wont_be_empty
+ @client.hardware_profile('m1-small').memory.must_respond_to :kind
+ @client.hardware_profile('m1-small').memory.kind.wont_be_empty
+ @client.hardware_profile('m1-small').memory.must_respond_to :unit
+ @client.hardware_profile('m1-small').memory.unit.wont_be_empty
+ end
+
+ it 'support #storage' do
+ @client.hardware_profile('m1-small').must_respond_to :storage
+ @client.hardware_profile('m1-small').storage.wont_be_nil
+ @client.hardware_profile('m1-small').storage.must_respond_to :default
+ @client.hardware_profile('m1-small').storage.default.wont_be_empty
+ @client.hardware_profile('m1-small').storage.must_respond_to :kind
+ @client.hardware_profile('m1-small').storage.kind.wont_be_empty
+ @client.hardware_profile('m1-small').storage.must_respond_to :unit
+ @client.hardware_profile('m1-small').storage.unit.wont_be_empty
+ end
+
+ it 'support #architecture' do
+ @client.hardware_profile('m1-small').must_respond_to :architecture
+ @client.hardware_profile('m1-small').architecture.wont_be_nil
+ @client.hardware_profile('m1-small').architecture.must_respond_to :default
+ @client.hardware_profile('m1-small').architecture.default.wont_be_empty
+ @client.hardware_profile('m1-small').architecture.must_respond_to :kind
+ @client.hardware_profile('m1-small').architecture.kind.wont_be_empty
+ @client.hardware_profile('m1-small').architecture.must_respond_to :unit
+ @client.hardware_profile('m1-small').architecture.unit.wont_be_empty
+ end
+
+ it 'support #opaque?' do
+ @client.hardware_profile('opaque').opaque?.must_equal true
+ @client.hardware_profile('m1-small').opaque?.must_equal false
+ end
+
+
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/image_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/image_test.rb b/client/tests/models/image_test.rb
new file mode 100644
index 0000000..0879b35
--- /dev/null
+++ b/client/tests/models/image_test.rb
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::Image do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'support #original_body' do
+ img = @client.image('img1')
+ img.original_body.must_be_instance_of Faraday::Response
+ end
+
+ it 'supports #hardware_profiles' do
+ img = @client.image('img1')
+ img.must_respond_to :hardware_profiles
+ img.hardware_profiles.wont_be_empty
+ img.hardware_profiles.first.must_be_instance_of Deltacloud::Client::HardwareProfile
+ end
+
+ it 'supports #is_compatible?' do
+ img = @client.image('img1')
+ img.must_respond_to 'is_compatible?'
+ img.is_compatible?('m1-small').must_equal true
+ img.is_compatible?('m1-large').must_equal true
+ end
+
+ it 'supports #lunch_image' do
+ img = @client.image('img1')
+ img.must_respond_to :launch
+ inst = img.launch(:hwp_id => 'm1-large')
+ inst.must_be_instance_of Deltacloud::Client::Instance
+ inst.hardware_profile_id.must_equal 'm1-large'
+ inst.stop!
+ inst.destroy!
+ end
+
+ it 'supports #id' do
+ img = @client.image('img1')
+ lambda { img.id.must_equal 'img1' }.must_output nil, "[DEPRECATION] `id` is deprecated because of possible conflict with Object#id. Use `_id` instead.\n"
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/models/storage_volume_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/models/storage_volume_test.rb b/client/tests/models/storage_volume_test.rb
new file mode 100644
index 0000000..2108684
--- /dev/null
+++ b/client/tests/models/storage_volume_test.rb
@@ -0,0 +1,52 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative '../test_helper'
+
+describe Deltacloud::Client::StorageVolume do
+
+ before do
+ VCR.insert_cassette(__name__)
+ @client = new_client
+ end
+
+ after do
+ VCR.eject_cassette
+ end
+
+ it 'supports #attached?' do
+ vol = @client.storage_volume('vol1')
+ vol.attached?.must_equal false
+ vol.attach('inst1')
+ vol.attached?.must_equal true
+ vol.detach!
+ end
+
+ it 'supports #snapshot!' do
+ vol = @client.storage_volume('vol1')
+ vol.snapshot!.must_be_instance_of Deltacloud::Client::StorageSnapshot
+ end
+
+ it 'supports #instance' do
+ vol = @client.storage_volume('vol2')
+ vol.attached?.must_equal false
+ vol.attach('inst1')
+ vol.attached?.must_equal true
+ vol.instance.must_be_instance_of Deltacloud::Client::Instance
+ vol.instance._id.must_equal 'inst1'
+ vol.detach!
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/realms_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/realms_test.rb b/client/tests/realms_test.rb
deleted file mode 100644
index 0017325..0000000
--- a/client/tests/realms_test.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-require 'rubygems'
-require 'require_relative' if RUBY_VERSION =~ /^1\.8/
-
-require_relative './test_helper.rb'
-
-describe "Realms" do
-
- before do
- @client = DeltaCloud.new(API_NAME, API_PASSWORD, API_URL)
- end
-
- it "should allow retrieval of all realms" do
- realms = @client.realms
- realms.wont_be_empty
- realms.each do |realm|
- realm.uri.wont_be_nil
- realm.uri.must_be_kind_of String
- realm.id.wont_be_nil
- realm.id.must_be_kind_of String
- realm.name.wont_be_nil
- realm.name.must_be_kind_of String
- end
- end
-
-
- it "should allow fetching a realm by id" do
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
- realm = client.realm( 'us' )
- realm.wont_be_nil
- realm.id.must_equal 'us'
- realm.name.must_equal 'United States'
- realm.state.must_equal 'AVAILABLE'
- realm = client.realm( 'eu' )
- realm.wont_be_nil
- realm.id.must_equal 'eu'
- realm.name.must_equal 'Europe'
- realm.state.must_equal 'AVAILABLE'
- end
- end
-
- it "should allow fetching a realm by URI" do
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
- realm = client.fetch_realm( API_URL + '/realms/us' )
- realm.wont_be_nil
- realm.id.must_equal 'us'
- end
- end
-
-end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/storage_snapshot_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/storage_snapshot_test.rb b/client/tests/storage_snapshot_test.rb
deleted file mode 100644
index aefe9a5..0000000
--- a/client/tests/storage_snapshot_test.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-require 'rubygems'
-require 'require_relative' if RUBY_VERSION =~ /^1\.8/
-
-require_relative './test_helper.rb'
-
-describe "Storage Snapshot" do
-
- it "allow retrieval of all storage volumes owned by the current user" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_snapshots = c.storage_snapshots
- storage_snapshots.wont_be_nil
- storage_snapshots.wont_be_empty
- ids = storage_snapshots.collect{|e| e.id}
- ids.size.must_equal 3
- ids.must_include 'snap2'
- ids.must_include 'snap3'
- end
- end
-
- it "should allow fetching of storage volume by id" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_snapshot = c.storage_snapshot( 'snap2' )
- storage_snapshot.wont_be_nil
- storage_snapshot.id.must_equal 'snap2'
- storage_snapshot.storage_volume.capacity.must_equal 1.0
- storage_snapshot.storage_volume.id.must_equal 'vol2'
- end
- end
-
- it "should allow fetching of storage volume by URI" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_snapshot = c.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' )
- storage_snapshot.wont_be_nil
- storage_snapshot.id.must_equal 'snap2'
- storage_snapshot.storage_volume.capacity.must_equal 1.0
- storage_snapshot.storage_volume.id.must_equal 'vol2'
- end
- end
-
- it "should return nil for unknown storage volume by ID" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- lambda {
- client.connect do |c|
- c.storage_snapshot( "bogus" )
- end
- }.must_raise DeltaCloud::HTTPError::NotFound
- end
-
- it "should return nil for unknown storage volume by URI" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- lambda {
- client.connect do |c|
- c.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' )
- end
- }.must_raise DeltaCloud::HTTPError::NotFound
- end
-
-end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/storage_volume_test.rb
----------------------------------------------------------------------
diff --git a/client/tests/storage_volume_test.rb b/client/tests/storage_volume_test.rb
deleted file mode 100644
index 95c6d18..0000000
--- a/client/tests/storage_volume_test.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-require 'rubygems'
-require 'require_relative' if RUBY_VERSION =~ /^1\.8/
-
-require_relative './test_helper.rb'
-
-describe "Storage Volumes" do
-
- it "allow retrieval of all storage volumes owned by the current user" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_volumes = c.storage_volumes
- storage_volumes.wont_be_nil
- storage_volumes.wont_be_nil
- ids = storage_volumes.collect{|e| e.id}
- ids.size.must_equal 3
- ids.must_include 'vol1'
- ids.must_include 'vol3'
- end
- end
-
- it "should allow fetching of storage volume by id" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_volume = c.storage_volume( 'vol3' )
- storage_volume.id.must_equal 'vol3'
- storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3'
- storage_volume.capacity.must_equal 1.0
- storage_volume.device.must_equal '/dev/sda1'
- storage_volume.instance.wont_be_nil
- storage_volume.instance.id.must_equal 'inst1'
- ip = storage_volume.instance
- ip.hardware_profile.architecture.value.must_equal 'i386'
- end
- end
-
- it "should allow fetching of storage volume by URI" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |c|
- storage_volume = c.fetch_storage_volume( API_URL + '/storage_volumes/vol3' )
- storage_volume.wont_be_nil
- storage_volume.id.must_equal 'vol3'
- storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3'
- storage_volume.capacity.must_equal 1.0
- storage_volume.device.must_equal '/dev/sda1'
- storage_volume.instance.wont_be_nil
- storage_volume.instance.id.must_equal 'inst1'
- ip = storage_volume.instance
- ip.hardware_profile.architecture.value.must_equal 'i386'
- end
- end
-
- it "should raise exception for unknown storage volume by ID" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- lambda {
- client.connect do |c|
- c.storage_volume( 'bogus' )
- end
- }.must_raise DeltaCloud::HTTPError::NotFound
- end
-
- it "should raise exception for unknown storage volume by URI" do
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- lambda {
- client.connect do |c|
- client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' )
- end
- }.must_raise DeltaCloud::HTTPError::NotFound
- end
-
-
-end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3d865944/client/tests/test_helper.rb
----------------------------------------------------------------------
diff --git a/client/tests/test_helper.rb b/client/tests/test_helper.rb
index 9419b4a..a238a73 100644
--- a/client/tests/test_helper.rb
+++ b/client/tests/test_helper.rb
@@ -1,16 +1,64 @@
-require 'rubygems'
-require 'require_relative' if RUBY_VERSION =~ /^1\.8/
-require 'minitest/autorun'
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'bundler'
+
+Bundler.setup(:default, :development)
+Bundler.require(:default, :development)
-require_relative '../lib/deltacloud.rb'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+if ENV['COVERAGE']
+ require 'simplecov'
+ SimpleCov.command_name 'tests:units'
+ SimpleCov.start do
+ add_group "Models", "lib/deltacloud/client/models"
+ add_group "Methods", "lib/deltacloud/client/methods"
+ add_group "Helpers", "lib/deltacloud/client/helpers"
+ add_group "Extensions", "lib/deltacloud/core_ext"
+ add_filter "tests/"
+ end
+end
+
+require 'minitest/autorun'
+#
+# Change this at will
+#
+DELTACLOUD_URL = ENV['API_URL'] || 'http://localhost:3001/api'
+DELTACLOUD_USER = 'mockuser'
+DELTACLOUD_PASSWORD = 'mockpassword'
-# Configuration:
+def new_client
+ Deltacloud::Client(DELTACLOUD_URL, DELTACLOUD_USER, DELTACLOUD_PASSWORD)
+end
-API_HOST = 'localhost'
-API_PORT = '3001'
-API_PATH = '/api'
+unless ENV['NO_VCR']
+ require 'vcr'
+ VCR.configure do |c|
+ c.hook_into :faraday
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
+ c.default_cassette_options = { :record => :new_episodes }
+ end
+end
-API_NAME = 'mockuser'
-API_PASSWORD = 'mockpassword'
+require_relative './../lib/deltacloud/client'
-API_URL = "http://#{API_HOST}:#{API_PORT}#{API_PATH}"
+def cleanup_instances(inst_arr)
+ inst_arr.each do |i|
+ i.reload!
+ i.stop! unless i.is_stopped?
+ i.destroy!
+ end
+end