Sha256: 93430402e0ab798a48e68f776bead721d058fd248243971a908a361fc0f9a12b

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'
require 'vagrant-ovirt4/action/create_vm'
require 'vagrant-ovirt4/config'

describe VagrantPlugins::OVirtProvider::Action::CreateVM do
  include_context 'provider:action'

  let(:vm) { double('vm', id: 'ID') }

  subject(:action) { described_class.new(app, env) }

  before do
    allow(env[:ui]).to receive(:info)
    allow(env[:machine]).to receive(:"id=").with(vm.id)
    allow(vm_service.get).to receive(:status).and_return('down')
  end

  context 'given a custom vmname' do
    let(:vmname) { 'VMNAME' }

    it 'uses that as the name for machine creation' do
      env[:machine].provider_config.vmname = vmname
      expect(env[:vms_service]).to receive(:add).with(hash_including(name: vmname)).and_return(vm)
      action.call(env)
    end
  end

  context 'given no custom vmname' do
    context 'given a custom hostname' do
      let(:hostname) { 'HOSTNAME' }

      it 'uses that as the name for machine creation' do
        expect(env[:machine].config.vm).to receive(:hostname).and_return(hostname)
        expect(env[:vms_service]).to receive(:add).with(hash_including(name: hostname)).and_return(vm)
        action.call(env)
      end
    end

    context 'given no custom hostname' do
      it 'uses a default name for machine creation' do
        expect(env[:machine].config.vm).to receive(:hostname)
        expect(env[:vms_service]).to receive(:add).with(hash_including(name: 'vagrant')).and_return(vm)
        action.call(env)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-ovirt4-2.2.0 spec/vagrant-ovirt4/action/create_vm_spec.rb
vagrant-ovirt4-2.1.3 spec/vagrant-ovirt4/action/create_vm_spec.rb