vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -2,6 +2,7 @@ module Vagrant
2
2
  class VM < Actions::Runner
3
3
  include Vagrant::Util
4
4
 
5
+ attr_accessor :env
5
6
  attr_accessor :vm
6
7
  attr_accessor :from
7
8
 
@@ -1,8 +1,8 @@
1
1
  Vagrant::Config.run do |config|
2
2
  # All Vagrant configuration is done here. For a detailed explanation
3
- # and listing of configuration options, please check the documentation
3
+ # and listing of configuration options, please view the documentation
4
4
  # online.
5
5
 
6
6
  # Every Vagrant virtual environment requires a box to build off of.
7
- config.vm.box = "base"
7
+ config.vm.box = "<%= default_box %>"
8
8
  end
@@ -0,0 +1,16 @@
1
+ log_level <%= log_level.inspect %>
2
+ log_location STDOUT
3
+ node_name "<%= node_name %>"
4
+ ssl_verify_mode :verify_none
5
+ chef_server_url "<%= chef_server_url %>"
6
+
7
+ validation_client_name "<%= validation_client_name %>"
8
+ validation_key "<%= validation_key %>"
9
+ client_key "<%= client_key %>"
10
+
11
+ file_store_path "/srv/chef/file_store"
12
+ file_cache_path "/srv/chef/cache"
13
+
14
+ pid_file "/var/run/chef/chef-client.pid"
15
+
16
+ Mixlib::Log::Formatter.show_time = true
@@ -0,0 +1,4 @@
1
+ file_cache_path "<%= provisioning_path %>"
2
+ cookbook_path <%= cookbooks_path %>
3
+ role_path <%= roles_path %>
4
+ log_level <%= log_level.inspect %>
@@ -0,0 +1,157 @@
1
+ # Using YAMLs Block Literals to preserve new lines
2
+ # http://en.wikipedia.org/wiki/YAML#Newlines_preserved
3
+ # In short, | means keep new lines, trim whitespace left and right
4
+ # The |- does the above, but trims the new line at the end of all text
5
+
6
+ :box_already_exists: |-
7
+ This box appears to already exist! Please call `vagrant box remove <%= box_name %>`
8
+ and then try to add it again.
9
+ :box_add_already_exists: |-
10
+ A box with the name '<%= box_name %>' already exists, please use another name or use `vagrant box remove <%= box_name %>`
11
+ :box_download_unknown_type: |-
12
+ Unknown URI type for box download.
13
+ :box_remove_doesnt_exist: |-
14
+ The box you're attempting to remove does not exist!
15
+ :box_specified_doesnt_exist: |-
16
+ Specified box `<%= box_name %>` does not exist!
17
+
18
+ The box must be added through the `vagrant box add` command. Please view
19
+ the documentation associated with the command for more information.
20
+ :box_not_specified: |-
21
+ No base box was specified! A base box is required as a staring point
22
+ for every vagrant virtual machine. Please specify one in your Vagrantfile
23
+ using `config.vm.box`
24
+ :chef_base_invalid_provisioner: |-
25
+ Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefServer instead.
26
+ :chef_server_url_required: |-
27
+ Chef server provisioning requires that the `config.chef.chef_server_url` be set to the
28
+ URL of your chef server. Examples include "http://12.12.12.12:4000" and
29
+ "http://myserver.com:4000" (the port of course can be different, but 4000 is the default)
30
+ :chef_server_validation_key_required: |-
31
+ Chef server provisioning requires that the `config.chef.validation_key_path` configuration
32
+ be set to a path on your local machine of the validation key used to register the
33
+ VM with the chef server.
34
+ :chef_server_validation_key_doesnt_exist: |-
35
+ The validation key set for `config.chef.validation_key_path` does not exist! This
36
+ file needs to exist so it can be uploaded to the virtual machine. It is
37
+ currently set to "<%= Vagrant.config.chef.validation_key_path %>"
38
+ :command_box_invalid: |-
39
+ Please specify a valid action to take on the boxes, either
40
+ `add` or `remove`. Examples:
41
+
42
+ vagrant box add name uri
43
+ vagrant box remove name
44
+ vagrant box list
45
+ :command_deprecation_down: |-
46
+ `vagrant down` is now `vagrant destroy`. Please use that command instead. This
47
+ warning will be removed in future versions.
48
+ :dotfile_error: |-
49
+ The dotfile which Vagrant uses to store the UUID of the project's
50
+ virtual machine already exists and is not a file! The dotfile is
51
+ currently configured to be `<%= env.dotfile_path %>`
52
+
53
+ To change this value, please see `config.vagrant.dotfile_name`
54
+
55
+ Are you trying to use Vagrant from your home directory? This is the
56
+ leading cause of this error message. To resolve this, simply use a
57
+ different directory. Or, if you really want to run Vagrant from your
58
+ home directory, modify the `config.vagrant.dotfile_name` configuration
59
+ key.
60
+ :downloader_file_doesnt_exist: |-
61
+ The given box does not exist on the file system:
62
+
63
+ <%= source_url %>
64
+ :environment_not_created: |-
65
+ The task you're trying to run requires that the vagrant environment
66
+ already be created, but unfortunately this vagrant still appears to
67
+ have no box! You can setup the environment by setting up your
68
+ <%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up`
69
+ :package_include_file_doesnt_exist: |-
70
+ File specified to include: '<%= filename %>' does not exist!
71
+ :package_requires_export: |-
72
+ Package must be used in conjunction with export.
73
+ :provisioner_invalid_class: |-
74
+ Provisioners must be an instance of Vagrant::Provisioners::Base
75
+ :provisioner_unknown_type: |-
76
+ Unknown provisioner type: <%= provisioner %>
77
+ :rootfile_already_exists: |-
78
+ It looks like this directory is already setup for vagrant! (A <%= Vagrant::Environment::ROOTFILE_NAME %>
79
+ already exists.)
80
+ :rootfile_not_found: |-
81
+ A `<%= Vagrant::Environment::ROOTFILE_NAME %>` was not found! This file is required for vagrant to run
82
+ since it describes the expected environment that vagrant is supposed
83
+ to manage. Please create a `<%= Vagrant::Environment::ROOTFILE_NAME %>` and place it in your project
84
+ root.
85
+ :ssh_bad_permissions: |-
86
+ The private key to connect to this box via SSH has invalid permissions
87
+ set on it. The permissions of the private key should be set to 0600, otherwise SSH will
88
+ ignore the key. Vagrant tried to do this automatically for you but failed. Please set the
89
+ permissions on the following file to 0600 and then try running this command again:
90
+
91
+ <%= key_path %>
92
+ :ssh_unavailable_windows: |-
93
+ `vagrant ssh` isn't available on the Windows platform. The
94
+ vagrant.ppk file is available at
95
+
96
+ <%= key_path %>.ppk
97
+
98
+ for use with Putty. To do this create a new Putty session for
99
+ `vagrant@localhost` on port `<%= ssh_port %>`, in the Connection>SSH>Auth
100
+ configuration section navigate to the vagrant.ppk file,
101
+ select it, save the session for later use, and connect.
102
+
103
+ For a more detailed guide please consult:
104
+
105
+ http://vagrantup.com/docs/getting-started/windows.html
106
+
107
+ :virtualbox_import_failure: |-
108
+ The VM import failed! Try running `VBoxManage import` on the box file
109
+ manually for more verbose error output.
110
+ :virtualbox_invalid_version: |-
111
+ Vagrant has detected that you have VirtualBox version <%= version %> installed!
112
+ Vagrant requires that you use at least VirtualBox version 3.1. Please install
113
+ a more recent version of VirtualBox to continue.
114
+ :virtualbox_not_detected: |-
115
+ Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
116
+ If VirtualBox is installed, it may be an incorrect version. Vagrant currently
117
+ only supports VirtualBox 3.1.x. Please install the proper version to continue.
118
+ :vm_failed_to_boot: |-
119
+ Failed to connect to VM! Failed to boot?
120
+ :vm_base_not_found: |-
121
+ The specified base VM "<%= name %>" was not found.
122
+ :vm_not_running: |-
123
+ VM is not running! Nothing to shut down!
124
+ :vm_not_running_for_suspend: |-
125
+ The vagrant virtual environment you are trying to suspend must be running to be suspended.
126
+ :vm_not_suspended: |-
127
+ The vagrant virtual environment you are trying to resume is not in a suspended state.
128
+ :vm_port_collision: |-
129
+ Vagrant cannot forward the specified ports on this VM, since they
130
+ would collide with another VirtualBox virtual machine's forwarded
131
+ ports! The "<%= name %>" forwarded port (<%= hostport %>) is already in use on the host
132
+ machine.
133
+
134
+ To fix this, modify your current projects Vagrantfile to use another
135
+ port. Example, where '1234' would be replaced by a unique host port:
136
+
137
+ config.vm.forward_port("<%= name %>", <%= guestport %>, 1234)
138
+ :vm_power_off_to_move_hd: |-
139
+ The virtual machine must be powered off to move its disk.
140
+ :vm_power_off_to_package: |-
141
+ The vagrant virtual environment you are trying to package must be powered off.
142
+ :vm_mount_fail: |-
143
+ Failed to mount shared folders. vboxsf was not available.
144
+ :vm_ssh_auth_failed: |-
145
+ SSH authentication failed! While this could be due to a variety of reasons,
146
+ the two most common are: private key path is incorrect or you're using a box
147
+ which was built for Vagrant 0.1.x.
148
+
149
+ Vagrant 0.2.x dropped support for password-based authentication. If you're
150
+ tring to `vagrant up` a box which does not support Vagrant's private/public
151
+ keypair, then this error will be raised. To resolve this, read the guide
152
+ on converting base boxes from password-based to keypairs here:
153
+
154
+ http://vagrantup.com/docs/converting_password_to_key_ssh.html
155
+
156
+ If the box was built for 0.2.x and contains a custom public key, perhaps
157
+ the path to the private key is incorrect. Check your `config.ssh.private_key_path`.
@@ -0,0 +1,11 @@
1
+ Vagrant::Config.run do |config|
2
+ # This Vagrantfile is auto-generated by `vagrant package` to contain
3
+ # the MAC address of the box. Custom configuration should be placed in
4
+ # the actual `Vagrantfile` in this box.
5
+ config.vm.base_mac = "<%= base_mac %>"
6
+ end
7
+
8
+ # Load include vagrant file if it exists after the auto-generated
9
+ # so it can override any of the settings
10
+ include_vagrantfile = File.expand_path(File.join(File.dirname(__FILE__), "include", "Vagrantfile"))
11
+ load include_vagrantfile if File.exist?(include_vagrantfile)
@@ -0,0 +1,7 @@
1
+ Host <%= host_key %>
2
+ HostName localhost
3
+ User <%= ssh_user %>
4
+ Port <%= ssh_port %>
5
+ UserKnownHostsFile /dev/null
6
+ StrictHostKeyChecking no
7
+ IdentityFile <%= private_key_path %>
@@ -3,8 +3,6 @@ begin
3
3
  rescue LoadError
4
4
  # Fallback on doing the resolve at runtime.
5
5
  require "rubygems"
6
- require "bundler"
7
- Bundler.setup
8
6
  end
9
7
 
10
8
  # ruby-debug, not necessary, but useful if we have it
@@ -18,9 +16,11 @@ require 'contest'
18
16
  require 'mocha'
19
17
 
20
18
  class Test::Unit::TestCase
21
- # Clears the previous config and sets up the new config
22
- def mock_config
23
- Vagrant::Config.reset!
19
+ # Mocks an environment, setting it up with the given config.
20
+ def mock_environment
21
+ environment = Vagrant::Environment.new
22
+
23
+ Vagrant::Config.reset!(environment)
24
24
 
25
25
  Vagrant::Config.run do |config|
26
26
  config.vagrant.dotfile_name = ".vagrant"
@@ -49,8 +49,10 @@ class Test::Unit::TestCase
49
49
  config.chef.chef_server_url = "http://localhost:4000"
50
50
  config.chef.validation_key_path = "validation.pem"
51
51
  config.chef.client_key_path = "/zoo/foo/bar.pem"
52
+ config.chef.node_name = "baz"
52
53
  config.chef.cookbooks_path = "cookbooks"
53
54
  config.chef.provisioning_path = "/tmp/vagrant-chef"
55
+ config.chef.log_level = :info
54
56
  config.chef.json = {
55
57
  :recipes => ["vagrant_main"]
56
58
  }
@@ -64,13 +66,10 @@ class Test::Unit::TestCase
64
66
  end
65
67
  end
66
68
 
67
- if block_given?
68
- Vagrant::Config.run do |config|
69
- yield config
70
- end
71
- end
69
+ config = Vagrant::Config.execute!
72
70
 
73
- Vagrant::Config.execute!
71
+ environment.instance_variable_set(:@config, config)
72
+ environment
74
73
  end
75
74
 
76
75
  # Sets up the mocks and instantiates an action for testing
@@ -85,11 +84,12 @@ class Test::Unit::TestCase
85
84
  mock_vm.stubs(:invoke_callback)
86
85
  mock_vm.stubs(:invoke_around_callback).yields
87
86
  mock_vm.stubs(:actions).returns([action])
87
+ mock_vm.stubs(:env).returns(mock_environment)
88
88
 
89
89
  [mock_vm, vm, action]
90
90
  end
91
91
 
92
- def stub_default_action_dependecies(mock, klass=MockAction)
92
+ def stub_default_action_dependecies(mock)
93
93
  mock.stubs(:precedes).returns([])
94
94
  mock.stubs(:follows).returns([])
95
95
  end
@@ -103,6 +103,3 @@ class Test::Unit::TestCase
103
103
  end
104
104
  end
105
105
 
106
- class MockAction; end
107
- class MockActionOther; end
108
-
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class AddBoxActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::Box::Add)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "prepare" do
@@ -27,7 +26,7 @@ class AddBoxActionTest < Test::Unit::TestCase
27
26
 
28
27
  should "result in an action exception if the box already exists" do
29
28
  File.expects(:exists?).once.returns(true)
30
- @runner.expects(:name).twice.returns('foo')
29
+ @runner.expects(:name).once.returns('foo')
31
30
  @runner.expects(:add_action).never
32
31
  assert_raise Vagrant::Actions::ActionException do
33
32
  @action.prepare
@@ -6,7 +6,6 @@ class DestroyBoxActionTest < Test::Unit::TestCase
6
6
  @dir = "foo"
7
7
  @runner, @vm, @action = mock_action(Vagrant::Actions::Box::Destroy)
8
8
  @runner.stubs(:directory).returns(@dir)
9
- mock_config
10
9
  end
11
10
 
12
11
  context "executing" do
@@ -6,24 +6,20 @@ class DownloadBoxActionTest < Test::Unit::TestCase
6
6
  @runner, @vm, @action = mock_action(Vagrant::Actions::Box::Download)
7
7
  @runner.stubs(:uri).returns(@uri)
8
8
  @runner.stubs(:temp_path=)
9
- mock_config
10
9
 
11
- Vagrant::Env.stubs(:tmp_path).returns("foo")
10
+ @runner.env.stubs(:tmp_path).returns("foo")
12
11
  end
13
12
 
14
13
  context "preparing" do
15
14
  setup do
16
- @uri = mock("uri")
17
- @uri.stubs(:is_a?).returns(false)
18
- URI.stubs(:parse).returns(@uri)
19
-
20
15
  @downloader = mock("downloader")
21
16
  Vagrant::Downloaders::File.any_instance.stubs(:prepare)
22
17
  Vagrant::Downloaders::HTTP.any_instance.stubs(:prepare)
23
18
  end
24
19
 
25
- should "raise an exception if no URI type is matched" do
26
- @uri.stubs(:is_a?).returns(false)
20
+ should "raise an exception if no URI type is matched" do\
21
+ Vagrant::Downloaders::File.expects(:match?).returns(false)
22
+ Vagrant::Downloaders::HTTP.expects(:match?).returns(false)
27
23
  assert_raises(Vagrant::Actions::ActionException) {
28
24
  @action.prepare
29
25
  }
@@ -32,21 +28,31 @@ class DownloadBoxActionTest < Test::Unit::TestCase
32
28
  should "call #prepare on the downloader" do
33
29
  @downloader.expects(:prepare).with(@runner.uri).once
34
30
  Vagrant::Downloaders::File.expects(:new).returns(@downloader)
35
- @uri.stubs(:is_a?).with(URI::Generic).returns(true)
31
+ expect_file
36
32
  @action.prepare
37
33
  end
38
34
 
39
- should "set the downloader to file if URI is generic" do
40
- @uri.stubs(:is_a?).with(URI::Generic).returns(true)
35
+ should "set the downloader to file if the uri provided is a file" do
36
+ expect_file
41
37
  @action.prepare
42
38
  assert @action.downloader.is_a?(Vagrant::Downloaders::File)
43
39
  end
44
40
 
45
- should "set the downloader to HTTP if URI is HTTP" do
46
- @uri.stubs(:is_a?).with(URI::HTTP).returns(true)
41
+ should "set the downloader to HTTP if the uri provided is a valid url" do
42
+ expect_http
47
43
  @action.prepare
48
44
  assert @action.downloader.is_a?(Vagrant::Downloaders::HTTP)
49
45
  end
46
+
47
+ def expect_file
48
+ Vagrant::Downloaders::File.expects(:match?).returns(true)
49
+ Vagrant::Downloaders::HTTP.expects(:match?).returns(false)
50
+ end
51
+
52
+ def expect_http
53
+ Vagrant::Downloaders::File.expects(:match?).returns(false)
54
+ Vagrant::Downloaders::HTTP.expects(:match?).returns(true)
55
+ end
50
56
  end
51
57
 
52
58
  context "executing" do
@@ -81,13 +87,16 @@ class DownloadBoxActionTest < Test::Unit::TestCase
81
87
 
82
88
  context "tempfile" do
83
89
  should "create a tempfile in the vagrant tmp directory" do
84
- Tempfile.expects(:open).with(Vagrant::Actions::Box::Download::BASENAME, Vagrant::Env.tmp_path).once
90
+ File.expects(:open).with { |name, bitmask|
91
+ name =~ /#{Vagrant::Actions::Box::Download::BASENAME}/ && name =~ /#{@runner.env.tmp_path}/
92
+ }.once
85
93
  @action.with_tempfile
86
94
  end
87
95
 
96
+
88
97
  should "yield the tempfile object" do
89
98
  @tempfile = mock("tempfile")
90
- Tempfile.expects(:open).yields(@tempfile)
99
+ File.expects(:open).yields(@tempfile)
91
100
 
92
101
  @action.with_tempfile do |otherfile|
93
102
  assert @tempfile.equal?(otherfile)
@@ -95,6 +104,22 @@ class DownloadBoxActionTest < Test::Unit::TestCase
95
104
  end
96
105
  end
97
106
 
107
+ context "file options" do
108
+ should "include add binary bit to options on windows platform" do
109
+ # This constant is not defined on non-windows platforms, so define it here
110
+ File::BINARY = 4096 unless defined?(File::BINARY)
111
+
112
+ Mario::Platform.expects(:windows?).returns(true)
113
+ assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
114
+ end
115
+
116
+ should "not include binary bit on other platforms" do
117
+ Mario::Platform.expects(:windows?).returns(false)
118
+ assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY
119
+ end
120
+ end
121
+
122
+
98
123
  context "cleaning up" do
99
124
  setup do
100
125
  @temp_path = "foo"
@@ -5,9 +5,8 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::Box::Unpackage)
6
6
  @runner.stubs(:name).returns("foo")
7
7
  @runner.stubs(:temp_path).returns("bar")
8
- mock_config
9
8
 
10
- Vagrant::Env.stubs(:boxes_path).returns("bar")
9
+ @runner.env.stubs(:boxes_path).returns("bar")
11
10
  end
12
11
 
13
12
  context "executing" do
@@ -68,7 +67,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
68
67
 
69
68
  should "error and exit if the directory exists" do
70
69
  File.expects(:directory?).returns(true)
71
- @action.expects(:error_and_exit).once
70
+ @action.expects(:error_and_exit).with(:box_already_exists, :box_name => @runner.name).once
72
71
  @action.setup_box_dir
73
72
  end
74
73
 
@@ -1,6 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class CollectionTest < Test::Unit::TestCase
4
+ class MockAction; end
5
+ class MockActionOther; end
6
+
4
7
  context "checking uniqueness" do
5
8
  setup do
6
9
  @actions = Vagrant::Actions::Collection.new([1])
@@ -10,14 +13,14 @@ class CollectionTest < Test::Unit::TestCase
10
13
  @actions << 1
11
14
  assert @actions.duplicates?
12
15
  end
13
-
16
+
14
17
  should "return false it all the classes are unique" do
15
18
  @actions << 1.0 << "foo"
16
19
  assert !@actions.duplicates?
17
20
  end
18
21
 
19
22
  should "raise an exception when there are duplicates" do
20
- @actions << 1
23
+ @actions << 1
21
24
  assert_raise Vagrant::Actions::DuplicateActionException do
22
25
  @actions.duplicates!
23
26
  end
@@ -42,7 +45,7 @@ class CollectionTest < Test::Unit::TestCase
42
45
  stub_default_action_dependecies(@mock_action)
43
46
  stub_default_action_dependecies(@mock_action2)
44
47
  end
45
-
48
+
46
49
  context "that come before an action" do
47
50
  setup do
48
51
  @mock_action.stubs(:follows).returns([MockActionOther])
@@ -52,7 +55,7 @@ class CollectionTest < Test::Unit::TestCase
52
55
  collection.new([@mock_action]).dependencies!
53
56
  end
54
57
  end
55
-
58
+
56
59
  should "not raise an exception if they are met" do
57
60
  assert_nothing_raised do
58
61
  collection.new([@mock_action2, @mock_action]).dependencies!
@@ -97,7 +100,7 @@ class CollectionTest < Test::Unit::TestCase
97
100
  end
98
101
  end
99
102
  end
100
-
103
+
101
104
  context "klasses" do
102
105
  should "return a list of the collection element's classes" do
103
106
  @action = mock('action')