deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/4] git commit: Tests: Added tests for Deltacloud models
Date Wed, 18 Jul 2012 08:27:46 GMT
Updated Branches:
  refs/heads/master 381622059 -> 7b568e5bf


Tests: Added tests for Deltacloud models


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/7b568e5b
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/7b568e5b
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/7b568e5b

Branch: refs/heads/master
Commit: 7b568e5bf83e3055d71885b0b24cf41d7437cd14
Parents: 2c9c6d6
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Jul 17 15:51:50 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Jul 18 10:28:14 2012 +0200

----------------------------------------------------------------------
 server/tests/drivers/models/address_test.rb        |   18 +++++
 server/tests/drivers/models/base_test.rb           |   34 ++++++++++
 server/tests/drivers/models/blob_test.rb           |   18 +++++
 .../tests/drivers/models/hardware_profile_test.rb  |   52 +++++++++++++++
 .../tests/drivers/models/instance_profile_test.rb  |   21 ++++++
 server/tests/drivers/models/instance_test.rb       |   29 ++++++++
 server/tests/drivers/models/keys_test.rb           |   25 +++++++
 server/tests/drivers/models/metrics_test.rb        |   20 ++++++
 8 files changed, 217 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/address_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/address_test.rb b/server/tests/drivers/models/address_test.rb
new file mode 100644
index 0000000..eae9a02
--- /dev/null
+++ b/server/tests/drivers/models/address_test.rb
@@ -0,0 +1,18 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
+
+describe Address do
+
+  before do
+    @address = Address.new(:id => 'adr1', :instance_id => 'inst1')
+  end
+
+  it 'should tell if it is associated to instance' do
+    @address.associated?.must_equal true
+    @address.instance_id = nil
+    @address.associated?.must_equal false
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/base_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/base_test.rb b/server/tests/drivers/models/base_test.rb
new file mode 100644
index 0000000..4ac71e4
--- /dev/null
+++ b/server/tests/drivers/models/base_test.rb
@@ -0,0 +1,34 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+
+describe BaseModel do
+
+  before do
+    class CustomModel < BaseModel
+      attr_accessor :name
+      attr_accessor :custom
+    end
+    @model = CustomModel.new(:id => 'm1', :name => 'Model1', :custom => '1')
+  end
+
+  describe 'initialize' do
+
+    it 'should properly advertise given attributes' do
+      @model.must_respond_to :id
+      @model.must_respond_to :name
+      @model.must_respond_to :custom
+      @model.id.must_equal 'm1'
+      @model.name.must_equal 'Model1'
+      @model.custom.must_equal '1'
+    end
+
+    it 'should report all attributes' do
+      @model.attributes.must_include :id
+      @model.attributes.must_include :name
+      @model.attributes.must_include :custom
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/blob_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/blob_test.rb b/server/tests/drivers/models/blob_test.rb
new file mode 100644
index 0000000..eae9a02
--- /dev/null
+++ b/server/tests/drivers/models/blob_test.rb
@@ -0,0 +1,18 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
+
+describe Address do
+
+  before do
+    @address = Address.new(:id => 'adr1', :instance_id => 'inst1')
+  end
+
+  it 'should tell if it is associated to instance' do
+    @address.associated?.must_equal true
+    @address.instance_id = nil
+    @address.associated?.must_equal false
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/hardware_profile_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/hardware_profile_test.rb b/server/tests/drivers/models/hardware_profile_test.rb
new file mode 100644
index 0000000..8e65dfd
--- /dev/null
+++ b/server/tests/drivers/models/hardware_profile_test.rb
@@ -0,0 +1,52 @@
+require 'minitest/autorun'
+require 'sinatra/base'
+require 'sinatra/rabbit'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'hardware_profile.rb')
+
+describe Deltacloud::HardwareProfile do
+
+  before do
+    @profile1 = Deltacloud::HardwareProfile.new('p1') do |hwp|
+      cpu           1
+      memory        512
+      storage       100
+      architecture 'i386'
+    end
+    @profile2 = Deltacloud::HardwareProfile.new('p2') do |hwp|
+      cpu           1..10
+      memory        [512, 1024]
+    end
+  end
+
+  it 'should return proper unit for property' do
+    Deltacloud::HardwareProfile.unit(:cpu).must_equal 'count'
+    Deltacloud::HardwareProfile.unit(:storage).must_equal 'GB'
+    Deltacloud::HardwareProfile.unit(:memory).must_equal 'MB'
+    Deltacloud::HardwareProfile.unit(:architecture).must_equal 'label'
+  end
+
+  it 'should properly advertise the properties' do
+    @profile1.properties.wont_be_empty
+    @profile1.property(:cpu).must_be_kind_of Deltacloud::HardwareProfile::Property
+    @profile1.property(:cpu).name.must_equal :cpu
+  end
+
+  it 'should return the default value for given property' do
+    @profile1.default?(:cpu, '1').must_equal true
+    @profile1.default?(:cpu, '666').must_equal false
+  end
+
+  it 'should return if given value is within property range' do
+    @profile2.include?(:cpu, 5).must_equal true
+    @profile2.include?(:cpu, 100).must_equal false
+    @profile2.include?(:memory, 10).must_equal false
+    @profile2.include?(:memory, 1024).must_equal true
+  end
+
+  it 'should return query params' do
+    @profile1.params.wont_be_empty
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/instance_profile_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/instance_profile_test.rb b/server/tests/drivers/models/instance_profile_test.rb
new file mode 100644
index 0000000..7f343c7
--- /dev/null
+++ b/server/tests/drivers/models/instance_profile_test.rb
@@ -0,0 +1,21 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'instance_profile.rb')
+
+describe InstanceProfile do
+
+  before do
+    @instance = InstanceProfile.new(
+      'm1-small',
+      :hwp_memory => '512',
+      :hwp_cpu => '1'
+    )
+  end
+
+  it 'advertise the overrides' do
+    @instance.overrides.keys.must_include :cpu
+    @instance.overrides.keys.must_include :memory
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/instance_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/instance_test.rb b/server/tests/drivers/models/instance_test.rb
new file mode 100644
index 0000000..005b72b
--- /dev/null
+++ b/server/tests/drivers/models/instance_test.rb
@@ -0,0 +1,29 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'instance.rb')
+
+describe Instance do
+
+  before do
+    @instance = Instance.new(
+      :id => 'inst1',
+      :create_image => true,
+      :name => 'Instance',
+      :instance_profile => 'm1-small',
+      :state => 'RUNNING'
+    )
+  end
+
+  it 'advertise if can be used to create image' do
+    @instance.can_create_image?.must_equal true
+    @instance.create_image = false
+    @instance.can_create_image?.must_equal false
+  end
+
+  it 'advertise the current state using is_state?' do
+    @instance.is_running?.must_equal true
+    @instance.is_stopped?.must_equal false
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/keys_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/keys_test.rb b/server/tests/drivers/models/keys_test.rb
new file mode 100644
index 0000000..a4ddeb5
--- /dev/null
+++ b/server/tests/drivers/models/keys_test.rb
@@ -0,0 +1,25 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'key.rb')
+
+describe Key do
+
+  before do
+    @key = Key.new(:credential_type => :key)
+  end
+
+  it 'advertise if it is password or key' do
+    @key.is_password?.must_equal false
+    @key.is_key?.must_equal true
+  end
+
+  it 'cat generate the mock fingerprint' do
+    Key.generate_mock_fingerprint.must_match /(\w{2}:?)/
+  end
+
+  it 'can generate the mock PEM key' do
+    Key.generate_mock_pem.must_include 'PRIVATE KEY'
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/7b568e5b/server/tests/drivers/models/metrics_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/models/metrics_test.rb b/server/tests/drivers/models/metrics_test.rb
new file mode 100644
index 0000000..255d0e6
--- /dev/null
+++ b/server/tests/drivers/models/metrics_test.rb
@@ -0,0 +1,20 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'metric.rb')
+
+describe Metric do
+
+  before do
+    @metric = Metric.new(:id => 'metric1', :entity => 'inst1')
+  end
+
+  it 'cat be extended by add_property' do
+    @metric.add_property :network, { :max => 100, :min => 10, :avg => 50 }
+    @metric.properties.wont_be_empty
+    @metric.properties.each do |p|
+      p.must_be_kind_of Metric::Property
+    end
+  end
+
+end


Mime
View raw message