Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started on the integration tests

Completed Appliance integration tests
Removed the old unit tests ( No longer applicable )
TODO: Make the tests work on rake test. Doesn't seem to work when I just put the test in the test/ directory.
  • Loading branch information...
commit 0023ce1932c71eba87f4f64f99bd0ae0dc999d9b 1 parent c38e64e
@rjsvaljean rjsvaljean authored
View
3  .gitignore
@@ -19,3 +19,6 @@ pkg
# gnome backup files
*~
+
+# test config file
+test/test_config.yaml
View
3  Gemfile.lock
@@ -10,6 +10,8 @@ GEM
activesupport (= 3.0.0)
activesupport (3.0.0)
builder (2.1.2)
+ fast_context (1.0.0)
+ shoulda
git (1.2.5)
i18n (0.4.1)
jeweler (1.6.0)
@@ -31,6 +33,7 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0.0)
+ fast_context (>= 1.0.0)
jeweler (~> 1.6.0)
mocha
rcov
View
7 lib/handlers/all.rb
@@ -20,6 +20,13 @@ def initialize(*args)
connect(options.username, options.password, optional_connection_options)
@not_local= true if options.remote?
end
+
+ no_tasks do
+ def say(*args)
+ super(*args)
+ args[0]
+ end
+ end
end
end
end
View
14 lib/handlers/appliance.rb
@@ -37,12 +37,14 @@ def info
desc "appliance destroy", "destroy the current appliance (within appliance directory only)"
require_appliance_id
def destroy
- if appliance.destroy.code_type == Net::HTTPOK
- say 'Appliance Successfully Destroyed', :red
- else
- say_array ['There was a problem with destroying the appliance.',
- 'Make sure that you\'re in the appliance directory OR',
- 'Have provided the --appliance_id option']
+ require_appliance do |appliance|
+ if appliance.destroy.code_type == Net::HTTPOK
+ say 'Appliance Successfully Destroyed', :red
+ else
+ say_array ['There was a problem with destroying the appliance.',
+ 'Make sure that you\'re in the appliance directory OR',
+ 'Have provided the --appliance_id option']
+ end
end
end
View
1  lib/handlers/helper.rb
@@ -70,6 +70,7 @@ def say_array(array, color= nil)
else
say "\n"
end
+ array
end
def require_appliance
View
20 test/handlers/test_appliance.rb
@@ -1,20 +0,0 @@
-require 'helper'
-
-class TestHandlerAppliance < Test::Unit::TestCase
- context "SSC::Handler::Template" do
- context "#list" do
- setup do
- @handler= SSC::Handler::Appliance.new()
- @handler.stubs(:connect)
- end
-
- should "call find(:all) on StudioApi::Appliance" do
- mock_app_list= mock('appliance list')
- mock_app_list.stubs(:collect)
- mock_app_list.stubs(:empty?)
- StudioApi::Appliance.expects(:find).with(:all).returns(mock_app_list)
- @handler.list
- end
- end
- end
-end
View
45 test/handlers/test_helper.rb
@@ -1,45 +0,0 @@
-require 'helper'
-
-class TestHandlerHelper < Test::Unit::TestCase
- context "SSC::Handler::Helper" do
- setup do
- class TestObject
- include SSC::Handler::Helper
- end
-
- @objekt= TestObject.new
- end
-
- context "#connect" do
- should "create connection and configure StudioApi to use it" do
- mock_connection= mock('connection')
- StudioApi::Connection.expects(:new)
- .with('user', 'pass', 'https://susestudio.com/api/v1/user',
- {:proxy => 'proxy'})
- .returns(mock_connection)
- StudioApi::Util.expects(:configure_studio_connection).with(mock_connection)
- @objekt.connect('user', 'pass', {:proxy => 'proxy', :another_option => 'value'})
- end
- end
-
- context "#filter_options" do
- should "return a hash of only the specified keys" do
- out= @objekt.filter_options({:a => 'a', :b => 'b'}, [:a])
- assert_equal({:a => 'a'}, out)
- end
- end
-
- context "#require_appliance_id" do
- should "raise and error if the appliance id option is not passed" do
- assert_raise(RuntimeError) { @objekt.require_appliance_id({}) }
- end
-
- should "not raise error if appliance id is provided" do
- StudioApi::Appliance.expects(:find).with(1).returns(nil)
- assert_nothing_raised do
- @objekt.require_appliance_id(:appliance_id=>1) {|i| i}
- end
- end
- end
- end
-end
View
20 test/handlers/test_repository.rb
@@ -1,20 +0,0 @@
-require 'helper'
-
-class TestHandlerRepository < Test::Unit::TestCase
- context "SSC::Handler::Repository" do
- setup do
- @handler= SSC::Handler::Repository.new()
- @handler.stubs(:connect)
- end
- context "#search" do
-
- should "call .find(:all, params_hash) on StudioApi::Repository" do
- mock_collection= mock('collection')
- mock_collection.stubs(:collect)
- StudioApi::Repository.expects(:find).with(:all, :params => {:filter => 'chess', :base_system => '11.1'}).returns(mock_collection)
- @handler.instance_variable_set('@options', {:base_system => '11.1'})
- @handler.search('chess')
- end
- end
- end
-end
View
27 test/handlers/test_template.rb
@@ -1,27 +0,0 @@
-require 'helper'
-
-class TestTemplateHandler < Test::Unit::TestCase
- context "SSC::Handler::Template" do
- context "#list" do
- setup do
- @handler= SSC::Handler::Template.new()
- @handler.stubs(:connect)
- end
-
- should "call .find(:all) on StudioApi::TemplateSet" do
- mock_template= mock('template_list')
- mock_template.stubs(:collect)
- StudioApi::TemplateSet.expects(:find).with(:all).returns(mock_template)
- @handler.list
- end
-
- should "return a list of strings of type 'template.id: template.name'" do
- mock_template= StudioApi::TemplateSet.new(:name => 'Template Name')
- StudioApi::TemplateSet.stubs(:find).with(:all).returns([mock_template])
- assert_equal ["Template Name"],
- @handler.list
- end
-
- end
- end
-end
View
6 test/helper.rb
@@ -10,10 +10,16 @@
require 'test/unit'
require 'shoulda'
require 'mocha'
+require 'yaml'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+
require 'ssc'
+
class Test::Unit::TestCase
+ # You'll need to create this file(test/test_config.yaml) before you run the tests
+ TEST_CONFIG= YAML::load(File.read(File.join(File.dirname(__FILE__), 'test_config.yaml')))
+ APPLIANCES_CREATED= []
end
View
55 test/test_argument_parser.rb
@@ -1,55 +0,0 @@
-require 'helper'
-
-class TestArgumentParser < Test::Unit::TestCase
- context "SSC::ArgumentParser" do
-
- context "when arguments are good" do
- setup do
- @parser= SSC::ArgumentParser.new(['appliance', 'create', 'act_arg1', 'act_arg2', '--option', 'value', '-o', 'v', '--flag', '-f'])
- end
-
- should "set @klass to Appliance" do
- assert_equal SSC::Handler::Appliance, @parser.klass
- end
-
- should "set @action to create" do
- assert_equal 'create', @parser.action
- end
-
- should "set @options to option hash" do
- assert_equal({:option => 'value',
- :o => 'v',
- :flag => true,
- :f => true }, @parser.options)
- end
-
- should "set @action_arguments to argument array" do
- #only one of the arguments must be taken since create take only one argument
- assert_equal(['act_arg1'], @parser.action_arguments)
- end
-
- should "have the entire list if arity of the method is -1(splat)" do
- parser= SSC::ArgumentParser.new(['repository', 'add', 'act_arg1', 'act_arg2'])
- assert_equal(['act_arg1', 'act_arg2'], parser.action_arguments )
- end
-
- end
- end
-
- context "when handler is unknown" do
- should "raise UnkownOptionError" do
- assert_raise(SSC::UnkownOptionError) do
- SSC::ArgumentParser.new(['apliance', 'create'])
- end
- end
- end
-
- context "when handler method is unknown" do
- should "raise UnkownOptionError" do
- assert_raise(SSC::UnkownOptionError) do
- SSC::ArgumentParser.new(['appliance', 'unkown_method'])
- end
- end
- end
-
-end
View
40 test/test_directory_manager.rb
@@ -1,40 +0,0 @@
-require 'helper'
-require 'fileutils'
-
-class TestDirectoryManager < Test::Unit::TestCase
- context "SSC::DirectoryManager" do
- setup do
- class B; include SSC::DirectoryManager; end
- @app_dir= B.create_appliance_directory('test_dir','user','pass',1)
- Dir.chdir('test_dir')
- class A
- include SSC::DirectoryManager
- manage 'software'
- end
- end
-
- should "set the @@local_source variable correctly" do
- assert_equal File.join(@app_dir, 'software'), A.class_variable_get('@@local_source')
- end
-
- context "#save" do
- should "save data to the local cache file" do
- A.new.save(['some', 'data'])
- assert_equal "some\ndata\n", File.read('software')
- end
- end
-
- context "#read" do
- should "fetch data from local_source" do
- A.new.save(['some', 'data'])
- assert_equal ['some', 'data'], A.new.read
- end
- end
-
- end
-
- def teardown
- Dir.chdir('..')
- FileUtils.rm_r('test_dir')
- end
-end
View
39 test/test_ssc.rb
@@ -1,39 +0,0 @@
-require 'helper'
-
-class TestSsc < Test::Unit::TestCase
- context "SSC::Base" do
- setup do
- File.open('.sscrc', 'w') {|f| f.write("username: user\npassword: pass")}
- @client= SSC::Base.new(['appliance', 'create', '--option', 'value',
- '-o', 'v', '--flag', '-f'])
- @specific_client= SSC::Base.new(['appliance', 'create',
- '--username', 'user1',
- '--password', 'pass1'])
- FileUtils.rm('.sscrc')
- end
-
- context "when username and password are passed in the command line" do
- should "override username and password in ./.sscrc" do
- assert_equal({:username => 'user1', :password => 'pass1'},
- @specific_client.instance_variable_get('@options'))
- end
- end
-
- should "initialize handler class correctly" do
- assert_equal SSC::Handler::Appliance,
- @client.instance_variable_get('@klass')
- end
-
- should "initialize @args with an ArgumentParser object" do
- args= @client.instance_variable_get('@args')
- assert_equal SSC::ArgumentParser, args.class
- end
-
- should "initialize @config with the config from .sscrc" do
- options= @client.instance_variable_get('@options')
- assert_equal('user', options[:username])
- assert_equal('pass', options[:password])
- end
-
- end
-end

0 comments on commit 0023ce1

Please sign in to comment.
Something went wrong with that request. Please try again.