ClearSharedFolders middleware

This commit is contained in:
Mitchell Hashimoto 2010-07-08 23:09:42 -07:00
parent c82308f8da
commit 0ebdf88144
6 changed files with 96 additions and 119 deletions

View File

@ -18,6 +18,7 @@ module Vagrant
use VM::Customize
use VM::ForwardPorts
use VM::Provision
use VM::ClearSharedFolders
use VM::ShareFolders
use VM::Network
use VM::Boot

View File

@ -0,0 +1,32 @@
module Vagrant
class Action
module VM
class ClearSharedFolders
def initialize(app, env)
@app = app
@env = env
end
def call(env)
@env = env
clear_shared_folders
@app.call(env)
end
def clear_shared_folders
if @env["vm"].vm.shared_folders.length > 0
@env.logger.info "Clearing previously set shared folders..."
folders = @env["vm"].vm.shared_folders.dup
folders.each do |shared_folder|
shared_folder.destroy
end
@env["vm"].reload!
end
end
end
end
end
end

View File

@ -12,7 +12,6 @@ module Vagrant
def call(env)
@env = env
clear_shared_folders
create_metadata
@app.call(env)
@ -58,19 +57,6 @@ module Vagrant
end
end
def clear_shared_folders
if @env["vm"].vm.shared_folders.length > 0
@env.logger.info "Clearing previously set shared folders..."
folders = @env["vm"].vm.shared_folders.dup
folders.each do |shared_folder|
shared_folder.destroy
end
@env["vm"].reload!
end
end
def create_metadata
@env.logger.info "Creating shared folders metadata..."

View File

@ -0,0 +1,49 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class ClearSharedFoldersVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::ClearSharedFolders
@app, @env = mock_action_data
@vm = mock("vm")
@env["vm"] = @vm
@internal_vm = mock("internal")
@vm.stubs(:vm).returns(@internal_vm)
@instance = @klass.new(@app, @env)
end
context "calling" do
should "call the proper methods in sequence" do
seq = sequence("seq")
@instance.expects(:clear_shared_folders).once.in_sequence(seq)
@app.expects(:call).with(@env).once
@instance.call(@env)
end
end
context "clearing shared folders" do
setup do
@shared_folder = mock("shared_folder")
@shared_folders = [@shared_folder]
@internal_vm.stubs(:shared_folders).returns(@shared_folders)
end
should "call destroy on each shared folder then reload" do
destroy_seq = sequence("destroy")
@shared_folders.each do |sf|
sf.expects(:destroy).once.in_sequence(destroy_seq)
end
@vm.expects(:reload!).once.in_sequence(destroy_seq)
@instance.clear_shared_folders
end
should "do nothing if no shared folders existed" do
@shared_folders.clear
@vm.expects(:reload!).never
@instance.clear_shared_folders
end
end
end

View File

@ -38,7 +38,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
context "calling" do
should "run the methods in the proper order" do
before_seq = sequence("before")
@instance.expects(:clear_shared_folders).once.in_sequence(before_seq)
@instance.expects(:create_metadata).once.in_sequence(before_seq)
@app.expects(:call).with(@env).in_sequence(before_seq)
@instance.expects(:mount_shared_folders).once.in_sequence(before_seq)
@ -51,7 +50,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
@env.error!(:foo)
before_seq = sequence("before")
@instance.expects(:clear_shared_folders).once.in_sequence(before_seq)
@instance.expects(:create_metadata).once.in_sequence(before_seq)
@app.expects(:call).with(@env).in_sequence(before_seq)
@instance.expects(:mount_shared_folders).never
@ -129,30 +127,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
end
end
context "clearing shared folders" do
setup do
@shared_folder = mock("shared_folder")
@shared_folders = [@shared_folder]
@internal_vm.stubs(:shared_folders).returns(@shared_folders)
end
should "call destroy on each shared folder then reload" do
destroy_seq = sequence("destroy")
@shared_folders.each do |sf|
sf.expects(:destroy).once.in_sequence(destroy_seq)
end
@vm.expects(:reload!).once.in_sequence(destroy_seq)
@instance.clear_shared_folders
end
should "do nothing if no shared folders existed" do
@shared_folders.clear
@vm.expects(:reload!).never
@instance.clear_shared_folders
end
end
context "setting up shared folder metadata" do
setup do
stub_shared_folders

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-07-07}
s.date = %q{2010-07-08}
s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
@ -34,14 +34,19 @@ Gem::Specification.new do |s|
"keys/vagrant.pub",
"lib/vagrant.rb",
"lib/vagrant/action.rb",
"lib/vagrant/action/action_exception.rb",
"lib/vagrant/action/box/destroy.rb",
"lib/vagrant/action/box/download.rb",
"lib/vagrant/action/box/unpackage.rb",
"lib/vagrant/action/box/verify.rb",
"lib/vagrant/action/builder.rb",
"lib/vagrant/action/builtin.rb",
"lib/vagrant/action/environment.rb",
"lib/vagrant/action/error_halt.rb",
"lib/vagrant/action/exception_catcher.rb",
"lib/vagrant/action/vm/boot.rb",
"lib/vagrant/action/vm/check_guest_additions.rb",
"lib/vagrant/action/vm/clear_shared_folders.rb",
"lib/vagrant/action/vm/customize.rb",
"lib/vagrant/action/vm/destroy.rb",
"lib/vagrant/action/vm/destroy_unused_network_interfaces.rb",
@ -57,32 +62,6 @@ Gem::Specification.new do |s|
"lib/vagrant/action/vm/resume.rb",
"lib/vagrant/action/vm/share_folders.rb",
"lib/vagrant/action/vm/suspend.rb",
"lib/vagrant/actions/base.rb",
"lib/vagrant/actions/box/add.rb",
"lib/vagrant/actions/box/destroy.rb",
"lib/vagrant/actions/box/download.rb",
"lib/vagrant/actions/box/unpackage.rb",
"lib/vagrant/actions/box/verify.rb",
"lib/vagrant/actions/collection.rb",
"lib/vagrant/actions/runner.rb",
"lib/vagrant/actions/vm/boot.rb",
"lib/vagrant/actions/vm/customize.rb",
"lib/vagrant/actions/vm/destroy.rb",
"lib/vagrant/actions/vm/down.rb",
"lib/vagrant/actions/vm/export.rb",
"lib/vagrant/actions/vm/forward_ports.rb",
"lib/vagrant/actions/vm/halt.rb",
"lib/vagrant/actions/vm/import.rb",
"lib/vagrant/actions/vm/move_hard_drive.rb",
"lib/vagrant/actions/vm/network.rb",
"lib/vagrant/actions/vm/package.rb",
"lib/vagrant/actions/vm/provision.rb",
"lib/vagrant/actions/vm/reload.rb",
"lib/vagrant/actions/vm/resume.rb",
"lib/vagrant/actions/vm/shared_folders.rb",
"lib/vagrant/actions/vm/start.rb",
"lib/vagrant/actions/vm/suspend.rb",
"lib/vagrant/actions/vm/up.rb",
"lib/vagrant/active_list.rb",
"lib/vagrant/box.rb",
"lib/vagrant/busy.rb",
@ -137,13 +116,17 @@ Gem::Specification.new do |s|
"templates/unison/crontab_entry.erb",
"templates/unison/script.erb",
"test/test_helper.rb",
"test/vagrant/action/box/destroy_test.rb",
"test/vagrant/action/box/download_test.rb",
"test/vagrant/action/box/unpackage_test.rb",
"test/vagrant/action/box/verify_test.rb",
"test/vagrant/action/builder_test.rb",
"test/vagrant/action/environment_test.rb",
"test/vagrant/action/error_halt_test.rb",
"test/vagrant/action/exception_catcher_test.rb",
"test/vagrant/action/vm/boot_test.rb",
"test/vagrant/action/vm/check_guest_additions_test.rb",
"test/vagrant/action/vm/clear_shared_folders_test.rb",
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/destroy_test.rb",
"test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb",
@ -160,32 +143,6 @@ Gem::Specification.new do |s|
"test/vagrant/action/vm/share_folders_test.rb",
"test/vagrant/action/vm/suspend_test.rb",
"test/vagrant/action_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/download_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/collection_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/vm/boot_test.rb",
"test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/actions/vm/destroy_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/actions/vm/halt_test.rb",
"test/vagrant/actions/vm/import_test.rb",
"test/vagrant/actions/vm/move_hard_drive_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/provision_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/resume_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/start_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/active_list_test.rb",
"test/vagrant/box_test.rb",
"test/vagrant/busy_test.rb",
@ -237,13 +194,17 @@ Gem::Specification.new do |s|
s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.test_files = [
"test/test_helper.rb",
"test/vagrant/action/box/destroy_test.rb",
"test/vagrant/action/box/download_test.rb",
"test/vagrant/action/box/unpackage_test.rb",
"test/vagrant/action/box/verify_test.rb",
"test/vagrant/action/builder_test.rb",
"test/vagrant/action/environment_test.rb",
"test/vagrant/action/error_halt_test.rb",
"test/vagrant/action/exception_catcher_test.rb",
"test/vagrant/action/vm/boot_test.rb",
"test/vagrant/action/vm/check_guest_additions_test.rb",
"test/vagrant/action/vm/clear_shared_folders_test.rb",
"test/vagrant/action/vm/customize_test.rb",
"test/vagrant/action/vm/destroy_test.rb",
"test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb",
@ -260,32 +221,6 @@ Gem::Specification.new do |s|
"test/vagrant/action/vm/share_folders_test.rb",
"test/vagrant/action/vm/suspend_test.rb",
"test/vagrant/action_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/download_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/collection_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/vm/boot_test.rb",
"test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/actions/vm/destroy_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/actions/vm/halt_test.rb",
"test/vagrant/actions/vm/import_test.rb",
"test/vagrant/actions/vm/move_hard_drive_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/provision_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/resume_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/start_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/active_list_test.rb",
"test/vagrant/box_test.rb",
"test/vagrant/busy_test.rb",