vagrantup 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/config/default.rb +13 -3
- data/lib/vagrant.rb +10 -13
- data/lib/vagrant/actions/base.rb +14 -2
- data/lib/vagrant/actions/box/download.rb +2 -7
- data/lib/vagrant/actions/box/verify.rb +1 -1
- data/lib/vagrant/actions/runner.rb +0 -1
- data/lib/vagrant/actions/vm/boot.rb +2 -6
- data/lib/vagrant/actions/vm/customize.rb +7 -5
- data/lib/vagrant/actions/vm/destroy.rb +4 -3
- data/lib/vagrant/actions/vm/down.rb +6 -3
- data/lib/vagrant/actions/vm/export.rb +2 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +77 -16
- data/lib/vagrant/actions/vm/halt.rb +10 -2
- data/lib/vagrant/actions/vm/import.rb +2 -4
- data/lib/vagrant/actions/vm/move_hard_drive.rb +2 -2
- data/lib/vagrant/actions/vm/network.rb +120 -0
- data/lib/vagrant/actions/vm/package.rb +11 -7
- data/lib/vagrant/actions/vm/provision.rb +3 -3
- data/lib/vagrant/actions/vm/reload.rb +2 -9
- data/lib/vagrant/actions/vm/shared_folders.rb +19 -39
- data/lib/vagrant/actions/vm/start.rb +10 -2
- data/lib/vagrant/actions/vm/up.rb +5 -6
- data/lib/vagrant/active_list.rb +23 -13
- data/lib/vagrant/box.rb +2 -2
- data/lib/vagrant/busy.rb +3 -3
- data/lib/vagrant/command.rb +2 -2
- data/lib/vagrant/commands/base.rb +40 -20
- data/lib/vagrant/commands/destroy.rb +17 -3
- data/lib/vagrant/commands/halt.rb +23 -3
- data/lib/vagrant/commands/package.rb +54 -14
- data/lib/vagrant/commands/provision.rb +31 -0
- data/lib/vagrant/commands/reload.rb +16 -3
- data/lib/vagrant/commands/resume.rb +16 -3
- data/lib/vagrant/commands/ssh.rb +25 -3
- data/lib/vagrant/commands/ssh_config.rb +20 -5
- data/lib/vagrant/commands/status.rb +107 -40
- data/lib/vagrant/commands/suspend.rb +16 -3
- data/lib/vagrant/commands/up.rb +26 -7
- data/lib/vagrant/config.rb +82 -12
- data/lib/vagrant/downloaders/base.rb +8 -1
- data/lib/vagrant/downloaders/http.rb +31 -19
- data/lib/vagrant/environment.rb +146 -49
- data/lib/vagrant/provisioners/base.rb +19 -5
- data/lib/vagrant/provisioners/chef.rb +12 -4
- data/lib/vagrant/provisioners/chef_server.rb +13 -6
- data/lib/vagrant/provisioners/chef_solo.rb +7 -3
- data/lib/vagrant/resource_logger.rb +126 -0
- data/lib/vagrant/ssh.rb +109 -8
- data/lib/vagrant/systems/base.rb +70 -0
- data/lib/vagrant/systems/linux.rb +137 -0
- data/lib/vagrant/util.rb +1 -45
- data/lib/vagrant/util/error_helper.rb +13 -0
- data/lib/vagrant/util/glob_loader.rb +22 -0
- data/lib/vagrant/util/output_helper.rb +9 -0
- data/lib/vagrant/util/plain_logger.rb +12 -0
- data/lib/vagrant/util/platform.rb +7 -2
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/util/translator.rb +35 -0
- data/lib/vagrant/vm.rb +91 -10
- data/templates/crontab_entry.erb +1 -0
- data/templates/network_entry.erb +8 -0
- data/templates/ssh_config.erb +1 -0
- data/templates/{errors.yml → strings.yml} +111 -3
- data/templates/sync.erb +14 -0
- data/test/test_helper.rb +46 -3
- data/test/vagrant/actions/box/download_test.rb +0 -17
- data/test/vagrant/actions/vm/boot_test.rb +3 -10
- data/test/vagrant/actions/vm/customize_test.rb +6 -0
- data/test/vagrant/actions/vm/destroy_test.rb +6 -5
- data/test/vagrant/actions/vm/down_test.rb +5 -11
- data/test/vagrant/actions/vm/export_test.rb +1 -0
- data/test/vagrant/actions/vm/forward_ports_test.rb +92 -15
- data/test/vagrant/actions/vm/halt_test.rb +36 -4
- data/test/vagrant/actions/vm/import_test.rb +2 -0
- data/test/vagrant/actions/vm/network_test.rb +237 -0
- data/test/vagrant/actions/vm/package_test.rb +35 -5
- data/test/vagrant/actions/vm/provision_test.rb +3 -3
- data/test/vagrant/actions/vm/reload_test.rb +1 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +41 -74
- data/test/vagrant/actions/vm/start_test.rb +41 -3
- data/test/vagrant/actions/vm/up_test.rb +10 -21
- data/test/vagrant/active_list_test.rb +28 -43
- data/test/vagrant/commands/base_test.rb +25 -4
- data/test/vagrant/commands/destroy_test.rb +24 -12
- data/test/vagrant/commands/halt_test.rb +33 -11
- data/test/vagrant/commands/package_test.rb +77 -57
- data/test/vagrant/commands/provision_test.rb +50 -0
- data/test/vagrant/commands/reload_test.rb +27 -11
- data/test/vagrant/commands/resume_test.rb +25 -14
- data/test/vagrant/commands/ssh_config_test.rb +40 -17
- data/test/vagrant/commands/ssh_test.rb +52 -13
- data/test/vagrant/commands/status_test.rb +21 -1
- data/test/vagrant/commands/suspend_test.rb +25 -14
- data/test/vagrant/commands/up_test.rb +25 -19
- data/test/vagrant/config_test.rb +74 -18
- data/test/vagrant/downloaders/base_test.rb +2 -1
- data/test/vagrant/downloaders/http_test.rb +18 -8
- data/test/vagrant/environment_test.rb +245 -77
- data/test/vagrant/provisioners/base_test.rb +4 -4
- data/test/vagrant/provisioners/chef_server_test.rb +18 -7
- data/test/vagrant/provisioners/chef_solo_test.rb +17 -7
- data/test/vagrant/provisioners/chef_test.rb +22 -9
- data/test/vagrant/resource_logger_test.rb +144 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +42 -2
- data/test/vagrant/systems/linux_test.rb +174 -0
- data/test/vagrant/util/error_helper_test.rb +5 -0
- data/test/vagrant/util/output_helper_test.rb +5 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/{errors_test.rb → translator_test.rb} +25 -21
- data/test/vagrant/util_test.rb +12 -49
- data/test/vagrant/vm_test.rb +133 -11
- data/vagrant.gemspec +39 -15
- metadata +38 -14
- data/lib/vagrant/commands/down.rb +0 -16
- data/lib/vagrant/util/errors.rb +0 -36
- data/lib/vagrant/util/progress_meter.rb +0 -33
- data/test/vagrant/commands/down_test.rb +0 -17
- data/test/vagrant/util/progress_meter_test.rb +0 -33
@@ -0,0 +1,174 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class LinuxSystemTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Systems::Linux
|
6
|
+
@ssh = mock("ssh")
|
7
|
+
@mock_env = mock_environment
|
8
|
+
@vm = mock("vm")
|
9
|
+
@vm.stubs(:env).returns(@mock_env)
|
10
|
+
@instance = @klass.new(@vm)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "halting" do
|
14
|
+
setup do
|
15
|
+
@ssh_session = mock("ssh_session")
|
16
|
+
@ssh.stubs(:execute).yields(@ssh_session)
|
17
|
+
@vm.stubs(:ssh).returns(@ssh)
|
18
|
+
|
19
|
+
@real_vm = mock("real_vm")
|
20
|
+
@real_vm.stubs(:state).returns(:powered_off)
|
21
|
+
@vm.stubs(:vm).returns(@real_vm)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "execute halt via SSH" do
|
25
|
+
@ssh_session.expects(:exec!).with("sudo halt").once
|
26
|
+
@instance.halt
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "mounting shared folders" do
|
31
|
+
setup do
|
32
|
+
@name = "foo"
|
33
|
+
@guestpath = "/bar"
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create the dir, mount the folder, then set permissions" do
|
37
|
+
mount_seq = sequence("mount_seq")
|
38
|
+
@ssh.expects(:exec!).with("sudo mkdir -p #{@guestpath}").in_sequence(mount_seq)
|
39
|
+
@instance.expects(:mount_folder).with(@ssh, @name, @guestpath).in_sequence(mount_seq)
|
40
|
+
@ssh.expects(:exec!).with("sudo chown #{@vm.env.config.ssh.username} #{@guestpath}").in_sequence(mount_seq)
|
41
|
+
|
42
|
+
@instance.mount_shared_folder(@ssh, @name, @guestpath)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "preparing sync" do
|
47
|
+
setup do
|
48
|
+
@ssh.stubs(:exec!)
|
49
|
+
@vm.stubs(:ssh).returns(@ssh)
|
50
|
+
@vm.ssh.stubs(:upload!)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "upload the sync template" do
|
54
|
+
@vm.ssh.expects(:upload!).with do |string_io, guest_path|
|
55
|
+
string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.sync_script
|
56
|
+
end
|
57
|
+
|
58
|
+
@instance.prepare_sync(@ssh)
|
59
|
+
end
|
60
|
+
|
61
|
+
should "remove old crontab entries file" do
|
62
|
+
@ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.sync_crontab_entry_file}", :error_check => false)
|
63
|
+
@instance.prepare_sync(@ssh)
|
64
|
+
end
|
65
|
+
|
66
|
+
should "prepare the sync template for execution" do
|
67
|
+
@ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.sync_script}")
|
68
|
+
@instance.prepare_sync(@ssh)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "setting up an sync folder" do
|
73
|
+
setup do
|
74
|
+
@ssh.stubs(:exec!)
|
75
|
+
end
|
76
|
+
|
77
|
+
should "create the new rysnc destination directory" do
|
78
|
+
sync_path = 'foo'
|
79
|
+
@ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}")
|
80
|
+
@instance.create_sync(@ssh, :syncpath => "foo")
|
81
|
+
end
|
82
|
+
|
83
|
+
should "add an entry to the crontab file" do
|
84
|
+
@instance.expects(:render_crontab_entry).returns('foo')
|
85
|
+
@ssh.expects(:exec!).with do |cmd|
|
86
|
+
cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.sync_crontab_entry_file}/
|
87
|
+
end
|
88
|
+
@instance.create_sync(@ssh, {})
|
89
|
+
end
|
90
|
+
|
91
|
+
should "use the crontab entry file to define vagrant users cron entries" do
|
92
|
+
@ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}")
|
93
|
+
@instance.create_sync(@ssh, {})
|
94
|
+
end
|
95
|
+
|
96
|
+
should "chown the sync directory" do
|
97
|
+
@instance.expects(:chown).with(@ssh, "foo")
|
98
|
+
@instance.create_sync(@ssh, :syncpath => "foo")
|
99
|
+
end
|
100
|
+
|
101
|
+
should "return provide a formatted crontab entry that runs every minute" do
|
102
|
+
assert @instance.render_crontab_entry({}).include?("* * * * *")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#-------------------------------------------------------------------
|
107
|
+
# "Private" methods tests
|
108
|
+
#-------------------------------------------------------------------
|
109
|
+
context "mounting the main folder" do
|
110
|
+
setup do
|
111
|
+
@name = "foo"
|
112
|
+
@guestpath = "bar"
|
113
|
+
@sleeptime = 0
|
114
|
+
@limit = 10
|
115
|
+
|
116
|
+
@success_return = false
|
117
|
+
end
|
118
|
+
|
119
|
+
def mount_folder
|
120
|
+
@instance.mount_folder(@ssh, @name, @guestpath, @sleeptime)
|
121
|
+
end
|
122
|
+
|
123
|
+
should "execute the proper mount command" do
|
124
|
+
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@vm.env.config.ssh.username},gid=#{@vm.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
|
125
|
+
mount_folder
|
126
|
+
end
|
127
|
+
|
128
|
+
should "test type of text and text string to detect error" do
|
129
|
+
data = mock("data")
|
130
|
+
data.expects(:[]=).with(:result, !@success_return)
|
131
|
+
|
132
|
+
@ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
|
133
|
+
mount_folder
|
134
|
+
end
|
135
|
+
|
136
|
+
should "test type of text and test string to detect success" do
|
137
|
+
data = mock("data")
|
138
|
+
data.expects(:[]=).with(:result, @success_return)
|
139
|
+
|
140
|
+
@ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
|
141
|
+
mount_folder
|
142
|
+
end
|
143
|
+
|
144
|
+
should "raise an ActionException if the command fails constantly" do
|
145
|
+
@ssh.expects(:exec!).times(@limit).returns(!@success_return)
|
146
|
+
|
147
|
+
assert_raises(Vagrant::Actions::ActionException) {
|
148
|
+
mount_folder
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
should "not raise any exception if the command succeeded" do
|
153
|
+
@ssh.expects(:exec!).once.returns(@success_return)
|
154
|
+
|
155
|
+
assert_nothing_raised {
|
156
|
+
mount_folder
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
should "add uid AND gid to mount" do
|
161
|
+
uid = "foo"
|
162
|
+
gid = "bar"
|
163
|
+
env = mock_environment do |config|
|
164
|
+
config.vm.shared_folder_uid = uid
|
165
|
+
config.vm.shared_folder_gid = gid
|
166
|
+
end
|
167
|
+
|
168
|
+
@vm.stubs(:env).returns(env)
|
169
|
+
|
170
|
+
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
|
171
|
+
mount_folder
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class PlainLoggerUtilTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Util::PlainLogger
|
6
|
+
@instance = @klass.new(nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "inherit from the standard logger" do
|
10
|
+
assert @instance.is_a?(::Logger)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "just add a newline to the message" do
|
14
|
+
msg = "foo bar baz"
|
15
|
+
assert_equal "#{msg}\n", @instance.format_message("1", "2", "3", msg)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class PlatformTest < Test::Unit::TestCase
|
4
|
+
context "file options" do
|
5
|
+
should "include add binary bit to options on windows platform" do
|
6
|
+
# This constant is not defined on non-windows platforms, so define it here
|
7
|
+
File::BINARY = 4096 unless defined?(File::BINARY)
|
8
|
+
|
9
|
+
Mario::Platform.expects(:windows?).returns(true)
|
10
|
+
assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
|
11
|
+
end
|
12
|
+
|
13
|
+
should "not include binary bit on other platforms" do
|
14
|
+
Mario::Platform.expects(:windows?).returns(false)
|
15
|
+
assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,56 +1,60 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class TranslatorUtilTest < Test::Unit::TestCase
|
4
4
|
include Vagrant::Util
|
5
5
|
|
6
|
+
setup do
|
7
|
+
@klass = Translator
|
8
|
+
end
|
9
|
+
|
6
10
|
context "loading the errors from the YML" do
|
7
11
|
setup do
|
8
12
|
YAML.stubs(:load_file)
|
9
|
-
|
13
|
+
@klass.reset!
|
10
14
|
end
|
11
15
|
|
12
16
|
should "load the file initially, then never again unless reset" do
|
13
|
-
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).once
|
18
|
+
@klass.strings
|
19
|
+
@klass.strings
|
20
|
+
@klass.strings
|
21
|
+
@klass.strings
|
18
22
|
end
|
19
23
|
|
20
24
|
should "reload if reset! is called" do
|
21
|
-
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).twice
|
26
|
+
@klass.strings
|
27
|
+
@klass.reset!
|
28
|
+
@klass.strings
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
context "getting the
|
32
|
+
context "getting the string translated" do
|
29
33
|
setup do
|
30
|
-
@
|
31
|
-
@
|
32
|
-
|
34
|
+
@strings = {}
|
35
|
+
@strings[:foo] = "foo bar baz"
|
36
|
+
@klass.stubs(:strings).returns(@strings)
|
33
37
|
end
|
34
38
|
|
35
39
|
should "render the error string" do
|
36
|
-
TemplateRenderer.expects(:render_string).with(@
|
37
|
-
|
40
|
+
TemplateRenderer.expects(:render_string).with(@strings[:foo], anything).once
|
41
|
+
@klass.t(:foo)
|
38
42
|
end
|
39
43
|
|
40
44
|
should "pass in any data entries" do
|
41
45
|
data = mock("data")
|
42
|
-
TemplateRenderer.expects(:render_string).with(@
|
43
|
-
|
46
|
+
TemplateRenderer.expects(:render_string).with(@strings[:foo], data).once
|
47
|
+
@klass.t(:foo, data)
|
44
48
|
end
|
45
49
|
|
46
50
|
should "return the result of the render" do
|
47
51
|
result = mock("result")
|
48
52
|
TemplateRenderer.expects(:render_string).returns(result)
|
49
|
-
assert_equal result,
|
53
|
+
assert_equal result, @klass.t(:foo)
|
50
54
|
end
|
51
55
|
|
52
56
|
should "return an unknown if the key doesn't exist" do
|
53
|
-
result =
|
57
|
+
result = @klass.t(:unknown)
|
54
58
|
assert result =~ /Unknown/i
|
55
59
|
end
|
56
60
|
end
|
data/test/vagrant/util_test.rb
CHANGED
@@ -1,64 +1,27 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class UtilTest < Test::Unit::TestCase
|
4
|
-
class
|
5
|
-
|
4
|
+
class UtilIncludeTest
|
5
|
+
include Vagrant::Util
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
# otherwise
|
8
|
+
setup do
|
9
|
+
@klass = UtilIncludeTest
|
11
10
|
end
|
12
11
|
|
13
|
-
context "
|
14
|
-
|
15
|
-
|
12
|
+
context "with a class" do
|
13
|
+
should "have the util methods" do
|
14
|
+
assert @klass.respond_to?(:error_and_exit)
|
16
15
|
end
|
16
|
+
end
|
17
17
|
|
18
|
+
context "with an instance" do
|
18
19
|
setup do
|
19
|
-
@
|
20
|
-
@config.stubs(:loaded?).returns(true)
|
21
|
-
@config.vagrant.log_output = STDOUT
|
22
|
-
Vagrant::Config.stubs(:config).returns(@config)
|
23
|
-
Vagrant::Logger.reset_logger!
|
24
|
-
end
|
25
|
-
|
26
|
-
teardown do
|
27
|
-
Vagrant::Logger.reset_logger!
|
28
|
-
end
|
29
|
-
|
30
|
-
should "return a logger to nil if config is not loaded" do
|
31
|
-
@config.expects(:loaded?).returns(false)
|
32
|
-
logger = RegUtil.logger
|
33
|
-
assert_nil logger.instance_variable_get(:@logdev)
|
34
|
-
end
|
35
|
-
|
36
|
-
should "return a logger using the configured output" do
|
37
|
-
logger = RegUtil.logger
|
38
|
-
logdev = logger.instance_variable_get(:@logdev)
|
39
|
-
assert logger
|
40
|
-
assert !logdev.nil?
|
41
|
-
assert_equal STDOUT, logdev.dev
|
42
|
-
end
|
43
|
-
|
44
|
-
should "only instantiate a logger once" do
|
45
|
-
Vagrant::Logger.expects(:new).once.returns("GOOD")
|
46
|
-
RegUtil.logger
|
47
|
-
RegUtil.logger
|
20
|
+
@instance = @klass.new
|
48
21
|
end
|
49
22
|
|
50
|
-
should "
|
51
|
-
|
52
|
-
RegUtil.logger
|
53
|
-
Vagrant::Logger.reset_logger!
|
54
|
-
RegUtil.logger
|
55
|
-
end
|
56
|
-
|
57
|
-
should "return the same logger across classes" do
|
58
|
-
logger = RegUtil.logger
|
59
|
-
other = OtherUtil.logger
|
60
|
-
|
61
|
-
assert logger.equal?(other)
|
23
|
+
should "have the util methods" do
|
24
|
+
assert @instance.respond_to?(:error_and_exit)
|
62
25
|
end
|
63
26
|
end
|
64
27
|
end
|
data/test/vagrant/vm_test.rb
CHANGED
@@ -14,20 +14,22 @@ class VMTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
context "being an action runner" do
|
16
16
|
should "be an action runner" do
|
17
|
-
vm = Vagrant::VM.new
|
17
|
+
vm = Vagrant::VM.new(:env => @env)
|
18
18
|
assert vm.is_a?(Vagrant::Actions::Runner)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context "finding a VM" do
|
23
|
-
should "return
|
23
|
+
should "return return an uncreated VM object if the VM is not found" do
|
24
24
|
VirtualBox::VM.expects(:find).returns(nil)
|
25
|
-
|
25
|
+
result = Vagrant::VM.find("foo")
|
26
|
+
assert result.is_a?(Vagrant::VM)
|
27
|
+
assert !result.created?
|
26
28
|
end
|
27
29
|
|
28
|
-
should "return a Vagrant::VM object for that VM
|
30
|
+
should "return a Vagrant::VM object for that VM if found" do
|
29
31
|
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
30
|
-
result = Vagrant::VM.find("foo")
|
32
|
+
result = Vagrant::VM.find("foo", mock_environment)
|
31
33
|
assert result.is_a?(Vagrant::VM)
|
32
34
|
assert_equal "bar", result.vm
|
33
35
|
end
|
@@ -35,10 +37,98 @@ class VMTest < Test::Unit::TestCase
|
|
35
37
|
|
36
38
|
context "vagrant VM instance" do
|
37
39
|
setup do
|
38
|
-
@
|
40
|
+
@vm_name = "foo"
|
41
|
+
@vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :vm_name => @vm_name)
|
39
42
|
@mock_vm.stubs(:uuid).returns("foo")
|
40
43
|
end
|
41
44
|
|
45
|
+
context "checking if created" do
|
46
|
+
should "return true if the VM object is not nil" do
|
47
|
+
@vm.stubs(:vm).returns(:foo)
|
48
|
+
assert @vm.created?
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return false if the VM object is nil" do
|
52
|
+
@vm.stubs(:vm).returns(nil)
|
53
|
+
assert !@vm.created?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "accessing the SSH object" do
|
58
|
+
setup do
|
59
|
+
# Reset this to nil to force the reload
|
60
|
+
@vm.instance_variable_set(:@ssh, nil)
|
61
|
+
|
62
|
+
@ssh = mock("ssh")
|
63
|
+
Vagrant::SSH.stubs(:new).returns(@ssh)
|
64
|
+
end
|
65
|
+
|
66
|
+
should "load it the first time" do
|
67
|
+
Vagrant::SSH.expects(:new).with(@vm.env).once.returns(@ssh)
|
68
|
+
@vm.ssh
|
69
|
+
@vm.ssh
|
70
|
+
@vm.ssh
|
71
|
+
end
|
72
|
+
|
73
|
+
should "use the same value once its loaded" do
|
74
|
+
result = @vm.ssh
|
75
|
+
assert_equal result, @vm.ssh
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "loading associated system" do
|
80
|
+
should "error and exit if system is not specified" do
|
81
|
+
@vm.env.config.vm.system = nil
|
82
|
+
|
83
|
+
@vm.expects(:error_and_exit).with(:system_unspecified).once
|
84
|
+
@vm.load_system!
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with a class" do
|
88
|
+
class FakeSystemClass
|
89
|
+
def initialize(vm); end
|
90
|
+
end
|
91
|
+
|
92
|
+
should "initialize class if given" do
|
93
|
+
@vm.env.config.vm.system = Vagrant::Systems::Linux
|
94
|
+
|
95
|
+
@vm.expects(:error_and_exit).never
|
96
|
+
@vm.load_system!
|
97
|
+
|
98
|
+
assert @vm.system.is_a?(Vagrant::Systems::Linux)
|
99
|
+
end
|
100
|
+
|
101
|
+
should "error and exit if class has invalid parent" do
|
102
|
+
@vm.env.config.vm.system = FakeSystemClass
|
103
|
+
@vm.expects(:error_and_exit).with(:system_invalid_class, :system => @vm.env.config.vm.system.to_s).once
|
104
|
+
@vm.load_system!
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with a symbol" do
|
109
|
+
should "initialize proper symbols" do
|
110
|
+
valid = {
|
111
|
+
:linux => Vagrant::Systems::Linux
|
112
|
+
}
|
113
|
+
|
114
|
+
valid.each do |symbol, klass|
|
115
|
+
@vm.env.config.vm.system = symbol
|
116
|
+
@vm.expects(:error_and_exit).never
|
117
|
+
@vm.load_system!
|
118
|
+
|
119
|
+
assert @vm.system.is_a?(klass)
|
120
|
+
assert_equal @vm, @vm.system.vm
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
should "error and exit with invalid symbol" do
|
125
|
+
@vm.env.config.vm.system = :shall_never_exist
|
126
|
+
@vm.expects(:error_and_exit).with(:system_unknown_type, :system => @vm.env.config.vm.system.to_s).once
|
127
|
+
@vm.load_system!
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
42
132
|
context "uuid" do
|
43
133
|
should "call UUID on VM object" do
|
44
134
|
uuid = mock("uuid")
|
@@ -63,12 +153,44 @@ class VMTest < Test::Unit::TestCase
|
|
63
153
|
|
64
154
|
context "packaging" do
|
65
155
|
should "queue up the actions and execute" do
|
66
|
-
|
67
|
-
|
68
|
-
@vm.expects(:add_action).with(Vagrant::Actions::VM::
|
69
|
-
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, out_path, []).once.in_sequence(action_seq)
|
156
|
+
action_seq = sequence("action_seq")
|
157
|
+
@vm.expects(:add_action).with(Vagrant::Actions::VM::Export, nil).once.in_sequence(action_seq)
|
158
|
+
@vm.expects(:add_action).with(Vagrant::Actions::VM::Package, nil).once.in_sequence(action_seq)
|
70
159
|
@vm.expects(:execute!).in_sequence(action_seq)
|
71
|
-
@vm.package
|
160
|
+
@vm.package
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "upping" do
|
165
|
+
should "execute the up action" do
|
166
|
+
@vm.expects(:execute!).with(Vagrant::Actions::VM::Up, nil).once
|
167
|
+
@vm.up
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "halting" do
|
172
|
+
should "execute the halt action" do
|
173
|
+
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, nil).once
|
174
|
+
@vm.halt
|
175
|
+
end
|
176
|
+
|
177
|
+
should "force if specified" do
|
178
|
+
@vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, {:foo => :bar}).once
|
179
|
+
@vm.halt({:foo => :bar})
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "reloading action" do
|
184
|
+
should "execute the reload action" do
|
185
|
+
@vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
|
186
|
+
@vm.reload
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "provisioning" do
|
191
|
+
should "execute the provision action" do
|
192
|
+
@vm.expects(:execute!).with(Vagrant::Actions::VM::Provision).once
|
193
|
+
@vm.provision
|
72
194
|
end
|
73
195
|
end
|
74
196
|
|