vagrantup 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +14 -3
- data/Gemfile.lock +38 -11
- data/README.md +1 -1
- data/bin/vagrant +20 -5
- data/config/default.rb +6 -8
- data/lib/vagrant.rb +40 -13
- data/lib/vagrant/action.rb +56 -16
- data/lib/vagrant/action/box/destroy.rb +3 -1
- data/lib/vagrant/action/box/download.rb +8 -13
- data/lib/vagrant/action/box/unpackage.rb +8 -11
- data/lib/vagrant/action/box/verify.rb +3 -3
- data/lib/vagrant/action/builder.rb +3 -30
- data/lib/vagrant/action/builtin.rb +6 -1
- data/lib/vagrant/action/environment.rb +14 -62
- data/lib/vagrant/action/general/package.rb +29 -22
- data/lib/vagrant/action/vm/boot.rb +5 -12
- data/lib/vagrant/action/vm/check_box.rb +4 -4
- data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
- data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
- data/lib/vagrant/action/vm/customize.rb +1 -1
- data/lib/vagrant/action/vm/destroy.rb +1 -2
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
- data/lib/vagrant/action/vm/disable_networks.rb +11 -9
- data/lib/vagrant/action/vm/discard_state.rb +2 -2
- data/lib/vagrant/action/vm/export.rb +10 -11
- data/lib/vagrant/action/vm/forward_ports.rb +21 -9
- data/lib/vagrant/action/vm/halt.rb +3 -8
- data/lib/vagrant/action/vm/import.rb +16 -14
- data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
- data/lib/vagrant/action/vm/network.rb +9 -16
- data/lib/vagrant/action/vm/nfs.rb +14 -18
- data/lib/vagrant/action/vm/provision.rb +5 -5
- data/lib/vagrant/action/vm/resume.rb +1 -1
- data/lib/vagrant/action/vm/share_folders.rb +6 -44
- data/lib/vagrant/action/vm/suspend.rb +1 -1
- data/lib/vagrant/action/warden.rb +74 -0
- data/lib/vagrant/box.rb +18 -82
- data/lib/vagrant/box_collection.rb +47 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +99 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +17 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +41 -0
- data/lib/vagrant/command/ssh_config.rb +21 -0
- data/lib/vagrant/command/status.rb +23 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +20 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +107 -189
- data/lib/vagrant/config/base.rb +67 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +28 -0
- data/lib/vagrant/config/vagrant.rb +21 -0
- data/lib/vagrant/config/vm.rb +111 -0
- data/lib/vagrant/data_store.rb +68 -0
- data/lib/vagrant/downloaders/file.rb +3 -3
- data/lib/vagrant/downloaders/http.rb +5 -5
- data/lib/vagrant/environment.rb +246 -243
- data/lib/vagrant/errors.rb +306 -0
- data/lib/vagrant/hosts/base.rb +1 -1
- data/lib/vagrant/hosts/bsd.rb +3 -9
- data/lib/vagrant/hosts/linux.rb +3 -9
- data/lib/vagrant/plugin.rb +50 -0
- data/lib/vagrant/provisioners/base.rb +0 -6
- data/lib/vagrant/provisioners/chef.rb +63 -58
- data/lib/vagrant/provisioners/chef_server.rb +9 -11
- data/lib/vagrant/provisioners/chef_solo.rb +2 -2
- data/lib/vagrant/ssh.rb +34 -37
- data/lib/vagrant/systems/base.rb +0 -13
- data/lib/vagrant/systems/linux.rb +10 -33
- data/lib/vagrant/systems/solaris.rb +59 -0
- data/lib/vagrant/test_helpers.rb +109 -0
- data/lib/vagrant/ui.rb +65 -0
- data/lib/vagrant/util.rb +9 -19
- data/lib/vagrant/util/glob_loader.rb +19 -17
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +2 -0
- data/lib/vagrant/util/platform.rb +2 -0
- data/lib/vagrant/util/resource_logger.rb +5 -70
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/template_renderer.rb +1 -1
- data/lib/vagrant/version.rb +1 -1
- data/lib/vagrant/vm.rb +27 -13
- data/templates/commands/init/Vagrantfile.erb +13 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +402 -0
- data/templates/package_Vagrantfile.erb +1 -1
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +19 -103
- data/test/vagrant/action/box/destroy_test.rb +7 -19
- data/test/vagrant/action/box/download_test.rb +9 -25
- data/test/vagrant/action/box/package_test.rb +2 -2
- data/test/vagrant/action/box/unpackage_test.rb +8 -34
- data/test/vagrant/action/box/verify_test.rb +10 -19
- data/test/vagrant/action/builder_test.rb +0 -15
- data/test/vagrant/action/env/set_test.rb +1 -1
- data/test/vagrant/action/environment_test.rb +8 -26
- data/test/vagrant/action/general/package_test.rb +53 -53
- data/test/vagrant/action/vm/boot_test.rb +5 -22
- data/test/vagrant/action/vm/check_box_test.rb +35 -25
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
- data/test/vagrant/action/vm/customize_test.rb +2 -1
- data/test/vagrant/action/vm/destroy_test.rb +1 -2
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
- data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
- data/test/vagrant/action/vm/discard_state_test.rb +10 -1
- data/test/vagrant/action/vm/export_test.rb +9 -37
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
- data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
- data/test/vagrant/action/vm/halt_test.rb +11 -1
- data/test/vagrant/action/vm/import_test.rb +37 -21
- data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
- data/test/vagrant/action/vm/network_test.rb +8 -7
- data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
- data/test/vagrant/action/vm/nfs_test.rb +20 -45
- data/test/vagrant/action/vm/package_test.rb +1 -1
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
- data/test/vagrant/action/vm/provision_test.rb +10 -17
- data/test/vagrant/action/vm/resume_test.rb +1 -1
- data/test/vagrant/action/vm/share_folders_test.rb +25 -106
- data/test/vagrant/action/vm/suspend_test.rb +1 -1
- data/test/vagrant/action/warden_test.rb +105 -0
- data/test/vagrant/action_test.rb +5 -27
- data/test/vagrant/box_collection_test.rb +44 -0
- data/test/vagrant/box_test.rb +5 -105
- data/test/vagrant/cli_test.rb +35 -0
- data/test/vagrant/command/base_test.rb +23 -0
- data/test/vagrant/command/group_base_test.rb +15 -0
- data/test/vagrant/command/helpers_test.rb +88 -0
- data/test/vagrant/config/base_test.rb +52 -0
- data/test/vagrant/config/error_recorder_test.rb +18 -0
- data/test/vagrant/config/ssh_test.rb +12 -0
- data/test/vagrant/config/vagrant_test.rb +11 -0
- data/test/vagrant/config/vm_test.rb +70 -0
- data/test/vagrant/config_test.rb +113 -206
- data/test/vagrant/data_store_test.rb +68 -0
- data/test/vagrant/downloaders/base_test.rb +1 -1
- data/test/vagrant/downloaders/file_test.rb +4 -3
- data/test/vagrant/downloaders/http_test.rb +14 -4
- data/test/vagrant/environment_test.rb +290 -590
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +1 -1
- data/test/vagrant/hosts/bsd_test.rb +3 -6
- data/test/vagrant/hosts/linux_test.rb +3 -5
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +1 -1
- data/test/vagrant/provisioners/chef_server_test.rb +31 -35
- data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
- data/test/vagrant/provisioners/chef_test.rb +7 -7
- data/test/vagrant/ssh_session_test.rb +3 -10
- data/test/vagrant/ssh_test.rb +25 -33
- data/test/vagrant/systems/linux_test.rb +6 -71
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/resource_logger_test.rb +14 -81
- data/test/vagrant/util/retryable_test.rb +38 -0
- data/test/vagrant/util/template_renderer_test.rb +4 -4
- data/test/vagrant/vm_test.rb +47 -26
- data/vagrant.gemspec +14 -12
- metadata +121 -89
- data/bin/.gitignore +0 -0
- data/lib/vagrant/action/action_exception.rb +0 -16
- data/lib/vagrant/action/env/error_halt.rb +0 -16
- data/lib/vagrant/action/exception_catcher.rb +0 -14
- data/lib/vagrant/action/vm/persist.rb +0 -22
- data/lib/vagrant/active_list.rb +0 -83
- data/lib/vagrant/command.rb +0 -27
- data/lib/vagrant/commands/base.rb +0 -181
- data/lib/vagrant/commands/box.rb +0 -16
- data/lib/vagrant/commands/box/add.rb +0 -30
- data/lib/vagrant/commands/box/list.rb +0 -30
- data/lib/vagrant/commands/box/remove.rb +0 -30
- data/lib/vagrant/commands/box/repackage.rb +0 -35
- data/lib/vagrant/commands/destroy.rb +0 -37
- data/lib/vagrant/commands/halt.rb +0 -43
- data/lib/vagrant/commands/init.rb +0 -36
- data/lib/vagrant/commands/package.rb +0 -81
- data/lib/vagrant/commands/provision.rb +0 -31
- data/lib/vagrant/commands/reload.rb +0 -36
- data/lib/vagrant/commands/resume.rb +0 -35
- data/lib/vagrant/commands/ssh.rb +0 -78
- data/lib/vagrant/commands/ssh_config.rb +0 -45
- data/lib/vagrant/commands/status.rb +0 -125
- data/lib/vagrant/commands/suspend.rb +0 -36
- data/lib/vagrant/commands/up.rb +0 -44
- data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
- data/lib/vagrant/util/translator.rb +0 -35
- data/templates/strings.yml +0 -341
- data/templates/unison/crontab_entry.erb +0 -1
- data/templates/unison/script.erb +0 -71
- data/test/vagrant/action/env/error_halt_test.rb +0 -21
- data/test/vagrant/action/exception_catcher_test.rb +0 -30
- data/test/vagrant/action/vm/persist_test.rb +0 -50
- data/test/vagrant/active_list_test.rb +0 -173
- data/test/vagrant/command_test.rb +0 -53
- data/test/vagrant/commands/base_test.rb +0 -139
- data/test/vagrant/commands/box/add_test.rb +0 -34
- data/test/vagrant/commands/box/list_test.rb +0 -32
- data/test/vagrant/commands/box/remove_test.rb +0 -41
- data/test/vagrant/commands/box/repackage_test.rb +0 -52
- data/test/vagrant/commands/destroy_test.rb +0 -44
- data/test/vagrant/commands/halt_test.rb +0 -50
- data/test/vagrant/commands/init_test.rb +0 -71
- data/test/vagrant/commands/package_test.rb +0 -97
- data/test/vagrant/commands/provision_test.rb +0 -60
- data/test/vagrant/commands/reload_test.rb +0 -47
- data/test/vagrant/commands/resume_test.rb +0 -44
- data/test/vagrant/commands/ssh_config_test.rb +0 -77
- data/test/vagrant/commands/ssh_test.rb +0 -129
- data/test/vagrant/commands/status_test.rb +0 -40
- data/test/vagrant/commands/suspend_test.rb +0 -44
- data/test/vagrant/commands/up_test.rb +0 -49
- data/test/vagrant/util/translator_test.rb +0 -61
- data/test/vagrant/util_test.rb +0 -27
@@ -0,0 +1,88 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandHelpersTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@module = Vagrant::Command::Helpers
|
6
|
+
@command = Class.new(Vagrant::Command::Base) do
|
7
|
+
argument :name, :optional => true, :type => :string
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def command(args, env)
|
12
|
+
@command.new(args, {}, { :env => env })
|
13
|
+
end
|
14
|
+
|
15
|
+
context "initializing environment" do
|
16
|
+
should "raise an exception if no environment is given" do
|
17
|
+
assert_raises(Vagrant::Errors::CLIMissingEnvironment) { command([], nil) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "vms from args" do
|
22
|
+
setup do
|
23
|
+
@env = vagrant_env
|
24
|
+
end
|
25
|
+
|
26
|
+
should "raise an exception if no root path" do
|
27
|
+
@env.stubs(:root_path).returns(nil)
|
28
|
+
|
29
|
+
assert_raises(Vagrant::Errors::NoEnvironmentError) {
|
30
|
+
command([], @env).target_vms
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
should "only calculate the result once" do
|
35
|
+
instance = command([], @env)
|
36
|
+
result = instance.target_vms
|
37
|
+
assert instance.target_vms.equal?(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "without multivm" do
|
41
|
+
setup do
|
42
|
+
@env.stubs(:vms).returns({ :one => 1 })
|
43
|
+
end
|
44
|
+
|
45
|
+
should "raise an exception if a name is specified" do
|
46
|
+
instance = command(["foo"], @env)
|
47
|
+
assert_raises(Vagrant::Errors::MultiVMEnvironmentRequired) {
|
48
|
+
instance.target_vms
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
should "return the VM if no name is specified" do
|
53
|
+
instance = command([], @env)
|
54
|
+
assert_nothing_raised {
|
55
|
+
assert_equal @env.vms.values, instance.target_vms
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with multivm" do
|
61
|
+
setup do
|
62
|
+
@env.stubs(:vms).returns(:one => 1, :two => 2)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "return all the VMs if no name is specified" do
|
66
|
+
instance = command([], @env)
|
67
|
+
assert_equal @env.vms.values, instance.target_vms
|
68
|
+
end
|
69
|
+
|
70
|
+
should "return only the specified VM if a name is given" do
|
71
|
+
instance = command(["one"], @env)
|
72
|
+
assert_equal @env.vms[:one], instance.target_vms.first
|
73
|
+
end
|
74
|
+
|
75
|
+
should "return only the specified VM if name is given in the arg" do
|
76
|
+
instance = command([], @env)
|
77
|
+
assert_equal @env.vms[:two], instance.target_vms("two").first
|
78
|
+
end
|
79
|
+
|
80
|
+
should "raise an exception if an invalid name is given" do
|
81
|
+
instance = command(["foo"], @env)
|
82
|
+
assert_raises(Vagrant::Errors::VMNotFoundError) {
|
83
|
+
instance.target_vms
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigBaseTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Config::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
context "class methods" do
|
9
|
+
should "enable configuration with proper accessor" do
|
10
|
+
klass = Class.new(@klass)
|
11
|
+
acc = :foo
|
12
|
+
Vagrant::Config::Top.expects(:configures).with(acc, klass)
|
13
|
+
klass.configures(acc)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "instance methods" do
|
18
|
+
setup do
|
19
|
+
@base = @klass.new
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return a hash of instance variables" do
|
23
|
+
data = { "foo" => "bar", "bar" => "baz" }
|
24
|
+
|
25
|
+
data.each do |iv, value|
|
26
|
+
@base.instance_variable_set("@#{iv}".to_sym, value)
|
27
|
+
end
|
28
|
+
|
29
|
+
result = @base.instance_variables_hash
|
30
|
+
assert_equal data.length, result.length
|
31
|
+
|
32
|
+
data.each do |iv, value|
|
33
|
+
assert_equal value, result[iv]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "converting to JSON" do
|
38
|
+
should "include magic `json_class`" do
|
39
|
+
@iv_hash = { "foo" => "bar" }
|
40
|
+
@base.expects(:instance_variables_hash).returns(@iv_hash)
|
41
|
+
@json = { 'json_class' => @base.class.name }.merge(@iv_hash).to_json
|
42
|
+
assert_equal @json, @base.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not include env in the JSON hash" do
|
46
|
+
@base.env = "FOO"
|
47
|
+
hash = @base.instance_variables_hash
|
48
|
+
assert !hash.has_key?(:env)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigErrorsTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Config::ErrorRecorder
|
6
|
+
@instance = @klass.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should "not have any errors to start" do
|
10
|
+
assert @instance.errors.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
should "add errors" do
|
14
|
+
key = "vagrant.test.errors.test_key"
|
15
|
+
@instance.add(key)
|
16
|
+
assert_equal key, @instance.errors.first
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigSSHTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@env = vagrant_env
|
6
|
+
end
|
7
|
+
|
8
|
+
should "expand any path when requesting the value" do
|
9
|
+
result = File.expand_path(@env.config.ssh.private_key_path, @env.root_path)
|
10
|
+
assert_equal result, @env.config.ssh.private_key_path
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigVMTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@username = "mitchellh"
|
6
|
+
|
7
|
+
@env = vagrant_env
|
8
|
+
@config = @env.config.vm
|
9
|
+
@env.config.ssh.username = @username
|
10
|
+
end
|
11
|
+
|
12
|
+
context "defining VMs" do
|
13
|
+
should "store the proc by name but not run it" do
|
14
|
+
foo = mock("proc")
|
15
|
+
foo.expects(:call).never
|
16
|
+
|
17
|
+
proc = Proc.new { foo.call }
|
18
|
+
@config.define(:name, &proc)
|
19
|
+
assert @config.defined_vms[:name].proc_stack.include?(proc)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "store the options" do
|
23
|
+
@config.define(:name, :set => true)
|
24
|
+
assert @config.defined_vms[:name].options[:set]
|
25
|
+
end
|
26
|
+
|
27
|
+
should "not have multi-VMs by default" do
|
28
|
+
assert !@config.has_multi_vms?
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have multi-VMs once one is specified" do
|
32
|
+
@config.define(:foo) {}
|
33
|
+
assert @config.has_multi_vms?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "customizing" do
|
38
|
+
should "include the stacked proc runner module" do
|
39
|
+
assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "add the customize proc to the proc stack" do
|
43
|
+
proc = Proc.new {}
|
44
|
+
@config.customize(&proc)
|
45
|
+
assert @config.proc_stack.include?(proc)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "uid/gid" do
|
50
|
+
should "return the shared folder UID if set" do
|
51
|
+
@config.shared_folder_uid = "foo"
|
52
|
+
assert_equal "foo", @config.shared_folder_uid
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return the SSH username if UID not set" do
|
56
|
+
@config.shared_folder_uid = nil
|
57
|
+
assert_equal @username, @config.shared_folder_uid
|
58
|
+
end
|
59
|
+
|
60
|
+
should "return the shared folder GID if set" do
|
61
|
+
@config.shared_folder_gid = "foo"
|
62
|
+
assert_equal "foo", @config.shared_folder_gid
|
63
|
+
end
|
64
|
+
|
65
|
+
should "return the SSH username if GID not set" do
|
66
|
+
@config.shared_folder_gid = nil
|
67
|
+
assert_equal @username, @config.shared_folder_gid
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/test/vagrant/config_test.rb
CHANGED
@@ -1,154 +1,156 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class ConfigTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Config
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with an instance" do
|
5
9
|
setup do
|
6
|
-
@env =
|
7
|
-
@
|
10
|
+
@env = vagrant_env
|
11
|
+
@instance = @klass.new(@env)
|
12
|
+
|
13
|
+
# Don't want validation to occur for these tests
|
14
|
+
@klass::Top.any_instance.stubs(:validate!)
|
8
15
|
end
|
9
16
|
|
10
|
-
should "
|
11
|
-
|
12
|
-
assert_equal result, @env.config.ssh.private_key_path
|
17
|
+
should "initially have an empty queue" do
|
18
|
+
assert @instance.queue.empty?
|
13
19
|
end
|
14
|
-
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
klass
|
20
|
-
|
21
|
-
|
21
|
+
should "reset the config class on load, then execute" do
|
22
|
+
seq = sequence("sequence")
|
23
|
+
@klass.expects(:reset!).with(@env).in_sequence(seq)
|
24
|
+
@klass.expects(:execute!).in_sequence(seq)
|
25
|
+
@instance.load!
|
26
|
+
end
|
27
|
+
|
28
|
+
should "run the queue in the order given" do
|
29
|
+
@instance.queue << Proc.new { |config| config.vm.box = "foo" }
|
30
|
+
@instance.queue << Proc.new { |config| config.vm.box = "bar" }
|
31
|
+
result = @instance.load!
|
32
|
+
|
33
|
+
assert_equal "bar", result.vm.box
|
34
|
+
end
|
35
|
+
|
36
|
+
should "allow nested arrays" do
|
37
|
+
queue = []
|
38
|
+
queue << Proc.new { |config| config.vm.box = "foo" }
|
39
|
+
queue << Proc.new { |config| config.vm.box = "bar" }
|
40
|
+
@instance.queue << queue
|
41
|
+
result = @instance.load!
|
42
|
+
|
43
|
+
assert_equal "bar", result.vm.box
|
44
|
+
end
|
45
|
+
|
46
|
+
should "load a file if it exists" do
|
47
|
+
filename = "foo"
|
48
|
+
File.expects(:exist?).with(filename).returns(true)
|
49
|
+
@instance.expects(:load).with(filename).once
|
50
|
+
|
51
|
+
@instance.queue << filename
|
52
|
+
@instance.load!
|
53
|
+
end
|
54
|
+
|
55
|
+
should "not load a file if it doesn't exist" do
|
56
|
+
filename = "foo"
|
57
|
+
File.expects(:exist?).with(filename).returns(false)
|
58
|
+
@instance.expects(:load).with(filename).never
|
59
|
+
|
60
|
+
@instance.queue << filename
|
61
|
+
@instance.load!
|
62
|
+
end
|
63
|
+
|
64
|
+
should "raise an exception if there is a syntax error in a file" do
|
65
|
+
@instance.queue << "foo"
|
66
|
+
File.expects(:exist?).with("foo").returns(true)
|
67
|
+
@instance.expects(:load).with("foo").raises(SyntaxError.new)
|
68
|
+
|
69
|
+
assert_raises(Vagrant::Errors::VagrantfileSyntaxError) {
|
70
|
+
@instance.load!
|
71
|
+
}
|
22
72
|
end
|
23
73
|
end
|
24
74
|
|
25
75
|
context "resetting" do
|
26
76
|
setup do
|
27
|
-
|
28
|
-
|
77
|
+
@klass::Top.any_instance.stubs(:validate!)
|
78
|
+
@klass.run { |config| }
|
79
|
+
@klass.execute!
|
29
80
|
end
|
30
81
|
|
31
82
|
should "return the same config object typically" do
|
32
|
-
config =
|
33
|
-
assert config.equal?(
|
83
|
+
config = @klass.config
|
84
|
+
assert config.equal?(@klass.config)
|
34
85
|
end
|
35
86
|
|
36
87
|
should "create a new object if cleared" do
|
37
|
-
config =
|
38
|
-
|
39
|
-
assert !config.equal?(
|
88
|
+
config = @klass.config
|
89
|
+
@klass.reset!
|
90
|
+
assert !config.equal?(@klass.config)
|
40
91
|
end
|
41
92
|
|
42
93
|
should "empty the proc stack" do
|
43
|
-
assert
|
44
|
-
|
45
|
-
assert
|
94
|
+
assert !@klass.proc_stack.empty?
|
95
|
+
@klass.reset!
|
96
|
+
assert @klass.proc_stack.empty?
|
46
97
|
end
|
47
98
|
|
48
99
|
should "reload the config object based on the given environment" do
|
49
100
|
env = mock("env")
|
50
|
-
|
51
|
-
|
101
|
+
@klass.expects(:config).with(env).once
|
102
|
+
@klass.reset!(env)
|
52
103
|
end
|
53
104
|
end
|
54
105
|
|
55
106
|
context "initializing" do
|
56
107
|
setup do
|
57
|
-
|
108
|
+
@klass.reset!
|
109
|
+
@klass::Top.any_instance.stubs(:validate!)
|
58
110
|
end
|
59
111
|
|
60
112
|
should "add the given block to the proc stack" do
|
61
113
|
proc = Proc.new {}
|
62
|
-
|
63
|
-
assert_equal [proc],
|
114
|
+
@klass.run(&proc)
|
115
|
+
assert_equal [proc], @klass.proc_stack
|
64
116
|
end
|
65
117
|
|
66
118
|
should "run the proc stack with the config when execute is called" do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
should "not be loaded, initially" do
|
72
|
-
assert !Vagrant::Config.config.loaded?
|
73
|
-
end
|
74
|
-
|
75
|
-
should "be loaded after running" do
|
76
|
-
Vagrant::Config.run {}
|
77
|
-
Vagrant::Config.execute!
|
78
|
-
assert Vagrant::Config.config.loaded?
|
119
|
+
seq = sequence('seq')
|
120
|
+
@klass.expects(:run_procs!).with(@klass.config).once.in_sequence(seq)
|
121
|
+
@klass.config.expects(:validate!).once.in_sequence(seq)
|
122
|
+
@klass.execute!
|
79
123
|
end
|
80
124
|
|
81
125
|
should "return the configuration on execute!" do
|
82
|
-
|
83
|
-
result =
|
84
|
-
assert result.is_a?(
|
126
|
+
@klass.run {}
|
127
|
+
result = @klass.execute!
|
128
|
+
assert result.is_a?(@klass::Top)
|
85
129
|
end
|
86
130
|
|
87
131
|
should "use given configuration object if given" do
|
88
132
|
fake_env = mock("env")
|
89
|
-
config =
|
90
|
-
result =
|
133
|
+
config = @klass::Top.new(fake_env)
|
134
|
+
result = @klass.execute!(config)
|
91
135
|
assert_equal config.env, result.env
|
92
136
|
end
|
93
137
|
end
|
94
138
|
|
95
|
-
context "base class" do
|
96
|
-
setup do
|
97
|
-
@base = Vagrant::Config::Base.new
|
98
|
-
end
|
99
|
-
|
100
|
-
should "forward [] access to methods" do
|
101
|
-
@base.expects(:foo).once
|
102
|
-
@base[:foo]
|
103
|
-
end
|
104
|
-
|
105
|
-
should "return a hash of instance variables" do
|
106
|
-
data = { :foo => "bar", :bar => "baz" }
|
107
|
-
|
108
|
-
data.each do |iv, value|
|
109
|
-
@base.instance_variable_set("@#{iv}".to_sym, value)
|
110
|
-
end
|
111
|
-
|
112
|
-
result = @base.instance_variables_hash
|
113
|
-
assert_equal data.length, result.length
|
114
|
-
|
115
|
-
data.each do |iv, value|
|
116
|
-
assert_equal value, result[iv]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "converting to JSON" do
|
121
|
-
should "convert instance variable hash to json" do
|
122
|
-
@json = mock("json")
|
123
|
-
@iv_hash = mock("iv_hash")
|
124
|
-
@iv_hash.expects(:to_json).once.returns(@json)
|
125
|
-
@base.expects(:instance_variables_hash).returns(@iv_hash)
|
126
|
-
assert_equal @json, @base.to_json
|
127
|
-
end
|
128
|
-
|
129
|
-
should "not include env in the JSON hash" do
|
130
|
-
@base.env = "FOO"
|
131
|
-
hash = @base.instance_variables_hash
|
132
|
-
assert !hash.has_key?(:env)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
139
|
context "top config class" do
|
138
140
|
setup do
|
139
141
|
@configures_list = []
|
140
|
-
|
142
|
+
@klass::Top.stubs(:configures_list).returns(@configures_list)
|
141
143
|
end
|
142
144
|
|
143
145
|
context "adding configure keys" do
|
144
146
|
setup do
|
145
147
|
@key = "top_config_foo"
|
146
|
-
@
|
148
|
+
@config_klass = mock("klass")
|
147
149
|
end
|
148
150
|
|
149
151
|
should "add key and klass to configures list" do
|
150
|
-
@configures_list.expects(:<<).with([@key, @
|
151
|
-
|
152
|
+
@configures_list.expects(:<<).with([@key, @config_klass])
|
153
|
+
@klass::Top.configures(@key, @config_klass)
|
152
154
|
end
|
153
155
|
end
|
154
156
|
|
@@ -169,7 +171,7 @@ class ConfigTest < Test::Unit::TestCase
|
|
169
171
|
@configures_list << [key, klass]
|
170
172
|
end
|
171
173
|
|
172
|
-
|
174
|
+
@klass::Top.new(env)
|
173
175
|
end
|
174
176
|
|
175
177
|
should "allow reading via methods" do
|
@@ -178,129 +180,34 @@ class ConfigTest < Test::Unit::TestCase
|
|
178
180
|
instance = mock("instance")
|
179
181
|
instance.stubs(:env=)
|
180
182
|
klass.expects(:new).returns(instance)
|
181
|
-
|
183
|
+
@klass::Top.configures(key, klass)
|
182
184
|
|
183
|
-
config =
|
185
|
+
config = @klass::Top.new
|
184
186
|
assert_equal instance, config.send(key)
|
185
187
|
end
|
186
188
|
end
|
187
189
|
|
188
|
-
context "
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
assert !@top.loaded?
|
190
|
+
context "validation" do
|
191
|
+
should "do nothing if no errors are added" do
|
192
|
+
valid_class = Class.new(@klass::Base)
|
193
|
+
@klass::Top.configures(:subconfig, valid_class)
|
194
|
+
instance = @klass::Top.new
|
195
|
+
assert_nothing_raised { instance.validate! }
|
195
196
|
end
|
196
197
|
|
197
|
-
should "
|
198
|
-
@
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
context "deep cloning" do
|
204
|
-
class DeepCloneConfig < Vagrant::Config::Base
|
205
|
-
attr_accessor :attribute
|
206
|
-
end
|
207
|
-
|
208
|
-
setup do
|
209
|
-
Vagrant::Config::Top.configures :deep, DeepCloneConfig
|
210
|
-
@top = Vagrant::Config::Top.new
|
211
|
-
@top.deep.attribute = [1,2,3]
|
212
|
-
end
|
213
|
-
|
214
|
-
should "deep clone the object" do
|
215
|
-
copy = @top.deep_clone
|
216
|
-
copy.deep.attribute << 4
|
217
|
-
assert_not_equal @top.deep.attribute, copy.deep.attribute
|
218
|
-
assert_equal 3, @top.deep.attribute.length
|
219
|
-
assert_equal 4, copy.deep.attribute.length
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "vagrant configuration" do
|
225
|
-
setup do
|
226
|
-
@config = Vagrant::Config::VagrantConfig.new
|
227
|
-
end
|
228
|
-
|
229
|
-
should "return nil if home is nil" do
|
230
|
-
File.expects(:expand_path).never
|
231
|
-
assert @config.home.nil?
|
232
|
-
end
|
233
|
-
|
234
|
-
should "expand the path if home is not nil" do
|
235
|
-
@config.home = "foo"
|
236
|
-
File.expects(:expand_path).with("foo").once.returns("result")
|
237
|
-
assert_equal "result", @config.home
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
context "VM configuration" do
|
242
|
-
setup do
|
243
|
-
@env = mock_environment
|
244
|
-
@config = @env.config.vm
|
245
|
-
@env.config.ssh.username = @username
|
246
|
-
end
|
247
|
-
|
248
|
-
context "defining VMs" do
|
249
|
-
should "store the proc by name but not run it" do
|
250
|
-
foo = mock("proc")
|
251
|
-
foo.expects(:call).never
|
252
|
-
|
253
|
-
proc = Proc.new { foo.call }
|
254
|
-
@config.define(:name, &proc)
|
255
|
-
assert @config.defined_vms[:name].proc_stack.include?(proc)
|
256
|
-
end
|
257
|
-
|
258
|
-
should "store the options" do
|
259
|
-
@config.define(:name, :set => true)
|
260
|
-
assert @config.defined_vms[:name].options[:set]
|
261
|
-
end
|
262
|
-
|
263
|
-
should "not have multi-VMs by default" do
|
264
|
-
assert !@config.has_multi_vms?
|
265
|
-
end
|
266
|
-
|
267
|
-
should "have multi-VMs once one is specified" do
|
268
|
-
@config.define(:foo) {}
|
269
|
-
assert @config.has_multi_vms?
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
context "customizing" do
|
274
|
-
should "include the stacked proc runner module" do
|
275
|
-
assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner)
|
276
|
-
end
|
277
|
-
|
278
|
-
should "add the customize proc to the proc stack" do
|
279
|
-
proc = Proc.new {}
|
280
|
-
@config.customize(&proc)
|
281
|
-
assert_equal [proc], @config.proc_stack
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
context "uid/gid" do
|
286
|
-
should "return the shared folder UID if set" do
|
287
|
-
@config.shared_folder_uid = "foo"
|
288
|
-
assert_equal "foo", @config.shared_folder_uid
|
289
|
-
end
|
290
|
-
|
291
|
-
should "return the SSH username if UID not set" do
|
292
|
-
@config.shared_folder_uid = nil
|
293
|
-
assert_equal @username, @config.shared_folder_uid
|
294
|
-
end
|
198
|
+
should "raise an exception if there are errors" do
|
199
|
+
invalid_class = Class.new(@klass::Base) do
|
200
|
+
def validate(errors)
|
201
|
+
errors.add("vagrant.test.errors.test_key")
|
202
|
+
end
|
203
|
+
end
|
295
204
|
|
296
|
-
|
297
|
-
|
298
|
-
assert_equal "foo", @config.shared_folder_gid
|
299
|
-
end
|
205
|
+
@klass::Top.configures(:subconfig, invalid_class)
|
206
|
+
instance = @klass::Top.new
|
300
207
|
|
301
|
-
|
302
|
-
|
303
|
-
|
208
|
+
assert_raises(Vagrant::Errors::ConfigValidationFailed) {
|
209
|
+
instance.validate!
|
210
|
+
}
|
304
211
|
end
|
305
212
|
end
|
306
213
|
end
|