mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Simple prepare test for 9p and virtiofs synced_folders (#1529)
Provide basic tests for 9p and virtiofs synced_folder capabilities to validate prepare behaviour.
This commit is contained in:
@@ -37,5 +37,6 @@ shared_context 'unit' do
|
||||
before (:each) do
|
||||
allow(machine).to receive(:guest).and_return(guest)
|
||||
allow(machine).to receive(:communicate).and_return(communicator)
|
||||
allow(machine).to receive(:ui).and_return(ui)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -195,7 +195,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::ClearForwardedPorts do
|
||||
end
|
||||
end
|
||||
it 'should terminate each of the processes' do
|
||||
expect(logger).to receive(:info).with(no_args) # don't know how to test translations from vagrant
|
||||
expect(subject).to receive(:ssh_pid?).with("10001").and_return(true)
|
||||
expect(subject).to receive(:ssh_pid?).with("10002").and_return(true)
|
||||
expect(logger).to receive(:debug).with(/Killing pid/).twice()
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'spec_helper'
|
||||
require 'support/sharedcontext'
|
||||
|
||||
require 'vagrant-libvirt/cap/synced_folder_9p'
|
||||
require 'vagrant-libvirt/util/unindent'
|
||||
|
||||
describe VagrantPlugins::SyncedFolder9P::SyncedFolder do
|
||||
include_context 'unit'
|
||||
@@ -11,6 +12,79 @@ describe VagrantPlugins::SyncedFolder9P::SyncedFolder do
|
||||
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#prepare' do
|
||||
let(:synced_folders) { {
|
||||
"/vagrant" => {
|
||||
:hostpath => '/home/test/default',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/vagrant',
|
||||
:type => :"9p",
|
||||
},
|
||||
} }
|
||||
|
||||
let(:expected_xml) {
|
||||
<<-EOF.unindent
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="path" wrpolicy="immediate"></driver>
|
||||
<source dir="/home/test/default"></source>
|
||||
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
||||
</filesystem>
|
||||
EOF
|
||||
}
|
||||
|
||||
before do
|
||||
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
||||
allow(logger).to receive(:debug)
|
||||
end
|
||||
|
||||
it 'should attach device xml' do
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml, 0)
|
||||
|
||||
subject.prepare(machine, synced_folders, {})
|
||||
end
|
||||
|
||||
context 'multiple folders' do
|
||||
let(:synced_folders) { {
|
||||
"/vagrant" => {
|
||||
:hostpath => '/home/test/default',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/vagrant',
|
||||
:type => :"9p",
|
||||
},
|
||||
"/custom" => {
|
||||
:hostpath => '/home/test/custom',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/custom',
|
||||
:type => :"9p",
|
||||
},
|
||||
} }
|
||||
|
||||
let(:expected_xml) {
|
||||
[ <<-XML1.unindent, <<-XML2.unindent ]
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="path" wrpolicy="immediate"></driver>
|
||||
<source dir="/home/test/default"></source>
|
||||
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
||||
</filesystem>
|
||||
XML1
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="path" wrpolicy="immediate"></driver>
|
||||
<source dir="/home/test/custom"></source>
|
||||
<target dir=\"a2a1a8b6d98be8f790f3c987e006d13\"></target>
|
||||
</filesystem>
|
||||
XML2
|
||||
}
|
||||
|
||||
it 'should attach all device xml' do
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[0], 0)
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[1], 0)
|
||||
expect(ui).to receive(:info).with(/Configuring 9p devices for shared folders/).once
|
||||
|
||||
subject.prepare(machine, synced_folders, {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#usable?' do
|
||||
context 'with libvirt provider' do
|
||||
before do
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'spec_helper'
|
||||
require 'support/sharedcontext'
|
||||
|
||||
require 'vagrant-libvirt/cap/synced_folder_virtiofs'
|
||||
require 'vagrant-libvirt/util/unindent'
|
||||
|
||||
describe VagrantPlugins::SyncedFolderVirtioFS::SyncedFolder do
|
||||
include_context 'unit'
|
||||
@@ -11,6 +12,79 @@ describe VagrantPlugins::SyncedFolderVirtioFS::SyncedFolder do
|
||||
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#prepare' do
|
||||
let(:synced_folders) { {
|
||||
"/vagrant" => {
|
||||
:hostpath => '/home/test/default',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/vagrant',
|
||||
:type => :virtiofs,
|
||||
},
|
||||
} }
|
||||
|
||||
let(:expected_xml) {
|
||||
<<-EOF.unindent
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="virtiofs"></driver>
|
||||
<source dir="/home/test/default"></source>
|
||||
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
||||
</filesystem>
|
||||
EOF
|
||||
}
|
||||
|
||||
before do
|
||||
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
||||
allow(logger).to receive(:debug)
|
||||
end
|
||||
|
||||
it 'should attach device xml' do
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml, 0)
|
||||
|
||||
subject.prepare(machine, synced_folders, {})
|
||||
end
|
||||
|
||||
context 'multiple folders' do
|
||||
let(:synced_folders) { {
|
||||
"/vagrant" => {
|
||||
:hostpath => '/home/test/default',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/vagrant',
|
||||
:type => :virtiofs,
|
||||
},
|
||||
"/custom" => {
|
||||
:hostpath => '/home/test/custom',
|
||||
:disabled=>false,
|
||||
:guestpath=>'/custom',
|
||||
:type => :virtiofs,
|
||||
},
|
||||
} }
|
||||
|
||||
let(:expected_xml) {
|
||||
[ <<-XML1.unindent, <<-XML2.unindent ]
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="virtiofs"></driver>
|
||||
<source dir="/home/test/default"></source>
|
||||
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
||||
</filesystem>
|
||||
XML1
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="virtiofs"></driver>
|
||||
<source dir="/home/test/custom"></source>
|
||||
<target dir=\"a2a1a8b6d98be8f790f3c987e006d13\"></target>
|
||||
</filesystem>
|
||||
XML2
|
||||
}
|
||||
|
||||
it 'should attach all device xml' do
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[0], 0)
|
||||
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[1], 0)
|
||||
expect(ui).to receive(:info).with(/Configuring virtiofs devices for shared folders/).once
|
||||
|
||||
subject.prepare(machine, synced_folders, {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#usable?' do
|
||||
context 'with libvirt provider' do
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user