vagrant 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.md +48 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +2 -2
  6. data/Rakefile +22 -0
  7. data/bin/.gitignore +0 -0
  8. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  9. data/lib/vagrant/util/template_renderer.rb +2 -2
  10. data/lib/vagrant/version.rb +1 -1
  11. data/templates/Vagrantfile.erb +1 -1
  12. data/templates/nfs/exports.erb +4 -2
  13. data/test/test_helper.rb +128 -0
  14. data/test/vagrant/action/box/destroy_test.rb +30 -0
  15. data/test/vagrant/action/box/download_test.rb +141 -0
  16. data/test/vagrant/action/box/package_test.rb +25 -0
  17. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  18. data/test/vagrant/action/box/verify_test.rb +39 -0
  19. data/test/vagrant/action/builder_test.rb +218 -0
  20. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  21. data/test/vagrant/action/env/set_test.rb +24 -0
  22. data/test/vagrant/action/environment_test.rb +45 -0
  23. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  24. data/test/vagrant/action/general/package_test.rb +254 -0
  25. data/test/vagrant/action/vm/boot_test.rb +83 -0
  26. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  27. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  28. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  29. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  30. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  31. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  32. data/test/vagrant/action/vm/customize_test.rb +29 -0
  33. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  34. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  35. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  36. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  37. data/test/vagrant/action/vm/export_test.rb +135 -0
  38. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  39. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  40. data/test/vagrant/action/vm/halt_test.rb +69 -0
  41. data/test/vagrant/action/vm/import_test.rb +50 -0
  42. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  43. data/test/vagrant/action/vm/network_test.rb +246 -0
  44. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  45. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  46. data/test/vagrant/action/vm/package_test.rb +25 -0
  47. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  48. data/test/vagrant/action/vm/persist_test.rb +50 -0
  49. data/test/vagrant/action/vm/provision_test.rb +134 -0
  50. data/test/vagrant/action/vm/resume_test.rb +35 -0
  51. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  52. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  53. data/test/vagrant/action_test.rb +111 -0
  54. data/test/vagrant/active_list_test.rb +173 -0
  55. data/test/vagrant/box_test.rb +166 -0
  56. data/test/vagrant/command_test.rb +53 -0
  57. data/test/vagrant/commands/base_test.rb +139 -0
  58. data/test/vagrant/commands/box/add_test.rb +34 -0
  59. data/test/vagrant/commands/box/list_test.rb +32 -0
  60. data/test/vagrant/commands/box/remove_test.rb +41 -0
  61. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  62. data/test/vagrant/commands/destroy_test.rb +44 -0
  63. data/test/vagrant/commands/halt_test.rb +50 -0
  64. data/test/vagrant/commands/init_test.rb +71 -0
  65. data/test/vagrant/commands/package_test.rb +97 -0
  66. data/test/vagrant/commands/provision_test.rb +60 -0
  67. data/test/vagrant/commands/reload_test.rb +47 -0
  68. data/test/vagrant/commands/resume_test.rb +44 -0
  69. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  70. data/test/vagrant/commands/ssh_test.rb +129 -0
  71. data/test/vagrant/commands/status_test.rb +40 -0
  72. data/test/vagrant/commands/suspend_test.rb +44 -0
  73. data/test/vagrant/commands/up_test.rb +49 -0
  74. data/test/vagrant/config_test.rb +307 -0
  75. data/test/vagrant/downloaders/base_test.rb +28 -0
  76. data/test/vagrant/downloaders/file_test.rb +33 -0
  77. data/test/vagrant/downloaders/http_test.rb +70 -0
  78. data/test/vagrant/environment_test.rb +770 -0
  79. data/test/vagrant/hosts/base_test.rb +46 -0
  80. data/test/vagrant/hosts/bsd_test.rb +56 -0
  81. data/test/vagrant/hosts/linux_test.rb +56 -0
  82. data/test/vagrant/provisioners/base_test.rb +36 -0
  83. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  84. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  85. data/test/vagrant/provisioners/chef_test.rb +178 -0
  86. data/test/vagrant/ssh_session_test.rb +46 -0
  87. data/test/vagrant/ssh_test.rb +317 -0
  88. data/test/vagrant/systems/linux_test.rb +179 -0
  89. data/test/vagrant/util/busy_test.rb +106 -0
  90. data/test/vagrant/util/plain_logger_test.rb +17 -0
  91. data/test/vagrant/util/platform_test.rb +18 -0
  92. data/test/vagrant/util/resource_logger_test.rb +145 -0
  93. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  94. data/test/vagrant/util/template_renderer_test.rb +145 -0
  95. data/test/vagrant/util/translator_test.rb +61 -0
  96. data/test/vagrant/util_test.rb +27 -0
  97. data/test/vagrant/vm_test.rb +228 -0
  98. data/vagrant.gemspec +34 -0
  99. metadata +158 -43
@@ -0,0 +1,10 @@
1
+ pkg/*
2
+ Vagrantfile
3
+ .vagrant
4
+ .bundle
5
+ cookbooks/*
6
+ _site/*
7
+ !templates/*
8
+ *.org
9
+ .yardoc/
10
+ doc/
@@ -0,0 +1,48 @@
1
+ ## 0.5.3 (August 23, 2010)
2
+
3
+ - Add erubis as a dependency since its rendering of `erb` is sane.
4
+ - Fixed poorly formatted Vagrantfile after `vagrant init`. [GH-142]
5
+ - Fixed NFS not working properly with multiple NFS folders.
6
+ - Fixed chef solo provision to work on Windows. It was expanding a linux
7
+ path which prepended a drive letter onto it.
8
+
9
+ ## 0.5.2 (August 3, 2010)
10
+
11
+ - `vagrant up` can be used as a way to resume the VM as well (same as
12
+ `vagrant resume`). [GH-134]
13
+ - Sudo uses "-E" flag to preserve environment for chef provisioners.
14
+ This fixes issues with CentOS. [GH-133]
15
+ - Added "IdentitiesOnly yes" to options when `vagrant ssh` is run to
16
+ avoid "Too Many Authentication Failures" error. [GH-131]
17
+ - Fix regression with `package` not working. [GH-132]
18
+ - Added ability to specify box url in `init`, which populates the
19
+ Vagrantfile with the proper `config.vm.box_url`.
20
+
21
+ ## 0.5.1 (July 31, 2010)
22
+
23
+ - Allow specifying cookbook paths which exist only on the VM in `config.chef.cookbooks_path`.
24
+ This is used for specifying cookbook paths when `config.chef.recipe_url` is used. [GH-130]
25
+ See updated chef solo documentation for more information on this.
26
+ - No longer show "Disabling host only networks..." if no host only networks
27
+ are destroyed. Quiets `destroy`, `halt`, etc output a bit.
28
+ - Updated getting started guide to be more up to date and generic. [GH-125]
29
+ - Fixed error with doing a `vagrant up` when no Vagrantfile existed. [GH-128]
30
+ - Fixed NFS erroring when NFS wasn't even enabled if `/etc/exports` doesn't
31
+ exist. [GH-126]
32
+ - Fixed `vagrant resume` to properly resume a suspended VM. [GH-122]
33
+ - Fixed `halt`, `destroy`, `reload` to where they failed if the VM was
34
+ in a saved state. [GH-123]
35
+ - Added `config.chef.recipe_url` which allows you to specify a URL to
36
+ a gzipped tar file for chef solo to download cookbooks. See the
37
+ [chef-solo docs](http://wiki.opscode.com/display/chef/Chef+Solo#ChefSolo-RunningfromaURL) for more information.
38
+ [GH-121]
39
+ - Added `vagrant box repackage` which repackages boxes which have
40
+ been added. This is useful in case you want to redistribute a base
41
+ box you have but may have lost the actual "box" file. [GH-120]
42
+
43
+ ## Previous
44
+
45
+ The changelog began with version 0.5.1 so any changes prior to that
46
+ can be seen by checking the tagged releases and reading git commit
47
+ messages.
48
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "vagrant", :path => '.'
4
+
5
+ # Use the version of virtualbox off of github
6
+ gem "virtualbox", :git => "git://github.com/mitchellh/virtualbox.git"
7
+
8
+ # Gems required for testing only. To install run
9
+ # gem bundle test
10
+ group :test do
11
+ gem "rake"
12
+ gem "contest", ">= 0.1.2"
13
+ gem "mocha"
14
+ gem "yard"
15
+ gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9'
16
+ end
@@ -0,0 +1,49 @@
1
+ GIT
2
+ remote: git://github.com/mitchellh/virtualbox.git
3
+ revision: 69db76b
4
+ specs:
5
+ virtualbox (0.7.5)
6
+ ffi (>= 0.6.3)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ vagrant (0.5.3)
12
+ archive-tar-minitar (= 0.5.2)
13
+ erubis (>= 2.6.6)
14
+ json (>= 1.4.3)
15
+ mario (~> 0.0.6)
16
+ net-scp (>= 1.0.2)
17
+ net-ssh (>= 2.0.19)
18
+ virtualbox (~> 0.7.3)
19
+
20
+ GEM
21
+ remote: http://rubygems.org/
22
+ specs:
23
+ abstract (1.0.0)
24
+ archive-tar-minitar (0.5.2)
25
+ contest (0.1.2)
26
+ erubis (2.6.6)
27
+ abstract (>= 1.0.0)
28
+ ffi (0.6.3)
29
+ rake (>= 0.8.7)
30
+ json (1.4.6)
31
+ mario (0.0.6)
32
+ mocha (0.9.8)
33
+ rake
34
+ net-scp (1.0.3)
35
+ net-ssh (>= 1.99.1)
36
+ net-ssh (2.0.23)
37
+ rake (0.8.7)
38
+ yard (0.5.8)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ contest (>= 0.1.2)
45
+ mocha
46
+ rake
47
+ vagrant!
48
+ virtualbox!
49
+ yard
data/README.md CHANGED
@@ -48,9 +48,9 @@ and you're welcome to give it a shot. The following is an example showing how to
48
48
  ## Contributing to Vagrant
49
49
 
50
50
  To hack on vagrant, you'll need [bundler](http://github.com/carlhuda/bundler) which can
51
- be installed with a simple `gem install bundler`. Afterwords, do the following:
51
+ be installed with a simple `gem install bundler --pre`. Afterwords, do the following:
52
52
 
53
53
  bundle install
54
- bundle exec rake
54
+ rake
55
55
 
56
56
  This will run the test suite, which should come back all green! Then you're good to go!
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rake/testtask'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "test"
10
+ t.pattern = 'test/**/*_test.rb'
11
+ end
12
+
13
+ begin
14
+ require 'yard'
15
+ YARD::Rake::YardocTask.new do |t|
16
+ t.options = ['--main', 'README.md', '--markup', 'markdown']
17
+ t.options += ['--title', 'Vagrant Developer Documentation']
18
+ end
19
+ rescue LoadError
20
+ puts "Yard not available. Install it with: gem install yard"
21
+ puts "if you wish to be able to generate developer documentation."
22
+ end
File without changes
@@ -64,7 +64,7 @@ module Vagrant
64
64
  end
65
65
 
66
66
  def folder_path(*args)
67
- File.expand_path(args.join("-"), env.config.chef.provisioning_path)
67
+ File.join(env.config.chef.provisioning_path, args.join("-"))
68
68
  end
69
69
 
70
70
  def folders_path(folders, folder)
@@ -1,5 +1,5 @@
1
1
  require 'ostruct'
2
- require 'erb'
2
+ require 'erubis'
3
3
 
4
4
  module Vagrant
5
5
  module Util
@@ -68,7 +68,7 @@ module Vagrant
68
68
  #
69
69
  # @return [String]
70
70
  def render_string
71
- ERB.new(template, nil, "%<>-").result(binding)
71
+ Erubis::Eruby.new(template, :trim => true).result(binding)
72
72
  end
73
73
 
74
74
  # Returns the full path to the template, taking into accoun the gem directory
@@ -2,5 +2,5 @@ module Vagrant
2
2
  # This will always be up to date with the current version of Vagrant,
3
3
  # since it is used to generate the gemspec and is also the source of
4
4
  # the version for `vagrant -v`
5
- VERSION = "0.5.2"
5
+ VERSION = "0.5.3"
6
6
  end
@@ -5,8 +5,8 @@ Vagrant::Config.run do |config|
5
5
 
6
6
  # Every Vagrant virtual environment requires a box to build off of.
7
7
  config.vm.box = "<%= default_box %>"
8
-
9
8
  <% if !default_box_url.nil? -%>
9
+
10
10
  # The url from where the 'config.vm.box' box will be fetched if it
11
11
  # doesn't already exist on the user's system
12
12
  config.vm.box_url = "<%= default_box_url %>"
@@ -1,3 +1,5 @@
1
1
  # VAGRANT-BEGIN: <%= uuid %>
2
- <% folders.each do |name, opts| %><%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] %> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end %><% end %>
3
- # VAGRANT-END: <%= uuid %>
2
+ <% folders.each do |name, opts| %>
3
+ <%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
4
+ <% end %>
5
+ # VAGRANT-END: <%= uuid %>
@@ -0,0 +1,128 @@
1
+ # ruby-debug, not necessary, but useful if we have it
2
+ begin
3
+ require 'ruby-debug'
4
+ rescue LoadError; end
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'vagrant')
7
+ require 'contest'
8
+ require 'mocha'
9
+
10
+ # Add this folder to the load path for "test_helper"
11
+ $:.unshift(File.dirname(__FILE__))
12
+
13
+ class Test::Unit::TestCase
14
+ # Mocks an environment, setting it up with the given config.
15
+ def mock_environment
16
+ environment = Vagrant::Environment.new
17
+
18
+ Vagrant::Config.reset!(environment)
19
+
20
+ Vagrant::Config.run do |config|
21
+ config.vagrant.home = '~/.home'
22
+ config.vagrant.dotfile_name = ".vagrant"
23
+ config.vagrant.log_output = nil
24
+ config.vagrant.host = :detect
25
+
26
+ config.ssh.username = "foo"
27
+ config.ssh.host = "baz"
28
+ config.ssh.port = 22
29
+ config.ssh.forwarded_port_key = "ssh"
30
+ config.ssh.max_tries = 10
31
+ config.ssh.timeout = 10
32
+ config.ssh.private_key_path = '~/foo'
33
+
34
+ config.vm.box = "foo"
35
+ config.vm.box_url = nil
36
+ config.vm.box_ovf = "box.ovf"
37
+ config.vm.base_mac = "42"
38
+ config.vm.disk_image_format = 'VMDK'
39
+ config.vm.forward_port("ssh", 22, 2222)
40
+ config.vm.shared_folder_uid = nil
41
+ config.vm.shared_folder_gid = nil
42
+ config.vm.system = :linux
43
+ config.vm.share_folder("v-root", "/vagrant", ".")
44
+
45
+ config.package.name = 'package'
46
+
47
+ # Unison
48
+ config.unison.folder_suffix = ".sync"
49
+ config.unison.log_file = "foo-%s"
50
+
51
+ # Chef
52
+ config.chef.chef_server_url = "http://localhost:4000"
53
+ config.chef.validation_key_path = "validation.pem"
54
+ config.chef.client_key_path = "/zoo/foo/bar.pem"
55
+ config.chef.node_name = "baz"
56
+ config.chef.recipe_url = nil
57
+ config.chef.cookbooks_path = "cookbooks"
58
+ config.chef.provisioning_path = "/tmp/vagrant-chef"
59
+ config.chef.log_level = :info
60
+ config.chef.json = {
61
+ :recipes => ["vagrant_main"]
62
+ }
63
+ end
64
+
65
+ if block_given?
66
+ Vagrant::Config.run do |config|
67
+ yield config
68
+ end
69
+ end
70
+
71
+ config = Vagrant::Config.execute!
72
+
73
+ environment.instance_variable_set(:@config, config)
74
+
75
+ # Setup the logger. We create it then reset it so that subsequent
76
+ # calls will recreate it for us.
77
+ environment.load_logger!
78
+ environment.logger.class.reset_singleton_logger!
79
+ environment.logger.stubs(:flush_progress)
80
+ environment.logger.stubs(:cl_reset).returns("")
81
+
82
+ environment
83
+ end
84
+
85
+ # Sets up the mocks for a VM
86
+ def mock_vm(env=nil)
87
+ env ||= mock_environment
88
+ vm = Vagrant::VM.new
89
+ vm.stubs(:env).returns(env)
90
+ vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
91
+ vm
92
+ end
93
+
94
+ def mock_action_data
95
+ app = lambda { |env| }
96
+ env = Vagrant::Action::Environment.new(mock_environment)
97
+ env["vagrant.test"] = true
98
+ [app, env]
99
+ end
100
+
101
+ # Returns a resource logger which is safe for tests
102
+ def quiet_logger(resource, env=nil)
103
+ logger = Vagrant::ResourceLogger.new(resource, env)
104
+ logger.stubs(:flush_progress)
105
+ logger.stubs(:cl_reset).returns("")
106
+ logger
107
+ end
108
+
109
+ # Returns a linux system
110
+ def linux_system(vm)
111
+ Vagrant::Systems::Linux.new(vm)
112
+ end
113
+
114
+ def stub_default_action_dependecies(mock)
115
+ mock.stubs(:precedes).returns([])
116
+ mock.stubs(:follows).returns([])
117
+ end
118
+
119
+ # Sets up the mocks and stubs for a downloader
120
+ def mock_downloader(downloader_klass)
121
+ tempfile = mock("tempfile")
122
+ tempfile.stubs(:write)
123
+
124
+ _, env = mock_action_data
125
+ [downloader_klass.new(env), tempfile]
126
+ end
127
+ end
128
+
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+
3
+ class DestroyBoxActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Box::Destroy
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+ @env["box"] = Vagrant::Box.new(mock_environment, "foo")
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ context "calling" do
19
+ setup do
20
+ @env.logger.stubs(:info)
21
+ end
22
+
23
+ should "delete the box directory" do
24
+ seq = sequence("seq")
25
+ FileUtils.expects(:rm_rf).with(@env["box"].directory).in_sequence(seq)
26
+ @app.expects(:call).with(@env).once.in_sequence(seq)
27
+ @instance.call(@env)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,141 @@
1
+ require "test_helper"
2
+
3
+ class DownloadBoxActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Box::Download
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+ @env["box"] = Vagrant::Box.new(mock_environment, "foo")
11
+ @env["box"].uri = "http://google.com"
12
+
13
+ @internal_vm = mock("internal")
14
+ @vm.stubs(:vm).returns(@internal_vm)
15
+ end
16
+
17
+ context "initializing" do
18
+ should "initialize download classes" do
19
+ @klass.new(@app, @env)
20
+ assert_equal [Vagrant::Downloaders::HTTP, Vagrant::Downloaders::File], @env["download.classes"]
21
+ end
22
+ end
23
+
24
+ context "with an instance" do
25
+ setup do
26
+ @instance = @klass.new(@app, @env)
27
+ end
28
+
29
+ context "calling" do
30
+ should "call the proper methods in sequence" do
31
+ seq = sequence("seq")
32
+ @instance.expects(:instantiate_downloader).in_sequence(seq).returns(true)
33
+ @instance.expects(:download).in_sequence(seq)
34
+ @app.expects(:call).with(@env).in_sequence(seq)
35
+ @instance.expects(:cleanup).in_sequence(seq)
36
+ @instance.call(@env)
37
+ end
38
+
39
+ should "halt the chain if downloader instantiation fails" do
40
+ seq = sequence("seq")
41
+ @env.error!(:foo)
42
+ @instance.expects(:instantiate_downloader).in_sequence(seq).returns(false)
43
+ @instance.expects(:download).never
44
+ @app.expects(:call).with(@env).never
45
+ @instance.expects(:cleanup).never
46
+ @instance.call(@env)
47
+ end
48
+ end
49
+
50
+ context "instantiating downloader" do
51
+ should "instantiate the proper class" do
52
+ instance = mock("instance")
53
+ Vagrant::Downloaders::HTTP.expects(:new).with(@env).returns(instance)
54
+ instance.expects(:prepare).with(@env["box"].uri).once
55
+ assert @instance.instantiate_downloader
56
+ end
57
+
58
+ should "error environment if URI is invalid for any downloaders" do
59
+ @env["box"].uri = "foobar"
60
+ assert !@instance.instantiate_downloader
61
+ assert @env.error?
62
+ assert_equal :box_download_unknown_type, @env.error.first
63
+ end
64
+ end
65
+
66
+ context "downloading" do
67
+ setup do
68
+ @path = "foo"
69
+
70
+ @tempfile = mock("tempfile")
71
+ @tempfile.stubs(:path).returns(@path)
72
+
73
+ @instance.stubs(:with_tempfile).yields(@tempfile)
74
+ @instance.stubs(:download_to)
75
+ end
76
+
77
+ should "make a tempfile and copy the URI contents to it" do
78
+ @instance.expects(:with_tempfile).yields(@tempfile)
79
+ @instance.expects(:download_to).with(@tempfile)
80
+ @instance.download
81
+ end
82
+
83
+ should "save the tempfile path" do
84
+ @instance.download
85
+ assert @env.has_key?("download.temp_path")
86
+ assert_equal @tempfile.path, @env["download.temp_path"]
87
+ assert_equal @tempfile.path, @instance.temp_path
88
+ end
89
+ end
90
+
91
+ context "tempfile" do
92
+ should "create a tempfile in the vagrant tmp directory" do
93
+ File.expects(:open).with { |name, bitmask|
94
+ name =~ /#{Vagrant::Action::Box::Download::BASENAME}/ && name =~ /#{@env.env.tmp_path}/
95
+ }.once
96
+ @instance.with_tempfile
97
+ end
98
+
99
+ should "yield the tempfile object" do
100
+ @tempfile = mock("tempfile")
101
+ File.expects(:open).yields(@tempfile)
102
+
103
+ @instance.with_tempfile do |otherfile|
104
+ assert @tempfile.equal?(otherfile)
105
+ end
106
+ end
107
+ end
108
+
109
+ context "cleaning up" do
110
+ setup do
111
+ @temp_path = "foo"
112
+ @instance.stubs(:temp_path).returns(@temp_path)
113
+ File.stubs(:exist?).returns(true)
114
+ end
115
+
116
+ should "delete the temporary file if it exists" do
117
+ File.expects(:unlink).with(@temp_path).once
118
+ @instance.cleanup
119
+ end
120
+
121
+ should "not delete anything if it doesn't exist" do
122
+ File.stubs(:exist?).returns(false)
123
+ File.expects(:unlink).never
124
+ @instance.cleanup
125
+ end
126
+ end
127
+
128
+ context "downloading to" do
129
+ setup do
130
+ @downloader = mock("downloader")
131
+ @instance.instance_variable_set(:@downloader, @downloader)
132
+ end
133
+
134
+ should "call download! on the download with the URI and tempfile" do
135
+ tempfile = "foo"
136
+ @downloader.expects(:download!).with(@env["box"].uri, tempfile)
137
+ @instance.download_to(tempfile)
138
+ end
139
+ end
140
+ end
141
+ end