From a56f4a43ddc3bc38874376cb8cf365014c18ad97 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 15 May 2010 01:51:45 -0700 Subject: [PATCH] Up command will up multiple VMs (persisting doesn't work yet) --- lib/vagrant/commands/up.rb | 4 +-- test/vagrant/commands/up_test.rb | 45 +++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/vagrant/commands/up.rb b/lib/vagrant/commands/up.rb index d8519a15b..6a15a52e2 100644 --- a/lib/vagrant/commands/up.rb +++ b/lib/vagrant/commands/up.rb @@ -16,10 +16,10 @@ module Vagrant env.vms.each do |name, vm| if vm.created? logger.info "VM '#{name}' already created. Booting if its not already running..." - # vm.start + vm.start else logger.info "Creating VM '#{name}'" - # env.create_vm.execute!(Actions::VM::Up) + vm.execute!(Actions::VM::Up) end end end diff --git a/test/vagrant/commands/up_test.rb b/test/vagrant/commands/up_test.rb index 777df4cbf..ba2aed82b 100644 --- a/test/vagrant/commands/up_test.rb +++ b/test/vagrant/commands/up_test.rb @@ -16,25 +16,50 @@ class CommandsUpTest < Test::Unit::TestCase @new_vm = mock("vm") @new_vm.stubs(:execute!) - @env.stubs(:vm).returns(nil) + @vms = {} + + @env.stubs(:vms).returns(@vms) @env.stubs(:require_box) - @env.stubs(:create_vm).returns(@new_vm) end - should "require a box" do - @env.expects(:require_box).once + def create_vm + env = mock_environment + env.stubs(:require_box) + + vm = mock("vm") + vm.stubs(:env).returns(env) + vm.stubs(:execute!) + vm.stubs(:created?).returns(false) + vm + end + + should "require a box for all VMs" do + @vms[:foo] = create_vm + @vms[:bar] = create_vm + + @vms.each do |name, vm| + vm.env.expects(:require_box).once + end + @instance.execute end - should "call the up action on VM if it doesn't exist" do - @new_vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once + should "start created VMs" do + vm = create_vm + vm.stubs(:created?).returns(true) + + @vms[:foo] = vm + + vm.expects(:start).once @instance.execute end - should "call start on the persisted vm if it exists" do - @env.stubs(:vm).returns(@persisted_vm) - @persisted_vm.expects(:start).once - @env.expects(:create_vm).never + should "up non-created VMs" do + vm = create_vm + vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once + vm.expects(:start).never + + @vms[:foo] = vm @instance.execute end end