mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Regression unit test for frozen string literal fix (#1393)
Add a unit test for the prepare nfs settings action to act as a regression test for the recent fix to avoiding modifying a frozen string literal. As part of this fix how the communicator is returned via a call to a machine for testing purposes and remove an obsolete expect from the wait till up tests as the code that would result in the communicator being called has been removed. Ensure that nfsd is not required to run the tests by mocking out the host capability check.
This commit is contained in:
parent
b475293fe9
commit
0b53be59cf
@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'vagrant/action/builtin/mixin_synced_folders'
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Util
|
||||
|
@ -36,6 +36,6 @@ shared_context 'unit' do
|
||||
|
||||
before (:each) do
|
||||
allow(machine).to receive(:guest).and_return(guest)
|
||||
allow(machine).to receive(:communicator).and_return(communicator)
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
end
|
||||
end
|
||||
|
55
spec/unit/action/prepare_nfs_settings_spec.rb
Normal file
55
spec/unit/action/prepare_nfs_settings_spec.rb
Normal file
@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require 'support/sharedcontext'
|
||||
|
||||
require 'vagrant-libvirt/action/prepare_nfs_settings'
|
||||
|
||||
|
||||
describe VagrantPlugins::ProviderLibvirt::Action::PrepareNFSSettings do
|
||||
subject { described_class.new(app, env) }
|
||||
|
||||
include_context 'unit'
|
||||
|
||||
describe '#call' do
|
||||
before do
|
||||
# avoid requiring nfsd installed to run tests
|
||||
allow(machine.env.host).to receive(:capability?).with(:nfs_installed).and_return(true)
|
||||
allow(machine.env.host).to receive(:capability).with(:nfs_installed).and_return(true)
|
||||
end
|
||||
|
||||
context 'when enabled' do
|
||||
let(:vagrantfile) do
|
||||
<<-EOF
|
||||
Vagrant.configure('2') do |config|
|
||||
config.vm.box = "vagrant-libvirt/test"
|
||||
config.vm.define :test
|
||||
config.vm.synced_folder ".", "/vagrant", type: "nfs"
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
#{vagrantfile_providerconfig}
|
||||
end
|
||||
end
|
||||
EOF
|
||||
end
|
||||
let(:socket) { double('socket') }
|
||||
|
||||
before do
|
||||
allow(::TCPSocket).to receive(:new).and_return(socket)
|
||||
allow(socket).to receive(:close)
|
||||
end
|
||||
|
||||
it 'should retrieve the guest IP address' do
|
||||
times_called = 0
|
||||
expect(::TCPSocket).to receive(:new) do
|
||||
# force reaching later code
|
||||
times_called += 1
|
||||
times_called < 2 ? raise("StandardError") : socket
|
||||
end
|
||||
expect(machine).to receive(:ssh_info).and_return({:host => '192.168.1.2'})
|
||||
expect(communicator).to receive(:execute).and_yield(:stdout, "192.168.1.2\n192.168.2.2")
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -62,7 +62,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
||||
expect(app).to_not receive(:call)
|
||||
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
||||
expect(ui).to_not receive(:info).with('Waiting for SSH to become available...')
|
||||
expect(env[:machine].communicate).to_not receive(:ready?)
|
||||
expect {subject.call(env) }.to raise_error(::Fog::Errors::TimeoutError)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user