2010-01-22 05:36:34 +00:00
|
|
|
# ruby-debug, not necessary, but useful if we have it
|
|
|
|
begin
|
|
|
|
require 'ruby-debug'
|
|
|
|
rescue LoadError; end
|
|
|
|
|
2010-02-10 07:08:23 +00:00
|
|
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'vagrant')
|
2010-01-22 05:54:23 +00:00
|
|
|
require 'contest'
|
2010-01-22 07:57:31 +00:00
|
|
|
require 'mocha'
|
2010-01-26 08:01:17 +00:00
|
|
|
|
2010-07-20 03:32:07 +00:00
|
|
|
# Add this folder to the load path for "test_helper"
|
|
|
|
$:.unshift(File.dirname(__FILE__))
|
|
|
|
|
2010-01-30 04:38:36 +00:00
|
|
|
class Test::Unit::TestCase
|
2010-03-18 21:27:53 +00:00
|
|
|
# Mocks an environment, setting it up with the given config.
|
|
|
|
def mock_environment
|
2010-03-20 04:15:45 +00:00
|
|
|
environment = Vagrant::Environment.new
|
|
|
|
|
|
|
|
Vagrant::Config.reset!(environment)
|
2010-03-18 21:27:53 +00:00
|
|
|
|
|
|
|
Vagrant::Config.run do |config|
|
2010-06-19 18:34:37 +00:00
|
|
|
config.vagrant.home = '~/.home'
|
2010-03-18 21:27:53 +00:00
|
|
|
config.vagrant.dotfile_name = ".vagrant"
|
2010-05-20 23:36:17 +00:00
|
|
|
config.vagrant.log_output = nil
|
2010-07-11 05:07:10 +00:00
|
|
|
config.vagrant.host = :detect
|
2010-03-18 21:27:53 +00:00
|
|
|
|
|
|
|
config.ssh.username = "foo"
|
|
|
|
config.ssh.host = "baz"
|
2010-05-28 01:18:25 +00:00
|
|
|
config.ssh.port = 22
|
2010-03-18 21:27:53 +00:00
|
|
|
config.ssh.forwarded_port_key = "ssh"
|
|
|
|
config.ssh.max_tries = 10
|
|
|
|
config.ssh.timeout = 10
|
|
|
|
config.ssh.private_key_path = '~/foo'
|
|
|
|
|
|
|
|
config.vm.box = "foo"
|
|
|
|
config.vm.box_ovf = "box.ovf"
|
|
|
|
config.vm.base_mac = "42"
|
|
|
|
config.vm.disk_image_format = 'VMDK'
|
|
|
|
config.vm.forward_port("ssh", 22, 2222)
|
|
|
|
config.vm.shared_folder_uid = nil
|
|
|
|
config.vm.shared_folder_gid = nil
|
2010-04-25 08:46:51 +00:00
|
|
|
config.vm.system = :linux
|
2010-06-04 05:19:42 +00:00
|
|
|
config.vm.share_folder("v-root", "/vagrant", ".")
|
2010-03-18 21:27:53 +00:00
|
|
|
|
|
|
|
config.package.name = 'vagrant'
|
|
|
|
config.package.extension = '.box'
|
|
|
|
|
2010-06-19 18:34:37 +00:00
|
|
|
# Unison
|
|
|
|
config.unison.folder_suffix = ".sync"
|
2010-06-23 06:33:20 +00:00
|
|
|
config.unison.log_file = "foo-%s"
|
2010-06-19 18:34:37 +00:00
|
|
|
|
2010-03-18 21:27:53 +00:00
|
|
|
# Chef
|
|
|
|
config.chef.chef_server_url = "http://localhost:4000"
|
|
|
|
config.chef.validation_key_path = "validation.pem"
|
|
|
|
config.chef.client_key_path = "/zoo/foo/bar.pem"
|
2010-04-01 21:20:40 +00:00
|
|
|
config.chef.node_name = "baz"
|
2010-03-18 21:27:53 +00:00
|
|
|
config.chef.cookbooks_path = "cookbooks"
|
|
|
|
config.chef.provisioning_path = "/tmp/vagrant-chef"
|
2010-04-09 06:17:25 +00:00
|
|
|
config.chef.log_level = :info
|
2010-03-18 21:27:53 +00:00
|
|
|
config.chef.json = {
|
|
|
|
:recipes => ["vagrant_main"]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if block_given?
|
|
|
|
Vagrant::Config.run do |config|
|
|
|
|
yield config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config = Vagrant::Config.execute!
|
|
|
|
|
|
|
|
environment.instance_variable_set(:@config, config)
|
2010-05-20 23:36:17 +00:00
|
|
|
|
|
|
|
# Setup the logger. We create it then reset it so that subsequent
|
|
|
|
# calls will recreate it for us.
|
|
|
|
environment.load_logger!
|
|
|
|
environment.logger.class.reset_singleton_logger!
|
2010-05-21 05:28:28 +00:00
|
|
|
environment.logger.stubs(:flush_progress)
|
|
|
|
environment.logger.stubs(:cl_reset).returns("")
|
2010-05-20 23:36:17 +00:00
|
|
|
|
2010-03-18 21:27:53 +00:00
|
|
|
environment
|
|
|
|
end
|
|
|
|
|
2010-05-08 04:40:32 +00:00
|
|
|
# Sets up the mocks for a VM
|
2010-05-08 04:45:40 +00:00
|
|
|
def mock_vm(env=nil)
|
|
|
|
env ||= mock_environment
|
2010-05-08 21:57:31 +00:00
|
|
|
vm = Vagrant::VM.new
|
2010-05-08 04:45:40 +00:00
|
|
|
vm.stubs(:env).returns(env)
|
2010-05-08 04:40:32 +00:00
|
|
|
vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
|
|
|
|
vm
|
|
|
|
end
|
|
|
|
|
2010-07-04 06:52:01 +00:00
|
|
|
def mock_action_data
|
|
|
|
app = lambda { |env| }
|
|
|
|
env = Vagrant::Action::Environment.new(mock_environment)
|
|
|
|
[app, env]
|
|
|
|
end
|
|
|
|
|
2010-05-21 05:28:28 +00:00
|
|
|
# Returns a resource logger which is safe for tests
|
|
|
|
def quiet_logger(resource, env=nil)
|
|
|
|
logger = Vagrant::ResourceLogger.new(resource, env)
|
|
|
|
logger.stubs(:flush_progress)
|
|
|
|
logger.stubs(:cl_reset).returns("")
|
|
|
|
logger
|
|
|
|
end
|
|
|
|
|
2010-04-25 23:27:03 +00:00
|
|
|
# Returns a linux system
|
|
|
|
def linux_system(vm)
|
|
|
|
Vagrant::Systems::Linux.new(vm)
|
|
|
|
end
|
|
|
|
|
2010-04-09 06:32:26 +00:00
|
|
|
def stub_default_action_dependecies(mock)
|
2010-03-15 05:34:48 +00:00
|
|
|
mock.stubs(:precedes).returns([])
|
|
|
|
mock.stubs(:follows).returns([])
|
|
|
|
end
|
|
|
|
|
2010-03-01 05:42:38 +00:00
|
|
|
# Sets up the mocks and stubs for a downloader
|
|
|
|
def mock_downloader(downloader_klass)
|
|
|
|
tempfile = mock("tempfile")
|
|
|
|
tempfile.stubs(:write)
|
|
|
|
|
2010-05-21 05:37:39 +00:00
|
|
|
[downloader_klass.new(mock_environment), tempfile]
|
2010-03-01 05:42:38 +00:00
|
|
|
end
|
2010-01-30 07:22:03 +00:00
|
|
|
end
|
2010-03-15 05:34:48 +00:00
|
|
|
|