vagrant/test/test_helper.rb

109 lines
2.7 KiB
Ruby
Raw Normal View History

begin
require File.expand_path('../.bundle/environment', __FILE__)
2010-01-22 05:07:01 +00:00
rescue LoadError
# Fallback on doing the resolve at runtime.
require "rubygems"
require "bundler"
Bundler.setup
2010-01-22 05:07:01 +00:00
end
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
require File.join(File.dirname(__FILE__), '..', 'lib', 'vagrant')
2010-01-22 05:54:23 +00:00
require 'contest'
require 'mocha'
2010-01-26 08:01:17 +00:00
class Test::Unit::TestCase
2010-02-13 19:56:33 +00:00
# Clears the previous config and sets up the new config
def mock_config
Vagrant::Config.reset!
2010-02-02 06:14:40 +00:00
Vagrant::Config.run do |config|
config.vagrant.dotfile_name = ".vagrant"
2010-02-02 06:14:40 +00:00
config.ssh.username = "foo"
config.ssh.password = "bar"
2010-02-02 06:14:40 +00:00
config.ssh.host = "baz"
config.ssh.forwarded_port_key = "ssh"
2010-02-02 06:14:40 +00:00
config.ssh.max_tries = 10
config.ssh.timeout = 10
2010-03-12 09:19:45 +00:00
config.ssh.private_key_path = '~/foo'
2010-02-02 06:14:40 +00:00
config.vm.box = "foo"
config.vm.box_ovf = "box.ovf"
2010-02-02 06:14:40 +00:00
config.vm.base_mac = "42"
config.vm.project_directory = "/vagrant"
2010-02-15 06:27:06 +00:00
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
config.package.name = 'vagrant'
config.package.extension = '.box'
2010-02-15 21:55:42 +00:00
# Chef
2010-03-11 05:57:51 +00:00
config.chef.chef_server_url = "http://localhost:4000"
config.chef.validation_key_path = "validation.pem"
config.chef.client_key_path = "/zoo/foo/bar.pem"
config.chef.cookbooks_path = "cookbooks"
config.chef.provisioning_path = "/tmp/vagrant-chef"
config.chef.json = {
:recipes => ["vagrant_main"]
}
2010-02-15 21:55:42 +00:00
config.vagrant.home = '~/.home'
2010-02-02 06:14:40 +00:00
end
2010-02-15 06:27:06 +00:00
if block_given?
Vagrant::Config.run do |config|
yield config
end
end
2010-02-15 06:27:06 +00:00
if block_given?
Vagrant::Config.run do |config|
yield config
end
end
Vagrant::Config.execute!
end
2010-02-13 19:56:33 +00:00
# Sets up the mocks and instantiates an action for testing
def mock_action(action_klass, *args)
vm = mock("vboxvm")
mock_vm = mock("vm")
action = action_klass.new(mock_vm, *args)
stub_default_action_dependecies(action)
mock_vm.stubs(:vm).returns(vm)
mock_vm.stubs(:vm=)
mock_vm.stubs(:invoke_callback)
mock_vm.stubs(:invoke_around_callback).yields
mock_vm.stubs(:actions).returns([action])
2010-02-13 19:56:33 +00:00
[mock_vm, vm, action]
2010-02-13 19:56:33 +00:00
end
def stub_default_action_dependecies(mock, klass=MockAction)
mock.stubs(:precedes).returns([])
mock.stubs(:follows).returns([])
end
# Sets up the mocks and stubs for a downloader
def mock_downloader(downloader_klass)
tempfile = mock("tempfile")
tempfile.stubs(:write)
[downloader_klass.new, tempfile]
end
end
class MockAction; end
class MockActionOther; end