aboutsummaryrefslogtreecommitdiffstats
path: root/switchtower/test
diff options
context:
space:
mode:
Diffstat (limited to 'switchtower/test')
-rw-r--r--switchtower/test/actor_test.rb261
-rw-r--r--switchtower/test/command_test.rb43
-rw-r--r--switchtower/test/configuration_test.rb210
-rw-r--r--switchtower/test/fixtures/config.rb5
-rw-r--r--switchtower/test/scm/cvs_test.rb164
-rw-r--r--switchtower/test/scm/subversion_test.rb100
-rw-r--r--switchtower/test/ssh_test.rb104
-rw-r--r--switchtower/test/utils.rb41
8 files changed, 0 insertions, 928 deletions
diff --git a/switchtower/test/actor_test.rb b/switchtower/test/actor_test.rb
deleted file mode 100644
index ed657ee26e..0000000000
--- a/switchtower/test/actor_test.rb
+++ /dev/null
@@ -1,261 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../lib"
-
-require 'stringio'
-require 'test/unit'
-require 'switchtower/actor'
-require 'switchtower/logger'
-
-class ActorTest < Test::Unit::TestCase
-
- class TestingConnectionFactory
- def initialize(config)
- end
-
- def connect_to(server)
- server
- end
- end
-
- class GatewayConnectionFactory
- def connect_to(server)
- server
- end
- end
-
- class TestingCommand
- def self.invoked!
- @invoked = true
- end
-
- def self.invoked?
- @invoked
- end
-
- def self.reset!
- @invoked = nil
- end
-
- def initialize(*args)
- end
-
- def process!
- self.class.invoked!
- end
- end
-
- class TestActor < SwitchTower::Actor
- attr_reader :factory
-
- self.connection_factory = TestingConnectionFactory
- self.command_factory = TestingCommand
-
- def establish_gateway
- GatewayConnectionFactory.new
- end
- end
-
- class MockConfiguration
- Role = Struct.new(:host, :options)
-
- attr_accessor :gateway, :pretend
-
- def delegated_method
- "result of method"
- end
-
- ROLES = { :db => [ Role.new("01.example.com", :primary => true),
- Role.new("02.example.com", {}),
- Role.new("all.example.com", {})],
- :web => [ Role.new("03.example.com", {}),
- Role.new("04.example.com", {}),
- Role.new("all.example.com", {})],
- :app => [ Role.new("05.example.com", {}),
- Role.new("06.example.com", {}),
- Role.new("07.example.com", {}),
- Role.new("all.example.com", {})] }
-
- def roles
- ROLES
- end
-
- def logger
- @logger ||= SwitchTower::Logger.new(:output => StringIO.new)
- end
- end
-
- def setup
- TestingCommand.reset!
- @actor = TestActor.new(MockConfiguration.new)
- end
-
- def test_define_task_creates_method
- @actor.define_task :hello do
- "result"
- end
- assert @actor.respond_to?(:hello)
- assert_equal "result", @actor.hello
- end
-
- def test_define_task_with_successful_transaction
- class << @actor
- attr_reader :rolled_back
- attr_reader :history
- end
-
- @actor.define_task :hello do
- (@history ||= []) << :hello
- on_rollback { @rolled_back = true }
- "hello"
- end
-
- @actor.define_task :goodbye do
- (@history ||= []) << :goodbye
- transaction do
- hello
- end
- "goodbye"
- end
-
- assert_nothing_raised { @actor.goodbye }
- assert !@actor.rolled_back
- assert_equal [:goodbye, :hello], @actor.history
- end
-
- def test_define_task_with_failed_transaction
- class << @actor
- attr_reader :rolled_back
- attr_reader :history
- end
-
- @actor.define_task :hello do
- (@history ||= []) << :hello
- on_rollback { @rolled_back = true }
- "hello"
- end
-
- @actor.define_task :goodbye do
- (@history ||= []) << :goodbye
- transaction do
- hello
- raise "ouch"
- end
- "goodbye"
- end
-
- assert_raise(RuntimeError) do
- @actor.goodbye
- end
-
- assert @actor.rolled_back
- assert_equal [:goodbye, :hello], @actor.history
- end
-
- def test_delegates_to_configuration
- @actor.define_task :hello do
- delegated_method
- end
- assert_equal "result of method", @actor.hello
- end
-
- def test_task_servers_with_duplicates
- @actor.define_task :foo do
- run "do this"
- end
-
- assert_equal %w(01.example.com 02.example.com 03.example.com 04.example.com 05.example.com 06.example.com 07.example.com all.example.com), @actor.tasks[:foo].servers(@actor.configuration).sort
- end
-
- def test_run_in_task_without_explicit_roles_selects_all_roles
- @actor.define_task :foo do
- run "do this"
- end
-
- @actor.foo
- assert_equal %w(01.example.com 02.example.com 03.example.com 04.example.com 05.example.com 06.example.com 07.example.com all.example.com), @actor.sessions.keys.sort
- end
-
- def test_run_in_task_with_single_role_selects_that_role
- @actor.define_task :foo, :roles => :db do
- run "do this"
- end
-
- @actor.foo
- assert_equal %w(01.example.com 02.example.com all.example.com), @actor.sessions.keys.sort
- end
-
- def test_run_in_task_with_multiple_roles_selects_those_roles
- @actor.define_task :foo, :roles => [:db, :web] do
- run "do this"
- end
-
- @actor.foo
- assert_equal %w(01.example.com 02.example.com 03.example.com 04.example.com all.example.com), @actor.sessions.keys.sort
- end
-
- def test_run_in_task_with_only_restricts_selected_roles
- @actor.define_task :foo, :roles => :db, :only => { :primary => true } do
- run "do this"
- end
-
- @actor.foo
- assert_equal %w(01.example.com), @actor.sessions.keys.sort
- end
-
- def test_establish_connection_uses_gateway_if_specified
- @actor.configuration.gateway = "10.example.com"
- @actor.define_task :foo, :roles => :db do
- run "do this"
- end
-
- @actor.foo
- assert_instance_of GatewayConnectionFactory, @actor.factory
- end
-
- def test_run_when_not_pretend
- @actor.define_task :foo do
- run "do this"
- end
-
- @actor.configuration.pretend = false
- @actor.foo
- assert TestingCommand.invoked?
- end
-
- def test_run_when_pretend
- @actor.define_task :foo do
- run "do this"
- end
-
- @actor.configuration.pretend = true
- @actor.foo
- assert !TestingCommand.invoked?
- end
-
- def test_task_before_hook
- history = []
- @actor.define_task :foo do
- history << "foo"
- end
-
- @actor.define_task :before_foo do
- history << "before_foo"
- end
-
- @actor.foo
- assert_equal %w(before_foo foo), history
- end
-
- def test_task_after_hook
- history = []
- @actor.define_task :foo do
- history << "foo"
- end
-
- @actor.define_task :after_foo do
- history << "after_foo"
- end
-
- @actor.foo
- assert_equal %w(foo after_foo), history
- end
-end
diff --git a/switchtower/test/command_test.rb b/switchtower/test/command_test.rb
deleted file mode 100644
index 7005ba0f2d..0000000000
--- a/switchtower/test/command_test.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../lib"
-
-require 'stringio'
-require 'test/unit'
-require 'switchtower/command'
-
-class CommandTest < Test::Unit::TestCase
- class MockSession
- def open_channel
- { :closed => true, :status => 0 }
- end
- end
-
- class MockActor
- attr_reader :sessions
-
- def initialize
- @sessions = Hash.new { |h,k| h[k] = MockSession.new }
- end
- end
-
- def setup
- @actor = MockActor.new
- end
-
- def test_command_executes_on_all_servers
- command = SwitchTower::Command.new(%w(server1 server2 server3),
- "hello", nil, {}, @actor)
- assert_equal %w(server1 server2 server3), @actor.sessions.keys.sort
- end
-
- def test_command_with_newlines
- command = SwitchTower::Command.new(%w(server1), "hello\nworld", nil, {},
- @actor)
- assert_equal "hello\\\nworld", command.command
- end
-
- def test_command_with_windows_newlines
- command = SwitchTower::Command.new(%w(server1), "hello\r\nworld", nil, {},
- @actor)
- assert_equal "hello\\\nworld", command.command
- end
-end
diff --git a/switchtower/test/configuration_test.rb b/switchtower/test/configuration_test.rb
deleted file mode 100644
index ecbc0a5607..0000000000
--- a/switchtower/test/configuration_test.rb
+++ /dev/null
@@ -1,210 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../lib"
-
-require 'test/unit'
-require 'switchtower/configuration'
-require 'flexmock'
-
-class ConfigurationTest < Test::Unit::TestCase
- class MockActor
- attr_reader :tasks
-
- def initialize(config)
- end
-
- def define_task(*args, &block)
- (@tasks ||= []).push [args, block].flatten
- end
- end
-
- class MockSCM
- attr_reader :configuration
-
- def initialize(config)
- @configuration = config
- end
- end
-
- def setup
- @config = SwitchTower::Configuration.new(MockActor)
- @config.set :scm, MockSCM
- end
-
- def test_version_dir_default
- assert "releases", @config.version_dir
- end
-
- def test_current_dir_default
- assert "current", @config.current_dir
- end
-
- def test_shared_dir_default
- assert "shared", @config.shared_dir
- end
-
- def test_set_repository
- @config.set :repository, "/foo/bar/baz"
- assert_equal "/foo/bar/baz", @config.repository
- end
-
- def test_set_user
- @config.set :user, "flippy"
- assert_equal "flippy", @config.user
- end
-
- def test_define_single_role
- @config.role :app, "somewhere.example.com"
- assert_equal 1, @config.roles[:app].length
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
- assert_equal Hash.new, @config.roles[:app].first.options
- end
-
- def test_define_single_role_with_options
- @config.role :app, "somewhere.example.com", :primary => true
- assert_equal 1, @config.roles[:app].length
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
- assert_equal({:primary => true}, @config.roles[:app].first.options)
- end
-
- def test_define_multi_role
- @config.role :app, "somewhere.example.com", "else.example.com"
- assert_equal 2, @config.roles[:app].length
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
- assert_equal "else.example.com", @config.roles[:app].last.host
- assert_equal({}, @config.roles[:app].first.options)
- assert_equal({}, @config.roles[:app].last.options)
- end
-
- def test_define_multi_role_with_options
- @config.role :app, "somewhere.example.com", "else.example.com", :primary => true
- assert_equal 2, @config.roles[:app].length
- assert_equal "somewhere.example.com", @config.roles[:app].first.host
- assert_equal "else.example.com", @config.roles[:app].last.host
- assert_equal({:primary => true}, @config.roles[:app].first.options)
- assert_equal({:primary => true}, @config.roles[:app].last.options)
- end
-
- def test_load_string_unnamed
- @config.load :string => "set :repository, __FILE__"
- assert_equal "<eval>", @config.repository
- end
-
- def test_load_string_named
- @config.load :string => "set :repository, __FILE__", :name => "test.rb"
- assert_equal "test.rb", @config.repository
- end
-
- def test_load
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
- @config.load file
- assert_equal "1/2/foo", @config.repository
- assert_equal "./#{file}.example.com", @config.gateway
- assert_equal 1, @config.roles[:web].length
- end
-
- def test_load_explicit_name
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
- @config.load file, :name => "config"
- assert_equal "1/2/foo", @config.repository
- assert_equal "config.example.com", @config.gateway
- assert_equal 1, @config.roles[:web].length
- end
-
- def test_load_file_implied_name
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
- @config.load :file => file
- assert_equal "1/2/foo", @config.repository
- assert_equal "./#{file}.example.com", @config.gateway
- assert_equal 1, @config.roles[:web].length
- end
-
- def test_load_file_explicit_name
- file = File.dirname(__FILE__) + "/fixtures/config.rb"
- @config.load :file => file, :name => "config"
- assert_equal "1/2/foo", @config.repository
- assert_equal "config.example.com", @config.gateway
- assert_equal 1, @config.roles[:web].length
- end
-
- def test_task_without_options
- block = Proc.new { }
- @config.task :hello, &block
- assert_equal 1, @config.actor.tasks.length
- assert_equal :hello, @config.actor.tasks[0][0]
- assert_equal({}, @config.actor.tasks[0][1])
- assert_equal block, @config.actor.tasks[0][2]
- end
-
- def test_task_with_options
- block = Proc.new { }
- @config.task :hello, :roles => :app, &block
- assert_equal 1, @config.actor.tasks.length
- assert_equal :hello, @config.actor.tasks[0][0]
- assert_equal({:roles => :app}, @config.actor.tasks[0][1])
- assert_equal block, @config.actor.tasks[0][2]
- end
-
- def test_source
- @config.set :repository, "/foo/bar/baz"
- assert_equal "/foo/bar/baz", @config.source.configuration.repository
- end
-
- def test_releases_path_default
- @config.set :deploy_to, "/start/of/path"
- assert_equal "/start/of/path/releases", @config.releases_path
- end
-
- def test_releases_path_custom
- @config.set :deploy_to, "/start/of/path"
- @config.set :version_dir, "right/here"
- assert_equal "/start/of/path/right/here", @config.releases_path
- end
-
- def test_current_path_default
- @config.set :deploy_to, "/start/of/path"
- assert_equal "/start/of/path/current", @config.current_path
- end
-
- def test_current_path_custom
- @config.set :deploy_to, "/start/of/path"
- @config.set :current_dir, "right/here"
- assert_equal "/start/of/path/right/here", @config.current_path
- end
-
- def test_shared_path_default
- @config.set :deploy_to, "/start/of/path"
- assert_equal "/start/of/path/shared", @config.shared_path
- end
-
- def test_shared_path_custom
- @config.set :deploy_to, "/start/of/path"
- @config.set :shared_dir, "right/here"
- assert_equal "/start/of/path/right/here", @config.shared_path
- end
-
- def test_release_path_implicit
- @config.set :deploy_to, "/start/of/path"
- assert_equal "/start/of/path/releases/#{@config.now.strftime("%Y%m%d%H%M%S")}", @config.release_path
- end
-
- def test_release_path_explicit
- @config.set :deploy_to, "/start/of/path"
- assert_equal "/start/of/path/releases/silly", @config.release_path("silly")
- end
-
- def test_task_description
- block = Proc.new { }
- @config.desc "A sample task"
- @config.task :hello, &block
- assert_equal "A sample task", @config.actor.tasks[0][1][:desc]
- end
-
- def test_set_scm_to_darcs
- @config.set :scm, :darcs
- assert_equal "SwitchTower::SCM::Darcs", @config.source.class.name
- end
-
- def test_set_scm_to_subversion
- @config.set :scm, :subversion
- assert_equal "SwitchTower::SCM::Subversion", @config.source.class.name
- end
-end
diff --git a/switchtower/test/fixtures/config.rb b/switchtower/test/fixtures/config.rb
deleted file mode 100644
index 0570980bd8..0000000000
--- a/switchtower/test/fixtures/config.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-set :application, "foo"
-set :repository, "1/2/#{application}"
-set :gateway, "#{__FILE__}.example.com"
-
-role :web, "www.example.com", :primary => true
diff --git a/switchtower/test/scm/cvs_test.rb b/switchtower/test/scm/cvs_test.rb
deleted file mode 100644
index 4532870826..0000000000
--- a/switchtower/test/scm/cvs_test.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../../lib"
-
-require File.dirname(__FILE__) + "/../utils"
-require 'test/unit'
-require 'switchtower/scm/cvs'
-
-class ScmCvsTest < Test::Unit::TestCase
- class CvsTest < SwitchTower::SCM::Cvs
- attr_accessor :story
- attr_reader :last_path
-
- def cvs_log(path)
- @last_path = path
- story.shift
- end
- end
-
- class MockChannel
- attr_reader :sent_data
-
- def send_data(data)
- @sent_data ||= []
- @sent_data << data
- end
-
- def [](name)
- "value"
- end
- end
-
- class MockActor
- attr_reader :command
- attr_reader :channels
- attr_accessor :story
-
- def initialize(config)
- @config = config
- end
-
- def run(command)
- @command = command
- @channels ||= []
- @channels << MockChannel.new
- story.each { |stream, line| yield @channels.last, stream, line }
- end
-
- def release_path
- (@config[:now] || Time.now.utc).strftime("%Y%m%d%H%M%S")
- end
-
- def method_missing(sym, *args)
- @config.send(sym, *args)
- end
- end
-
- def setup
- @config = MockConfiguration.new
- @config[:repository] = ":ext:joetester@rubyforge.org:/hello/world"
- @config[:local] = "/hello/world"
- @config[:cvs] = "/path/to/cvs"
- @config[:password] = "chocolatebrownies"
- @config[:now] = Time.utc(2005,8,24,12,0,0)
- @scm = CvsTest.new(@config)
- @actor = MockActor.new(@config)
- @log_msg = <<MSG.strip
-RCS file: /var/cvs/copland/copland/LICENSE,v
-Working file: LICENSE
-head: 1.1
-branch:
-locks: strict
-access list:
-keyword substitution: kv
-total revisions: 1; selected revisions: 1
-description:
-----------------------------
-revision 1.1
-date: 2004/08/29 04:23:36; author: minam; state: Exp;
-New implementation.
-=============================================================================
-
-RCS file: /var/cvs/copland/copland/Rakefile,v
-Working file: Rakefile
-head: 1.7
-branch:
-locks: strict
-access list:
-keyword substitution: kv
-total revisions: 7; selected revisions: 1
-description:
-----------------------------
-revision 1.7
-date: 2004/09/15 16:35:01; author: minam; state: Exp; lines: +2 -1
-Rakefile now publishes package documentation from doc/packages instead of
-doc/packrat. Updated "latest updates" in manual.
-=============================================================================
-
-RCS file: /var/cvs/copland/copland/TODO,v
-Working file: TODO
-head: 1.18
-branch:
-locks: strict
-access list:
-keyword substitution: kv
-total revisions: 18; selected revisions: 1
-description:
-----------------------------
-revision 1.18
-date: 2004/10/12 02:21:02; author: minam; state: Exp; lines: +4 -1
-Added RubyConf 2004 presentation.
-=============================================================================
-
-RCS file: /var/cvs/copland/copland/Attic/build-gemspec.rb,v
-Working file: build-gemspec.rb
-head: 1.5
-branch:
-locks: strict
-access list:
-keyword substitution: kv
-total revisions: 5; selected revisions: 1
-description:
-----------------------------
-revision 1.5
-date: 2004/08/29 04:10:17; author: minam; state: dead; lines: +0 -0
-Here we go -- point of no return. Deleting existing implementation to make
-way for new implementation.
-=============================================================================
-
-RCS file: /var/cvs/copland/copland/copland.gemspec,v
-Working file: copland.gemspec
-head: 1.12
-branch:
-locks: strict
-access list:
-keyword substitution: kv
-total revisions: 13; selected revisions: 1
-description:
-----------------------------
-revision 1.12
-date: 2004/09/11 21:45:58; author: minam; state: Exp; lines: +4 -4
-Minor change in how version is communicated to gemspec.
-=============================================================================
-MSG
- @scm.story = [ @log_msg ]
- end
-
- def test_latest_revision
- @scm.story = [ @log_msg ]
- assert_equal "2004-10-12 02:21:02", @scm.latest_revision
- assert_equal "/hello/world", @scm.last_path
- end
-
- def test_checkout
- @actor.story = []
- assert_nothing_raised { @scm.checkout(@actor) }
- assert_nil @actor.channels.last.sent_data
- assert_match %r{/path/to/cvs}, @actor.command
- end
-
- def test_checkout_needs_ssh_password
- @actor.story = [[:out, "joetester@rubyforge.org's password: "]]
- assert_nothing_raised { @scm.checkout(@actor) }
- assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
- end
-end
diff --git a/switchtower/test/scm/subversion_test.rb b/switchtower/test/scm/subversion_test.rb
deleted file mode 100644
index fa65714b6b..0000000000
--- a/switchtower/test/scm/subversion_test.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../../lib"
-
-require File.dirname(__FILE__) + "/../utils"
-require 'test/unit'
-require 'switchtower/scm/subversion'
-
-class ScmSubversionTest < Test::Unit::TestCase
- class SubversionTest < SwitchTower::SCM::Subversion
- attr_accessor :story
- attr_reader :last_path
-
- def svn_log(path)
- @last_path = path
- story.shift
- end
- end
-
- class MockChannel
- attr_reader :sent_data
-
- def send_data(data)
- @sent_data ||= []
- @sent_data << data
- end
-
- def [](name)
- "value"
- end
- end
-
- class MockActor
- attr_reader :command
- attr_reader :channels
- attr_accessor :story
-
- def initialize(config)
- @config = config
- end
-
- def run(command)
- @command = command
- @channels ||= []
- @channels << MockChannel.new
- story.each { |stream, line| yield @channels.last, stream, line }
- end
-
- def method_missing(sym, *args)
- @config.send(sym, *args)
- end
- end
-
- def setup
- @config = MockConfiguration.new
- @config[:repository] = "/hello/world"
- @config[:svn] = "/path/to/svn"
- @config[:password] = "chocolatebrownies"
- @scm = SubversionTest.new(@config)
- @actor = MockActor.new(@config)
- @log_msg = <<MSG.strip
-------------------------------------------------------------------------
-r1967 | minam | 2005-08-03 06:59:03 -0600 (Wed, 03 Aug 2005) | 2 lines
-
-Initial commit of the new switchtower utility
-
-------------------------------------------------------------------------
-MSG
- @scm.story = [ @log_msg ]
- end
-
- def test_latest_revision
- @scm.story = [ @log_msg ]
- assert_equal "1967", @scm.latest_revision
- assert_equal "/hello/world", @scm.last_path
- end
-
- def test_latest_revision_searching_upwards
- @scm.story = [ "-----------------------------\n", @log_msg ]
- assert_equal "1967", @scm.latest_revision
- assert_equal "/hello", @scm.last_path
- end
-
- def test_checkout
- @actor.story = []
- assert_nothing_raised { @scm.checkout(@actor) }
- assert_nil @actor.channels.last.sent_data
- assert_match %r{/path/to/svn}, @actor.command
- end
-
- def test_checkout_needs_ssh_password
- @actor.story = [[:out, "Password: "]]
- assert_nothing_raised { @scm.checkout(@actor) }
- assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
- end
-
- def test_checkout_needs_http_password
- @actor.story = [[:out, "Password for (something): "]]
- assert_nothing_raised { @scm.checkout(@actor) }
- assert_equal ["chocolatebrownies\n"], @actor.channels.last.sent_data
- end
-end
diff --git a/switchtower/test/ssh_test.rb b/switchtower/test/ssh_test.rb
deleted file mode 100644
index 60e791beb3..0000000000
--- a/switchtower/test/ssh_test.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-$:.unshift File.dirname(__FILE__) + "/../lib"
-
-require File.dirname(__FILE__) + "/utils"
-require 'test/unit'
-require 'switchtower/ssh'
-
-class SSHTest < Test::Unit::TestCase
- class MockSSH
- AuthenticationFailed = Net::SSH::AuthenticationFailed
-
- class <<self
- attr_accessor :story
- attr_accessor :invocations
- end
-
- def self.start(server, opts, &block)
- @invocations << [server, opts, block]
- err = story.shift
- raise err if err
- end
- end
-
- def setup
- @config = MockConfiguration.new
- @config[:user] = 'demo'
- @config[:password] = 'c0c0nutfr0st1ng'
- MockSSH.story = []
- MockSSH.invocations = []
- end
-
- def test_publickey_auth_succeeds_default_port_no_block
- Net.const_during(:SSH, MockSSH) do
- SwitchTower::SSH.connect('demo.server.i', @config)
- end
-
- assert_equal 1, MockSSH.invocations.length
- assert_equal 'demo.server.i', MockSSH.invocations.first[0]
- assert_equal 22, MockSSH.invocations.first[1][:port]
- assert_equal 'demo', MockSSH.invocations.first[1][:username]
- assert_nil MockSSH.invocations.first[1][:password]
- assert_equal %w(publickey hostbased),
- MockSSH.invocations.first[1][:auth_methods]
- assert_nil MockSSH.invocations.first[2]
- end
-
- def test_publickey_auth_succeeds_explicit_port_no_block
- Net.const_during(:SSH, MockSSH) do
- SwitchTower::SSH.connect('demo.server.i', @config, 23)
- end
-
- assert_equal 1, MockSSH.invocations.length
- assert_equal 23, MockSSH.invocations.first[1][:port]
- assert_nil MockSSH.invocations.first[2]
- end
-
- def test_publickey_auth_succeeds_with_block
- Net.const_during(:SSH, MockSSH) do
- SwitchTower::SSH.connect('demo.server.i', @config) do |session|
- end
- end
-
- assert_equal 1, MockSSH.invocations.length
- assert_instance_of Proc, MockSSH.invocations.first[2]
- end
-
- def test_publickey_auth_fails
- MockSSH.story << Net::SSH::AuthenticationFailed
-
- Net.const_during(:SSH, MockSSH) do
- SwitchTower::SSH.connect('demo.server.i', @config)
- end
-
- assert_equal 2, MockSSH.invocations.length
-
- assert_nil MockSSH.invocations.first[1][:password]
- assert_equal %w(publickey hostbased),
- MockSSH.invocations.first[1][:auth_methods]
-
- assert_equal 'c0c0nutfr0st1ng', MockSSH.invocations.last[1][:password]
- assert_equal %w(password keyboard-interactive),
- MockSSH.invocations.last[1][:auth_methods]
- end
-
- def test_password_auth_fails
- MockSSH.story << Net::SSH::AuthenticationFailed
- MockSSH.story << Net::SSH::AuthenticationFailed
-
- Net.const_during(:SSH, MockSSH) do
- assert_raises(Net::SSH::AuthenticationFailed) do
- SwitchTower::SSH.connect('demo.server.i', @config)
- end
- end
-
- assert_equal 2, MockSSH.invocations.length
-
- assert_nil MockSSH.invocations.first[1][:password]
- assert_equal %w(publickey hostbased),
- MockSSH.invocations.first[1][:auth_methods]
-
- assert_equal 'c0c0nutfr0st1ng', MockSSH.invocations.last[1][:password]
- assert_equal %w(password keyboard-interactive),
- MockSSH.invocations.last[1][:auth_methods]
- end
-end
diff --git a/switchtower/test/utils.rb b/switchtower/test/utils.rb
deleted file mode 100644
index 4ddfbdbad1..0000000000
--- a/switchtower/test/utils.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-class Module
- def const_during(constant, value)
- if const_defined?(constant)
- overridden = true
- saved = const_get(constant)
- remove_const(constant)
- end
-
- const_set(constant, value)
- yield
- ensure
- if overridden
- remove_const(constant)
- const_set(constant, saved)
- end
- end
-end
-
-class MockLogger
- def info(msg,pfx=nil) end
- def debug(msg,pfx=nil) end
-end
-
-class MockConfiguration < Hash
- def initialize(*args)
- super
- self[:release_path] = "/path/to/releases/version"
- end
-
- def logger
- @logger ||= MockLogger.new
- end
-
- def method_missing(sym, *args)
- if args.length == 0
- self[sym]
- else
- super
- end
- end
-end