vagrant 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +49 -0
- data/README.md +2 -2
- data/Rakefile +22 -0
- data/bin/.gitignore +0 -0
- data/lib/vagrant/provisioners/chef_solo.rb +1 -1
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/version.rb +1 -1
- data/templates/Vagrantfile.erb +1 -1
- data/templates/nfs/exports.erb +4 -2
- data/test/test_helper.rb +128 -0
- data/test/vagrant/action/box/destroy_test.rb +30 -0
- data/test/vagrant/action/box/download_test.rb +141 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +103 -0
- data/test/vagrant/action/box/verify_test.rb +39 -0
- data/test/vagrant/action/builder_test.rb +218 -0
- data/test/vagrant/action/env/error_halt_test.rb +21 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +45 -0
- data/test/vagrant/action/exception_catcher_test.rb +30 -0
- data/test/vagrant/action/general/package_test.rb +254 -0
- data/test/vagrant/action/vm/boot_test.rb +83 -0
- data/test/vagrant/action/vm/check_box_test.rb +48 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +29 -0
- data/test/vagrant/action/vm/destroy_test.rb +26 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
- data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
- data/test/vagrant/action/vm/discard_state_test.rb +36 -0
- data/test/vagrant/action/vm/export_test.rb +135 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
- data/test/vagrant/action/vm/halt_test.rb +69 -0
- data/test/vagrant/action/vm/import_test.rb +50 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
- data/test/vagrant/action/vm/network_test.rb +246 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
- data/test/vagrant/action/vm/nfs_test.rb +269 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/persist_test.rb +50 -0
- data/test/vagrant/action/vm/provision_test.rb +134 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +215 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action_test.rb +111 -0
- data/test/vagrant/active_list_test.rb +173 -0
- data/test/vagrant/box_test.rb +166 -0
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +139 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/box/repackage_test.rb +52 -0
- data/test/vagrant/commands/destroy_test.rb +44 -0
- data/test/vagrant/commands/halt_test.rb +50 -0
- data/test/vagrant/commands/init_test.rb +71 -0
- data/test/vagrant/commands/package_test.rb +97 -0
- data/test/vagrant/commands/provision_test.rb +60 -0
- data/test/vagrant/commands/reload_test.rb +47 -0
- data/test/vagrant/commands/resume_test.rb +44 -0
- data/test/vagrant/commands/ssh_config_test.rb +77 -0
- data/test/vagrant/commands/ssh_test.rb +129 -0
- data/test/vagrant/commands/status_test.rb +40 -0
- data/test/vagrant/commands/suspend_test.rb +44 -0
- data/test/vagrant/commands/up_test.rb +49 -0
- data/test/vagrant/config_test.rb +307 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +33 -0
- data/test/vagrant/downloaders/http_test.rb +70 -0
- data/test/vagrant/environment_test.rb +770 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +56 -0
- data/test/vagrant/hosts/linux_test.rb +56 -0
- data/test/vagrant/provisioners/base_test.rb +36 -0
- data/test/vagrant/provisioners/chef_server_test.rb +182 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
- data/test/vagrant/provisioners/chef_test.rb +178 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +317 -0
- data/test/vagrant/systems/linux_test.rb +179 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +145 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/util/translator_test.rb +61 -0
- data/test/vagrant/util_test.rb +27 -0
- data/test/vagrant/vm_test.rb +228 -0
- data/vagrant.gemspec +34 -0
- metadata +158 -43
@@ -0,0 +1,77 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandsSSHConfigTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Commands::SSHConfig
|
6
|
+
|
7
|
+
@env = mock_environment
|
8
|
+
@env.stubs(:require_root_path)
|
9
|
+
@instance = @klass.new(@env)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "executing" do
|
13
|
+
setup do
|
14
|
+
@instance.stubs(:show_single)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "require root path" do
|
18
|
+
@env.expects(:require_root_path).once
|
19
|
+
@instance.execute
|
20
|
+
end
|
21
|
+
|
22
|
+
should "call show_single with given argument" do
|
23
|
+
@instance.expects(:show_single).with("foo").once
|
24
|
+
@instance.execute(["foo"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "showing a single entry" do
|
29
|
+
setup do
|
30
|
+
@ssh = mock("ssh")
|
31
|
+
@ssh.stubs(:port).returns(2197)
|
32
|
+
|
33
|
+
@bar = mock("vm")
|
34
|
+
@bar.stubs(:env).returns(mock_environment)
|
35
|
+
@bar.stubs(:ssh).returns(@ssh)
|
36
|
+
|
37
|
+
@vms = {:bar => @bar}
|
38
|
+
@env.stubs(:multivm?).returns(true)
|
39
|
+
@env.stubs(:vms).returns(@vms)
|
40
|
+
|
41
|
+
@data = {
|
42
|
+
:host_key => "vagrant",
|
43
|
+
:ssh_user => @bar.env.config.ssh.username,
|
44
|
+
:ssh_port => @bar.ssh.port,
|
45
|
+
:private_key_path => @bar.env.config.ssh.private_key_path
|
46
|
+
}
|
47
|
+
|
48
|
+
@instance.stubs(:puts)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "error if name is nil and multivm" do
|
52
|
+
@env.stubs(:multivm?).returns(true)
|
53
|
+
@instance.expects(:error_and_exit).with(:ssh_config_multivm).once
|
54
|
+
@instance.show_single(nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
should "error if the VM is not found" do
|
58
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => "foo").once
|
59
|
+
@instance.show_single("foo")
|
60
|
+
end
|
61
|
+
|
62
|
+
should "output rendered template" do
|
63
|
+
result = mock("result")
|
64
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data).returns(result)
|
65
|
+
|
66
|
+
@instance.expects(:puts).with(result).once
|
67
|
+
@instance.show_single(:bar)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "render with the given host name if given" do
|
71
|
+
host = "foo"
|
72
|
+
@data[:host_key] = host
|
73
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data)
|
74
|
+
@instance.execute(["bar", "--host", host])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandsSSHTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Commands::SSH
|
6
|
+
|
7
|
+
@env = mock_environment
|
8
|
+
@instance = @klass.new(@env)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "executing" do
|
12
|
+
should "connect to the given argument" do
|
13
|
+
@instance.expects(:ssh_connect).with("foo").once
|
14
|
+
@instance.execute(["foo"])
|
15
|
+
end
|
16
|
+
|
17
|
+
should "connect with nil name if none is given" do
|
18
|
+
@instance.expects(:ssh_connect).with(nil).once
|
19
|
+
@instance.execute
|
20
|
+
end
|
21
|
+
|
22
|
+
should "execute if commands are given" do
|
23
|
+
@env.stubs(:vms).returns(:foo => mock("foo"))
|
24
|
+
@instance.expects(:ssh_execute).with("foo", @env.vms[:foo]).once
|
25
|
+
@instance.execute(["foo","-e","bar"])
|
26
|
+
end
|
27
|
+
|
28
|
+
should "execute over every VM if none is specified with a command" do
|
29
|
+
vms = {
|
30
|
+
:foo => mock("foo"),
|
31
|
+
:bar => mock("bar")
|
32
|
+
}
|
33
|
+
|
34
|
+
@env.stubs(:vms).returns(vms)
|
35
|
+
vms.each do |key, vm|
|
36
|
+
@instance.expects(:ssh_execute).with(key, vm).once
|
37
|
+
end
|
38
|
+
|
39
|
+
@instance.execute(["--execute", "bar"])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "ssh executing" do
|
44
|
+
setup do
|
45
|
+
@name = :foo
|
46
|
+
|
47
|
+
@ssh_conn = mock("connection")
|
48
|
+
@ssh_conn.stubs(:exec!)
|
49
|
+
|
50
|
+
@ssh = mock("ssh")
|
51
|
+
@ssh.stubs(:execute).yields(@ssh_conn)
|
52
|
+
|
53
|
+
@vm = mock("vm")
|
54
|
+
@vm.stubs(:created?).returns(true)
|
55
|
+
@vm.stubs(:ssh).returns(@ssh)
|
56
|
+
@vm.stubs(:env).returns(@env)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "error and exit if invalid VM given" do
|
60
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => @name).once
|
61
|
+
@instance.ssh_execute(@name, nil)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "error and exit if VM isn't created" do
|
65
|
+
@vm.stubs(:created?).returns(false)
|
66
|
+
@instance.expects(:error_and_exit).with(:environment_not_created).once
|
67
|
+
@instance.ssh_execute(@name, @vm)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "execute each command" do
|
71
|
+
commands = [:a,:b,:c]
|
72
|
+
@instance.stubs(:options).returns(:execute => commands)
|
73
|
+
commands.each do |cmd|
|
74
|
+
@ssh_conn.expects(:exec!).with(cmd).once
|
75
|
+
end
|
76
|
+
|
77
|
+
@instance.ssh_execute(@name, @vm)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "ssh connecting" do
|
82
|
+
setup do
|
83
|
+
@vm = mock("vm")
|
84
|
+
@vm.stubs(:created?).returns(true)
|
85
|
+
|
86
|
+
@vms = {:bar => @vm}
|
87
|
+
@env.stubs(:vms).returns(@vms)
|
88
|
+
@env.stubs(:multivm?).returns(false)
|
89
|
+
end
|
90
|
+
|
91
|
+
should "error and exit if no VM is specified and multivm and no primary VM" do
|
92
|
+
@env.stubs(:multivm?).returns(true)
|
93
|
+
@env.stubs(:primary_vm).returns(nil)
|
94
|
+
@instance.expects(:error_and_exit).with(:ssh_multivm).once
|
95
|
+
@instance.ssh_connect(nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
should "use the primary VM if it exists and no name is specified" do
|
99
|
+
vm = mock("vm")
|
100
|
+
ssh = mock("ssh")
|
101
|
+
vm.stubs(:created?).returns(true)
|
102
|
+
vm.stubs(:ssh).returns(ssh)
|
103
|
+
|
104
|
+
@env.stubs(:multivm?).returns(true)
|
105
|
+
@env.stubs(:primary_vm).returns(vm)
|
106
|
+
ssh.expects(:connect).once
|
107
|
+
@instance.ssh_connect(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
should "error and exit if VM is nil" do
|
111
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
112
|
+
@instance.ssh_connect(:foo)
|
113
|
+
end
|
114
|
+
|
115
|
+
should "error and exit if VM isn't created" do
|
116
|
+
@vm.stubs(:created?).returns(false)
|
117
|
+
@instance.expects(:error_and_exit).with(:environment_not_created).once
|
118
|
+
@instance.ssh_connect(:bar)
|
119
|
+
end
|
120
|
+
|
121
|
+
should "ssh connect" do
|
122
|
+
ssh = mock("ssh")
|
123
|
+
@vm.stubs(:ssh).returns(ssh)
|
124
|
+
ssh.expects(:connect)
|
125
|
+
|
126
|
+
@instance.ssh_connect(:bar)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandsStatusTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Commands::Status
|
6
|
+
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
8
|
+
@persisted_vm.stubs(:execute!)
|
9
|
+
|
10
|
+
@env = mock_environment
|
11
|
+
@env.stubs(:require_persisted_vm)
|
12
|
+
@env.stubs(:vm).returns(@persisted_vm)
|
13
|
+
|
14
|
+
@instance = @klass.new(@env)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "executing" do
|
18
|
+
should "show local status by default" do
|
19
|
+
@instance.expects(:show_local_status).once
|
20
|
+
@instance.expects(:show_global_status).never
|
21
|
+
@instance.execute
|
22
|
+
end
|
23
|
+
|
24
|
+
should "show global status if flagged" do
|
25
|
+
@instance.expects(:show_local_status).never
|
26
|
+
@instance.expects(:show_global_status).once
|
27
|
+
@instance.execute(["--global"])
|
28
|
+
end
|
29
|
+
|
30
|
+
should "show help if too many args are given" do
|
31
|
+
@instance.expects(:show_help).once
|
32
|
+
@instance.execute(["1","2","3"])
|
33
|
+
end
|
34
|
+
|
35
|
+
should "pass the VM name to local status if given" do
|
36
|
+
@instance.expects(:show_local_status).with("foo").once
|
37
|
+
@instance.execute(["foo"])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandsSuspendTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Commands::Suspend
|
6
|
+
|
7
|
+
@env = mock_environment
|
8
|
+
@instance = @klass.new(@env)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "executing" do
|
12
|
+
should "call all or single for the method" do
|
13
|
+
@instance.expects(:all_or_single).with([], :suspend)
|
14
|
+
@instance.execute
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "suspending a single VM" do
|
19
|
+
setup do
|
20
|
+
@foo_vm = mock("vm")
|
21
|
+
@foo_vm.stubs(:env).returns(@env)
|
22
|
+
vms = { :foo => @foo_vm }
|
23
|
+
@env.stubs(:vms).returns(vms)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "error and exit if the VM doesn't exist" do
|
27
|
+
@env.stubs(:vms).returns({})
|
28
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
29
|
+
@instance.suspend_single(:foo)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "suspend if its created" do
|
33
|
+
@foo_vm.stubs(:created?).returns(true)
|
34
|
+
@foo_vm.expects(:suspend).once
|
35
|
+
@instance.execute(["foo"])
|
36
|
+
end
|
37
|
+
|
38
|
+
should "do nothing if its not created" do
|
39
|
+
@foo_vm.stubs(:created?).returns(false)
|
40
|
+
@foo_vm.expects(:suspend).never
|
41
|
+
@instance.suspend_single(:foo)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CommandsUpTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Commands::Up
|
6
|
+
|
7
|
+
@env = mock_environment
|
8
|
+
@env.stubs(:require_root_path)
|
9
|
+
@instance = @klass.new(@env)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "executing" do
|
13
|
+
should "call all or single for the method" do
|
14
|
+
seq = sequence("seq")
|
15
|
+
@env.expects(:require_root_path).in_sequence(seq)
|
16
|
+
@instance.expects(:all_or_single).with([], :up).in_sequence(seq)
|
17
|
+
@instance.execute
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "upping a single VM" do
|
22
|
+
setup do
|
23
|
+
@vm = mock("vm")
|
24
|
+
@vm.stubs(:env).returns(@env)
|
25
|
+
|
26
|
+
@vms = {:foo => @vm}
|
27
|
+
@env.stubs(:vms).returns(@vms)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "error and exit if the VM doesn't exist" do
|
31
|
+
@env.stubs(:vms).returns({})
|
32
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
33
|
+
@instance.up_single(:foo)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "start created VMs" do
|
37
|
+
@vm.stubs(:created?).returns(true)
|
38
|
+
@vm.expects(:start).once
|
39
|
+
@instance.up_single(:foo)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "up non-created VMs" do
|
43
|
+
@vm.stubs(:created?).returns(false)
|
44
|
+
@vm.expects(:up).once
|
45
|
+
@vm.expects(:start).never
|
46
|
+
@instance.up_single(:foo)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigTest < Test::Unit::TestCase
|
4
|
+
context "the ssh config" do
|
5
|
+
setup do
|
6
|
+
@env = mock_environment
|
7
|
+
@env.stubs(:root_path).returns("foo")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "expand any path when requesting the value" do
|
11
|
+
result = File.expand_path(@env.config.ssh[:private_key_path], @env.root_path)
|
12
|
+
assert_equal result, @env.config.ssh.private_key_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "adding configures" do
|
17
|
+
should "forward the method to the Top class" do
|
18
|
+
key = mock("key")
|
19
|
+
klass = mock("klass")
|
20
|
+
Vagrant::Config::Top.expects(:configures).with(key, klass)
|
21
|
+
Vagrant::Config.configures(key, klass)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "resetting" do
|
26
|
+
setup do
|
27
|
+
Vagrant::Config.run { |config| }
|
28
|
+
Vagrant::Config.execute!
|
29
|
+
end
|
30
|
+
|
31
|
+
should "return the same config object typically" do
|
32
|
+
config = Vagrant::Config.config
|
33
|
+
assert config.equal?(Vagrant::Config.config)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create a new object if cleared" do
|
37
|
+
config = Vagrant::Config.config
|
38
|
+
Vagrant::Config.reset!
|
39
|
+
assert !config.equal?(Vagrant::Config.config)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "empty the proc stack" do
|
43
|
+
assert !Vagrant::Config.proc_stack.empty?
|
44
|
+
Vagrant::Config.reset!
|
45
|
+
assert Vagrant::Config.proc_stack.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
should "reload the config object based on the given environment" do
|
49
|
+
env = mock("env")
|
50
|
+
Vagrant::Config.expects(:config).with(env).once
|
51
|
+
Vagrant::Config.reset!(env)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "initializing" do
|
56
|
+
setup do
|
57
|
+
Vagrant::Config.reset!
|
58
|
+
end
|
59
|
+
|
60
|
+
should "add the given block to the proc stack" do
|
61
|
+
proc = Proc.new {}
|
62
|
+
Vagrant::Config.run(&proc)
|
63
|
+
assert_equal [proc], Vagrant::Config.proc_stack
|
64
|
+
end
|
65
|
+
|
66
|
+
should "run the proc stack with the config when execute is called" do
|
67
|
+
Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once
|
68
|
+
Vagrant::Config.execute!
|
69
|
+
end
|
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?
|
79
|
+
end
|
80
|
+
|
81
|
+
should "return the configuration on execute!" do
|
82
|
+
Vagrant::Config.run {}
|
83
|
+
result = Vagrant::Config.execute!
|
84
|
+
assert result.is_a?(Vagrant::Config::Top)
|
85
|
+
end
|
86
|
+
|
87
|
+
should "use given configuration object if given" do
|
88
|
+
fake_env = mock("env")
|
89
|
+
config = Vagrant::Config::Top.new(fake_env)
|
90
|
+
result = Vagrant::Config.execute!(config)
|
91
|
+
assert_equal config.env, result.env
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
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
|
+
context "top config class" do
|
138
|
+
setup do
|
139
|
+
@configures_list = []
|
140
|
+
Vagrant::Config::Top.stubs(:configures_list).returns(@configures_list)
|
141
|
+
end
|
142
|
+
|
143
|
+
context "adding configure keys" do
|
144
|
+
setup do
|
145
|
+
@key = "top_config_foo"
|
146
|
+
@klass = mock("klass")
|
147
|
+
end
|
148
|
+
|
149
|
+
should "add key and klass to configures list" do
|
150
|
+
@configures_list.expects(:<<).with([@key, @klass])
|
151
|
+
Vagrant::Config::Top.configures(@key, @klass)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "configuration keys on instance" do
|
156
|
+
setup do
|
157
|
+
@configures_list.clear
|
158
|
+
end
|
159
|
+
|
160
|
+
should "initialize each configurer and set it to its key" do
|
161
|
+
env = mock('env')
|
162
|
+
|
163
|
+
5.times do |i|
|
164
|
+
key = "key#{i}"
|
165
|
+
klass = mock("klass#{i}")
|
166
|
+
instance = mock("instance#{i}")
|
167
|
+
instance.expects(:env=).with(env)
|
168
|
+
klass.expects(:new).returns(instance)
|
169
|
+
@configures_list << [key, klass]
|
170
|
+
end
|
171
|
+
|
172
|
+
Vagrant::Config::Top.new(env)
|
173
|
+
end
|
174
|
+
|
175
|
+
should "allow reading via methods" do
|
176
|
+
key = "my_foo_bar_key"
|
177
|
+
klass = mock("klass")
|
178
|
+
instance = mock("instance")
|
179
|
+
instance.stubs(:env=)
|
180
|
+
klass.expects(:new).returns(instance)
|
181
|
+
Vagrant::Config::Top.configures(key, klass)
|
182
|
+
|
183
|
+
config = Vagrant::Config::Top.new
|
184
|
+
assert_equal instance, config.send(key)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "loaded status" do
|
189
|
+
setup do
|
190
|
+
@top= Vagrant::Config::Top.new
|
191
|
+
end
|
192
|
+
|
193
|
+
should "not be loaded by default" do
|
194
|
+
assert !@top.loaded?
|
195
|
+
end
|
196
|
+
|
197
|
+
should "be loaded after calling loaded!" do
|
198
|
+
@top.loaded!
|
199
|
+
assert @top.loaded?
|
200
|
+
end
|
201
|
+
end
|
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
|
295
|
+
|
296
|
+
should "return the shared folder GID if set" do
|
297
|
+
@config.shared_folder_gid = "foo"
|
298
|
+
assert_equal "foo", @config.shared_folder_gid
|
299
|
+
end
|
300
|
+
|
301
|
+
should "return the SSH username if GID not set" do
|
302
|
+
@config.shared_folder_gid = nil
|
303
|
+
assert_equal @username, @config.shared_folder_gid
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|