Sha256: 5d88b28c270f4c9e10a5b8f8b2b3f5857fe67aeb465abfa1b8cca8dc0bf995ef

Contents?: true

Size: 1.75 KB

Versions: 101

Compression:

Stored size: 1.75 KB

Contents

require "test_helper"

class ImportVMActionTest < Test::Unit::TestCase
  setup do
    clean_paths
    vagrant_box("foo")

    @klass = Vagrant::Action::VM::Import
    @app, @env = action_env(vagrant_env(vagrantfile(<<-vf)))
      config.vm.box = "foo"
    vf

    @instance = @klass.new(@app, @env)

    @env.env.vm = Vagrant::VM.new(:env => @env.env, :name => "foobar")

    VirtualBox::VM.stubs(:import)

    @vm = mock("vm")
    @vm.stubs(:uuid).returns("foobar")
  end

  should "call import on VirtualBox with proper base" do
    VirtualBox::VM.expects(:import).once.with(@env.env.box.ovf_file.to_s).returns(@vm)
    @instance.call(@env)
  end

  should "call next in chain on success and set VM" do
    VirtualBox::VM.stubs(:import).returns(@vm)
    @app.expects(:call).with(@env).once
    @instance.call(@env)

    assert_equal @vm, @env["vm"].vm
  end

  should "mark environment erroneous and not continue chain on failure" do
    @app.expects(:call).never
    assert_raises(Vagrant::Errors::VMImportFailure) {
      @instance.call(@env)
    }
  end

  context "recovery" do
    setup do
      @env.env.vm.stubs(:created?).returns(true)
    end

    should "not run the destroy action on recover if error is a VagrantError" do
      @env["vagrant.error"] = Vagrant::Errors::VMImportFailure.new
      @env.env.actions.expects(:run).never
      @instance.recover(@env)
    end

    should "not run the destroy action on recover if VM is not created" do
      @env.env.vm.stubs(:created?).returns(false)
      @env.env.actions.expects(:run).never
      @instance.recover(@env)
    end

    should "run the destroy action on recover" do
      @env.env.vm.stubs(:created?).returns(true)
      @env.env.actions.expects(:run).with(:destroy).once
      @instance.recover(@env)
    end
  end
end

Version data entries

101 entries across 101 versions & 9 rubygems

Version Path
bmhatfield-vagrant-1.0.10 test/unit_legacy/vagrant/action/vm/import_test.rb
bmhatfield-vagrant-1.0.9 test/unit_legacy/vagrant/action/vm/import_test.rb
bmhatfield-vagrant-1.0.8 test/unit_legacy/vagrant/action/vm/import_test.rb
bmhatfield-vagrant-1.0.7 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.7 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.6 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.5 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.4 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.3 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.2 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.1 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-1.0.0 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.99.2 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.99.1 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.7 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.6 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.5 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.4 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.3 test/unit_legacy/vagrant/action/vm/import_test.rb
vagrantup-0.9.2 test/unit_legacy/vagrant/action/vm/import_test.rb