incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962200 - in /incubator/deltacloud/trunk/server/libexec: ./ tests/ tests/xmls/
Date Thu, 08 Jul 2010 23:36:09 GMT
Author: lutter
Date: Thu Jul  8 23:36:09 2010
New Revision: 962200

URL: http://svn.apache.org/viewvc?rev=962200&view=rev
Log:
Added basic Unit tests for Sinatra to match XML from Rails

- 'gem install nokogiri' is needed to test equality of XML's
- XML files is saved by hand from Firefox

Added:
    incubator/deltacloud/trunk/server/libexec/run_tests.sh   (with props)
    incubator/deltacloud/trunk/server/libexec/tests/
    incubator/deltacloud/trunk/server/libexec/tests/flavors.rb
    incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb
    incubator/deltacloud/trunk/server/libexec/tests/realms.rb
    incubator/deltacloud/trunk/server/libexec/tests/xmls/
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml
    incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml

Added: incubator/deltacloud/trunk/server/libexec/run_tests.sh
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/run_tests.sh?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/run_tests.sh (added)
+++ incubator/deltacloud/trunk/server/libexec/run_tests.sh Thu Jul  8 23:36:09 2010
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+## TODO: This fiel will be replaced by regular Rake task
+#
+
+for t in tests/*.rb; do
+  ruby $t
+done

Propchange: incubator/deltacloud/trunk/server/libexec/run_tests.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/deltacloud/trunk/server/libexec/run_tests.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/deltacloud/trunk/server/libexec/tests/flavors.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/flavors.rb?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/flavors.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/flavors.rb Thu Jul  8 23:36:09 2010
@@ -0,0 +1,71 @@
+require 'rubygems'
+require 'test/unit'
+require 'rack/test'
+require 'base64'
+require 'nokogiri'
+require 'pp'
+
+ENV['API_DRIVER']='mock'
+
+require 'server'
+
+set :environment, :test
+
+class FlavorTest < Test::Unit::TestCase
+  include Rack::Test::Methods
+
+  def app
+    Sinatra::Application
+  end
+
+  def test_if_xml_is_valid
+    get '/api/flavors.xml', {}, auth
+    assert last_response.ok?
+    document = Nokogiri::XML(last_response.body)
+    assert_equal '1.0', document.version
+  end
+
+  def test_index_operation
+    get '/api/flavors.xml', {}, auth
+    original = Nokogiri::XML(xml_file_content('flavors'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+  end
+
+  def test_index_filter_architecture
+    get '/api/flavors.xml', { :architecture => 'x86_64'}, auth
+    original = Nokogiri::XML(xml_file_content('flavors-x86_64'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+    original = Nokogiri::XML(xml_file_content('flavors-unknown-testing'))
+    get '/api/flavors.xml', { :architecture => 'unknown-testing'}, auth
+    assert_equal original.to_s, responded.to_s
+  end
+
+  def test_show_operation
+    get '/api/flavors.xml', {}, auth
+    url = Nokogiri::XML(xml_file_content('flavors')).xpath('/flavors/flavor[1]').attr('href').to_s
+    get "#{url}.xml", {}, auth
+    original = Nokogiri::XML(xml_file_content('flavors-m1-small'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+  end
+
+  private
+
+  def xml_file_content(name)
+    out = ""
+    File.open("tests/xmls/#{name}.xml", 'r') do |f|
+      while (line = f.gets)
+        out += line
+      end
+    end
+    return out
+  end
+
+  def auth
+    auth_string = "Basic " + Base64.encode64("mockuser:mockpassword")
+    @auth = { 'HTTP_AUTHORIZATION' => auth_string }
+  end
+
+end

Added: incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/instance-states.rb Thu Jul  8 23:36:09
2010
@@ -0,0 +1,53 @@
+require 'rubygems'
+require 'test/unit'
+require 'rack/test'
+require 'base64'
+require 'nokogiri'
+require 'pp'
+
+ENV['API_DRIVER']='mock'
+
+require 'server'
+
+set :environment, :test
+
+class InstanceStatesTest < Test::Unit::TestCase
+  include Rack::Test::Methods
+
+  def app
+    Sinatra::Application
+  end
+
+  def test_if_xml_is_valid
+    get '/api/instance_states.xml', {}, auth
+    assert last_response.ok?
+    document = Nokogiri::XML(last_response.body)
+    assert_equal '1.0', document.version
+  end
+
+  def test_index_operation
+    get '/api/instance_states.xml', {}, auth
+    assert last_response.ok?
+    original = Nokogiri::XML(xml_file_content('instance-states'))
+    document = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, document.to_s
+  end
+
+  private
+
+  def xml_file_content(name)
+    out = ""
+    File.open("tests/xmls/#{name}.xml", 'r') do |f|
+      while (line = f.gets)
+        out += line
+      end
+    end
+    return out
+  end
+
+  def auth
+    auth_string = "Basic " + Base64.encode64("mockuser:mockpassword")
+    @auth = { 'HTTP_AUTHORIZATION' => auth_string }
+  end
+
+end

Added: incubator/deltacloud/trunk/server/libexec/tests/realms.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/realms.rb?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/realms.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/realms.rb Thu Jul  8 23:36:09 2010
@@ -0,0 +1,74 @@
+require 'rubygems'
+require 'test/unit'
+require 'rack/test'
+require 'base64'
+require 'nokogiri'
+require 'pp'
+
+ENV['API_DRIVER']='mock'
+
+require 'server'
+
+set :environment, :test
+
+class RealmTest < Test::Unit::TestCase
+  include Rack::Test::Methods
+
+  def app
+    Sinatra::Application
+  end
+
+  def test_if_xml_is_valid
+    get '/api/realms.xml', {}, auth
+    assert last_response.ok?
+    document = Nokogiri::XML(last_response.body)
+    assert_equal '1.0', document.version
+  end
+
+  def test_index_operation
+    get '/api/realms.xml', {}, auth
+    original = Nokogiri::XML(xml_file_content('realms'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+  end
+
+# TODO: Does Realms have 'architecture' ?
+=begin
+  def test_index_filter_architecture
+    get '/api/realms.xml', { :architecture => 'x86_64'}, auth
+    original = Nokogiri::XML(xml_file_content('realms-x86_64'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+    original = Nokogiri::XML(xml_file_content('realms-unknown-testing'))
+    get '/api/realms.xml', { :architecture => 'unknown-testing'}, auth
+    assert_equal original.to_s, responded.to_s
+  end
+=end
+
+  def test_show_operation
+    get '/api/realms.xml', {}, auth
+    url = Nokogiri::XML(xml_file_content('realms')).xpath('/realms/realm[1]').attr('href').to_s
+    get "#{url}.xml", {}, auth
+    original = Nokogiri::XML(xml_file_content('realms-us'))
+    responded = Nokogiri::XML(last_response.body)
+    assert_equal original.to_s, responded.to_s
+  end
+
+  private
+
+  def xml_file_content(name)
+    out = ""
+    File.open("tests/xmls/#{name}.xml", 'r') do |f|
+      while (line = f.gets)
+        out += line
+      end
+    end
+    return out
+  end
+
+  def auth
+    auth_string = "Basic " + Base64.encode64("mockuser:mockpassword")
+    @auth = { 'HTTP_AUTHORIZATION' => auth_string }
+  end
+
+end

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-m1-small.xml Thu Jul  8 23:36:09
2010
@@ -0,0 +1,6 @@
+<flavor href="http://localhost:3000/api/flavors/m1-small">
+  <id>m1-small</id>
+  <architecture>i386</architecture>
+  <memory>1.7</memory>
+  <storage>160</storage>
+</flavor>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-unknown-testing.xml Thu Jul
 8 23:36:09 2010
@@ -0,0 +1,2 @@
+<flavors>
+</flavors>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors-x86_64.xml Thu Jul  8 23:36:09
2010
@@ -0,0 +1,26 @@
+<flavors>
+  <flavor href="http://localhost:3030/api/flavors/m1-large">
+    <id>m1-large</id>
+    <architecture>x86_64</architecture>
+    <memory>7.5</memory>
+    <storage>850</storage>
+  </flavor>
+  <flavor href="http://localhost:3030/api/flavors/m1-xlarge">
+    <id>m1-xlarge</id>
+    <architecture>x86_64</architecture>
+    <memory>15</memory>
+    <storage>1690</storage>
+  </flavor>
+  <flavor href="http://localhost:3030/api/flavors/c1-medium">
+    <id>c1-medium</id>
+    <architecture>x86_64</architecture>
+    <memory>1.7</memory>
+    <storage>350</storage>
+  </flavor>
+  <flavor href="http://localhost:3030/api/flavors/c1-xlarge">
+    <id>c1-xlarge</id>
+    <architecture>x86_64</architecture>
+    <memory>7</memory>
+    <storage>1690</storage>
+  </flavor>
+</flavors>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/flavors.xml Thu Jul  8 23:36:09 2010
@@ -0,0 +1,32 @@
+<flavors>
+  <flavor href="http://localhost:3000/api/flavors/m1-small">
+    <id>m1-small</id>
+    <architecture>i386</architecture>
+    <memory>1.7</memory>
+    <storage>160</storage>
+  </flavor>
+  <flavor href="http://localhost:3000/api/flavors/m1-large">
+    <id>m1-large</id>
+    <architecture>x86_64</architecture>
+    <memory>7.5</memory>
+    <storage>850</storage>
+  </flavor>
+  <flavor href="http://localhost:3000/api/flavors/m1-xlarge">
+    <id>m1-xlarge</id>
+    <architecture>x86_64</architecture>
+    <memory>15</memory>
+    <storage>1690</storage>
+  </flavor>
+  <flavor href="http://localhost:3000/api/flavors/c1-medium">
+    <id>c1-medium</id>
+    <architecture>x86_64</architecture>
+    <memory>1.7</memory>
+    <storage>350</storage>
+  </flavor>
+  <flavor href="http://localhost:3000/api/flavors/c1-xlarge">
+    <id>c1-xlarge</id>
+    <architecture>x86_64</architecture>
+    <memory>7</memory>
+    <storage>1690</storage>
+  </flavor>
+</flavors>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/instance-states.xml Thu Jul  8 23:36:09
2010
@@ -0,0 +1,18 @@
+<states>
+  <state name='start'>
+    <transition action='create' to='pending'>    </transition>
+  </state>
+  <state name='pending'>
+    <transition auto='true' to='running'>    </transition>
+  </state>
+  <state name='running'>
+    <transition action='reboot' to='running'>    </transition>
+    <transition action='stop' to='stopped'>    </transition>
+  </state>
+  <state name='stopped'>
+    <transition action='start' to='running'>    </transition>
+    <transition action='destroy' to='finish'>    </transition>
+  </state>
+  <state name='finish'>
+  </state>
+</states>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/realms-us.xml Thu Jul  8 23:36:09
2010
@@ -0,0 +1,6 @@
+<realm href="http://localhost:3000/api/realms/us">
+  <id>us</id>
+  <name>United States</name>
+  <state>AVAILABLE</state>
+  <limit/>
+</realm>

Added: incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml?rev=962200&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml (added)
+++ incubator/deltacloud/trunk/server/libexec/tests/xmls/realms.xml Thu Jul  8 23:36:09 2010
@@ -0,0 +1,14 @@
+<realms>
+  <realm href="http://localhost:3000/api/realms/us">
+    <id>us</id>
+    <name>United States</name>
+    <state>AVAILABLE</state>
+    <limit/>
+  </realm>
+  <realm href="http://localhost:3000/api/realms/eu">
+    <id>eu</id>
+    <name>Europe</name>
+    <state>AVAILABLE</state>
+    <limit/>
+  </realm>
+</realms>



Mime
View raw message