diff --git a/spec/support/libvirt_context.rb b/spec/support/libvirt_context.rb
index e65eed8..152a08d 100644
--- a/spec/support/libvirt_context.rb
+++ b/spec/support/libvirt_context.rb
@@ -24,5 +24,7 @@ shared_context "libvirt" do
# return some information for domain when needed
allow(domain).to receive(:mac).and_return("9C:D5:53:F1:5A:E7")
+
+ machine.stub(:id => id)
end
end
diff --git a/spec/support/sharedcontext.rb b/spec/support/sharedcontext.rb
index adfa173..6f5f9af 100644
--- a/spec/support/sharedcontext.rb
+++ b/spec/support/sharedcontext.rb
@@ -29,7 +29,6 @@ shared_context "unit" do
before (:each) do
machine.stub(:guest => guest)
machine.stub(:communicator => communicator)
- machine.stub(:id => id)
end
end
diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml
new file mode 100644
index 0000000..b810415
--- /dev/null
+++ b/spec/unit/templates/domain_all_settings.xml
@@ -0,0 +1,125 @@
+
+
+
+
+ 1
+
+
+
+ qemu64
+
+
+
+
+
+ hvm
+ /efi/loader
+
+
+
+
+
+
+
+
+
+
+
+
+ /usr/bin/kvm-spice
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /dev/random
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spec/unit/templates/domain_defaults.xml b/spec/unit/templates/domain_defaults.xml
new file mode 100644
index 0000000..39abbf7
--- /dev/null
+++ b/spec/unit/templates/domain_defaults.xml
@@ -0,0 +1,44 @@
+
+
+
+
+ 1
+
+
+
+
+
+
+
+
+ hvm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb
new file mode 100644
index 0000000..23970c0
--- /dev/null
+++ b/spec/unit/templates/domain_spec.rb
@@ -0,0 +1,70 @@
+require "support/sharedcontext"
+
+require "vagrant-libvirt/config"
+require "vagrant-libvirt/util/erb_template"
+
+describe "templates/domain" do
+
+ include_context "unit"
+
+ class DomainTemplateHelper < VagrantPlugins::ProviderLibvirt::Config
+ include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
+ end
+
+ let(:domain) { DomainTemplateHelper.new }
+ let(:xml_expected) { File.read(File.join(File.dirname(__FILE__), test_file)) }
+
+ context "when only defaults used" do
+ let(:test_file) { 'domain_defaults.xml' }
+ it "renders template" do
+ domain.finalize!
+ expect(domain.to_xml('domain')).to eq xml_expected
+ end
+ end
+
+ context "when all settings enabled" do
+ before do
+ domain.instance_variable_set('@domain_type', 'kvm')
+ domain.cpu_mode = 'custom'
+ domain.cpu_feature({:name => 'AAA', :policy => 'required'})
+ domain.machine_type = 'pc-compatible'
+ domain.machine_arch = 'x86_64'
+ domain.loader = '/efi/loader'
+ domain.boot('network')
+ domain.boot('cdrom')
+ domain.boot('hd')
+ domain.emulator_path = '/usr/bin/kvm-spice'
+ domain.instance_variable_set('@domain_volume_path', '/var/lib/libvirt/images/test.qcow2')
+ domain.instance_variable_set('@domain_volume_cache', 'unsafe')
+ domain.disk_bus = 'ide'
+ domain.storage(:file, {:path => 'test-disk1.qcow2'})
+ domain.storage(:file, {:path => 'test-disk2.qcow2'})
+ domain.disks.each do |disk|
+ disk[:absolute_path] = '/var/lib/libvirt/images/' + disk[:path]
+ end
+ domain.storage(:file, {:device => :cdrom})
+ domain.storage(:file, {:device => :cdrom})
+ domain.channel(:type => 'unix',
+ :target_name => 'org.qemu.guest_agent.0',
+ :target_type => 'virtio')
+ domain.channel(:type => 'unix',
+ :target_type => 'guestfwd',
+ :target_address => '192.0.2.42',
+ :target_port => '4242',
+ :source_path => '/tmp/foo')
+ domain.random(:model => 'random')
+ domain.pci(:bus => '0x06', :slot => '0x12', :function => '0x5')
+ domain.pci(:bus => '0x03', :slot => '0x00', :function => '0x0')
+ domain.usb(:bus => '1', :device => '2', :vendor => '0x1234', :product => '0xabcd')
+ domain.redirdev(:type => 'tcp', :host => 'localhost', :port => '4000')
+ domain.redirfilter(:class => '0x0b', :vendor => '0x08e6',
+ :product => '0x3437', :version => '2.00', :allow => 'yes')
+ domain.tpm_path = '/dev/tpm0'
+ end
+ let(:test_file) { 'domain_all_settings.xml' }
+ it "renders template" do
+ domain.finalize!
+ expect(domain.to_xml('domain')).to eq xml_expected
+ end
+ end
+end