diff --git a/test/acceptance/support/output.rb b/test/acceptance/support/output.rb index 8ecbdcaae..75a3f2d6c 100644 --- a/test/acceptance/support/output.rb +++ b/test/acceptance/support/output.rb @@ -78,5 +78,10 @@ module Acceptance def vm_halt_force @text =~ /Forcing shutdown of VM...$/ end + + # Output shows the VM is in the process of suspending + def vm_suspending + @text =~ /Saving VM state and suspending execution...$/ + end end end diff --git a/test/acceptance/suspend_test.rb b/test/acceptance/suspend_test.rb new file mode 100644 index 000000000..d0cb3ed27 --- /dev/null +++ b/test/acceptance/suspend_test.rb @@ -0,0 +1,52 @@ +require File.expand_path("../base", __FILE__) +require "support/shared/command_examples" + +describe "vagrant suspend" do + include_context "acceptance" + it_behaves_like "a command that requires a Vagrantfile", ["vagrant", "suspend"] + + 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", "suspend") + result.stdout.should match_output(:vm_not_created_warning) + end + + it "is able to suspend 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") + + # Suspend the VM and assert that it worked properly (seemingly) + result = assert_execute("vagrant", "suspend") + result.stdout.should match_output(:vm_suspending) + + # Assert that the VM is no longer running + result = assert_execute("vagrant", "status") + result.stdout.should match_output(:status, "default", "saved") + end + + it "is able to resume after the machine has been suspended" do + require_box("default") + + assert_execute("vagrant", "box", "add", "base", box_path("default")) + assert_execute("vagrant", "init") + assert_execute("vagrant", "up") + assert_execute("vagrant", "suspend") + + # Assert that the VM is no longer running + result = assert_execute("vagrant", "status") + result.stdout.should match_output(:status, "default", "saved") + + assert_execute("vagrant", "resume") + + # Assert that the VM is once again running + result = assert_execute("vagrant", "status") + result.stdout.should match_output(:status, "default", "running") + end +end