vagrant 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/Gemfile +2 -2
  2. data/README.md +2 -2
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/config/default.rb +13 -3
  6. data/lib/vagrant.rb +10 -13
  7. data/lib/vagrant/actions/base.rb +14 -2
  8. data/lib/vagrant/actions/box/download.rb +2 -7
  9. data/lib/vagrant/actions/box/verify.rb +1 -1
  10. data/lib/vagrant/actions/runner.rb +0 -1
  11. data/lib/vagrant/actions/vm/boot.rb +2 -6
  12. data/lib/vagrant/actions/vm/customize.rb +7 -5
  13. data/lib/vagrant/actions/vm/destroy.rb +4 -3
  14. data/lib/vagrant/actions/vm/down.rb +6 -3
  15. data/lib/vagrant/actions/vm/export.rb +2 -4
  16. data/lib/vagrant/actions/vm/forward_ports.rb +77 -16
  17. data/lib/vagrant/actions/vm/halt.rb +10 -2
  18. data/lib/vagrant/actions/vm/import.rb +2 -4
  19. data/lib/vagrant/actions/vm/move_hard_drive.rb +2 -2
  20. data/lib/vagrant/actions/vm/network.rb +120 -0
  21. data/lib/vagrant/actions/vm/package.rb +11 -7
  22. data/lib/vagrant/actions/vm/provision.rb +3 -3
  23. data/lib/vagrant/actions/vm/reload.rb +2 -9
  24. data/lib/vagrant/actions/vm/shared_folders.rb +19 -39
  25. data/lib/vagrant/actions/vm/start.rb +10 -2
  26. data/lib/vagrant/actions/vm/up.rb +5 -6
  27. data/lib/vagrant/active_list.rb +23 -13
  28. data/lib/vagrant/box.rb +2 -2
  29. data/lib/vagrant/busy.rb +3 -3
  30. data/lib/vagrant/command.rb +2 -2
  31. data/lib/vagrant/commands/base.rb +40 -20
  32. data/lib/vagrant/commands/destroy.rb +17 -3
  33. data/lib/vagrant/commands/halt.rb +23 -3
  34. data/lib/vagrant/commands/package.rb +54 -14
  35. data/lib/vagrant/commands/provision.rb +31 -0
  36. data/lib/vagrant/commands/reload.rb +16 -3
  37. data/lib/vagrant/commands/resume.rb +16 -3
  38. data/lib/vagrant/commands/ssh.rb +25 -3
  39. data/lib/vagrant/commands/ssh_config.rb +20 -5
  40. data/lib/vagrant/commands/status.rb +107 -40
  41. data/lib/vagrant/commands/suspend.rb +16 -3
  42. data/lib/vagrant/commands/up.rb +26 -7
  43. data/lib/vagrant/config.rb +82 -12
  44. data/lib/vagrant/downloaders/base.rb +8 -1
  45. data/lib/vagrant/downloaders/http.rb +31 -19
  46. data/lib/vagrant/environment.rb +146 -49
  47. data/lib/vagrant/provisioners/base.rb +19 -5
  48. data/lib/vagrant/provisioners/chef.rb +12 -4
  49. data/lib/vagrant/provisioners/chef_server.rb +13 -6
  50. data/lib/vagrant/provisioners/chef_solo.rb +7 -3
  51. data/lib/vagrant/resource_logger.rb +126 -0
  52. data/lib/vagrant/ssh.rb +109 -8
  53. data/lib/vagrant/systems/base.rb +70 -0
  54. data/lib/vagrant/systems/linux.rb +137 -0
  55. data/lib/vagrant/util.rb +1 -45
  56. data/lib/vagrant/util/error_helper.rb +13 -0
  57. data/lib/vagrant/util/glob_loader.rb +22 -0
  58. data/lib/vagrant/util/output_helper.rb +9 -0
  59. data/lib/vagrant/util/plain_logger.rb +12 -0
  60. data/lib/vagrant/util/platform.rb +7 -2
  61. data/lib/vagrant/util/template_renderer.rb +2 -2
  62. data/lib/vagrant/util/translator.rb +35 -0
  63. data/lib/vagrant/vm.rb +91 -10
  64. data/templates/crontab_entry.erb +1 -0
  65. data/templates/network_entry.erb +8 -0
  66. data/templates/ssh_config.erb +1 -0
  67. data/templates/{errors.yml → strings.yml} +111 -3
  68. data/templates/sync.erb +14 -0
  69. data/test/test_helper.rb +46 -3
  70. data/test/vagrant/actions/box/download_test.rb +0 -17
  71. data/test/vagrant/actions/vm/boot_test.rb +3 -10
  72. data/test/vagrant/actions/vm/customize_test.rb +6 -0
  73. data/test/vagrant/actions/vm/destroy_test.rb +6 -5
  74. data/test/vagrant/actions/vm/down_test.rb +5 -11
  75. data/test/vagrant/actions/vm/export_test.rb +1 -0
  76. data/test/vagrant/actions/vm/forward_ports_test.rb +92 -15
  77. data/test/vagrant/actions/vm/halt_test.rb +36 -4
  78. data/test/vagrant/actions/vm/import_test.rb +2 -0
  79. data/test/vagrant/actions/vm/network_test.rb +237 -0
  80. data/test/vagrant/actions/vm/package_test.rb +35 -5
  81. data/test/vagrant/actions/vm/provision_test.rb +3 -3
  82. data/test/vagrant/actions/vm/reload_test.rb +1 -1
  83. data/test/vagrant/actions/vm/shared_folders_test.rb +41 -74
  84. data/test/vagrant/actions/vm/start_test.rb +41 -3
  85. data/test/vagrant/actions/vm/up_test.rb +10 -21
  86. data/test/vagrant/active_list_test.rb +28 -43
  87. data/test/vagrant/commands/base_test.rb +25 -4
  88. data/test/vagrant/commands/destroy_test.rb +24 -12
  89. data/test/vagrant/commands/halt_test.rb +33 -11
  90. data/test/vagrant/commands/package_test.rb +77 -57
  91. data/test/vagrant/commands/provision_test.rb +50 -0
  92. data/test/vagrant/commands/reload_test.rb +27 -11
  93. data/test/vagrant/commands/resume_test.rb +25 -14
  94. data/test/vagrant/commands/ssh_config_test.rb +40 -17
  95. data/test/vagrant/commands/ssh_test.rb +52 -13
  96. data/test/vagrant/commands/status_test.rb +21 -1
  97. data/test/vagrant/commands/suspend_test.rb +25 -14
  98. data/test/vagrant/commands/up_test.rb +25 -19
  99. data/test/vagrant/config_test.rb +74 -18
  100. data/test/vagrant/downloaders/base_test.rb +2 -1
  101. data/test/vagrant/downloaders/http_test.rb +18 -8
  102. data/test/vagrant/environment_test.rb +245 -77
  103. data/test/vagrant/provisioners/base_test.rb +4 -4
  104. data/test/vagrant/provisioners/chef_server_test.rb +18 -7
  105. data/test/vagrant/provisioners/chef_solo_test.rb +17 -7
  106. data/test/vagrant/provisioners/chef_test.rb +22 -9
  107. data/test/vagrant/resource_logger_test.rb +144 -0
  108. data/test/vagrant/ssh_session_test.rb +46 -0
  109. data/test/vagrant/ssh_test.rb +42 -2
  110. data/test/vagrant/systems/linux_test.rb +174 -0
  111. data/test/vagrant/util/error_helper_test.rb +5 -0
  112. data/test/vagrant/util/output_helper_test.rb +5 -0
  113. data/test/vagrant/util/plain_logger_test.rb +17 -0
  114. data/test/vagrant/util/platform_test.rb +18 -0
  115. data/test/vagrant/util/{errors_test.rb → translator_test.rb} +25 -21
  116. data/test/vagrant/util_test.rb +12 -49
  117. data/test/vagrant/vm_test.rb +133 -11
  118. data/vagrant.gemspec +39 -15
  119. metadata +64 -40
  120. data/lib/vagrant/commands/down.rb +0 -16
  121. data/lib/vagrant/util/errors.rb +0 -36
  122. data/lib/vagrant/util/progress_meter.rb +0 -33
  123. data/test/vagrant/commands/down_test.rb +0 -17
  124. 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,5 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class ErrorHelperUtilTest < Test::Unit::TestCase
4
+ # TODO
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class OutputHelperUtilTest < Test::Unit::TestCase
4
+ # TODO
5
+ 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 ErrorsUtilTest < Test::Unit::TestCase
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
- Errors.reset!
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", "errors.yml")).once
14
- Errors.errors
15
- Errors.errors
16
- Errors.errors
17
- Errors.errors
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", "errors.yml")).twice
22
- Errors.errors
23
- Errors.reset!
24
- Errors.errors
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 error string" do
32
+ context "getting the string translated" do
29
33
  setup do
30
- @errors = {}
31
- @errors[:foo] = "foo bar baz"
32
- Errors.stubs(:errors).returns(@errors)
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(@errors[:foo], anything).once
37
- Errors.error_string(:foo)
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(@errors[:foo], data).once
43
- Errors.error_string(:foo, data)
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, Errors.error_string(:foo)
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 = Errors.error_string(:unknown)
57
+ result = @klass.t(:unknown)
54
58
  assert result =~ /Unknown/i
55
59
  end
56
60
  end
@@ -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 RegUtil
5
- extend Vagrant::Util
4
+ class UtilIncludeTest
5
+ include Vagrant::Util
6
6
  end
7
7
 
8
- context "erroring" do
9
- # TODO: Any way to stub Kernel.exit? Can't test nicely
10
- # otherwise
8
+ setup do
9
+ @klass = UtilIncludeTest
11
10
  end
12
11
 
13
- context "logger" do
14
- class OtherUtil
15
- extend Vagrant::Util
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
- @config = Vagrant::Config::Top.new
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 "be able to reset the logger" do
51
- Vagrant::Logger.expects(:new).twice
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
@@ -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 nil if the VM is not found" do
23
+ should "return return an uncreated VM object if the VM is not found" do
24
24
  VirtualBox::VM.expects(:find).returns(nil)
25
- assert_nil Vagrant::VM.find("foo")
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 otherwise" do
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
- @vm = Vagrant::VM.new(@mock_vm)
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
- out_path = mock("out_path")
67
- action_seq = sequence("actions")
68
- @vm.expects(:add_action).with(Vagrant::Actions::VM::Export).once.in_sequence(action_seq)
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(out_path)
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