From 1ed1650fb68978fd0bdcfc0146a6a37629efee2d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 22 Nov 2011 19:34:25 -0800 Subject: [PATCH] `vagrant halt` acceptance tests --- test/acceptance/halt_test.rb | 54 +++++++++++++++++++++++++++++++ test/acceptance/support/output.rb | 10 ++++++ 2 files changed, 64 insertions(+) create mode 100644 test/acceptance/halt_test.rb diff --git a/test/acceptance/halt_test.rb b/test/acceptance/halt_test.rb new file mode 100644 index 000000000..876d1586c --- /dev/null +++ b/test/acceptance/halt_test.rb @@ -0,0 +1,54 @@ +require File.expand_path("../base", __FILE__) +require "support/shared/command_examples" + +describe "vagrant halt" do + include_context "acceptance" + it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "halt"] + + it "succeeds and ignores if the VM is not created" do + require_box("default") + + assert_execute("vagrant", "box", "add", "base", box_path("default")) + assert_execute("vagrant", "init") + + result = assert_execute("vagrant", "halt") + result.stdout.should match_output(:vm_not_created_warning) + end + + it "is able to halt a running virtual machine" do + require_box("default") + + assert_execute("vagrant", "box", "add", "base", box_path("default")) + assert_execute("vagrant", "init") + assert_execute("vagrant", "up") + + # Halt the VM and assert that it worked properly (seemingly) + result = assert_execute("vagrant", "halt") + result.stdout.should match_output(:vm_halt_graceful) + + # Assert that the VM no longer is created + result = assert_execute("vagrant", "status") + result.stdout.should match_output(:status, "default", "powered off") + end + + it "is able to force halt a running virtual machine" do + require_box("default") + + assert_execute("vagrant", "box", "add", "base", box_path("default")) + assert_execute("vagrant", "init") + assert_execute("vagrant", "up") + + # Halt the VM and assert that it worked properly (seemingly) + result = assert_execute("vagrant", "halt", "--force") + result.stdout.should match_output(:vm_halt_force) + + # Assert that the VM no longer is created + result = assert_execute("vagrant", "status") + result.stdout.should match_output(:status, "default", "powered off") + end + + # TODO: + # halt behavior on suspend machine + # halt behavior if machine is already powered off + # VM can come back up after a halt +end diff --git a/test/acceptance/support/output.rb b/test/acceptance/support/output.rb index deac8dbdd..8ecbdcaae 100644 --- a/test/acceptance/support/output.rb +++ b/test/acceptance/support/output.rb @@ -68,5 +68,15 @@ module Acceptance def up_fetching_box(name, vm=DEFAULT_VM) @text =~ /^\[#{vm}\] Box #{name} was not found. Fetching box from specified URL...$/ end + + # Check that the output shows that the VM was shut down gracefully + def vm_halt_graceful + @text =~ /Attempting graceful shutdown of/ + end + + # Output shows a forceful VM shutdown. + def vm_halt_force + @text =~ /Forcing shutdown of VM...$/ + end end end