From beacb5bada0fa65478f0eabc1d22336ffead3dd0 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 24 May 2018 16:56:46 -0700 Subject: [PATCH] Add test coverage for all hyper-v configuration options --- .../plugins/providers/hyperv/config_test.rb | 153 +++++++++++++++++- 1 file changed, 152 insertions(+), 1 deletion(-) diff --git a/test/unit/plugins/providers/hyperv/config_test.rb b/test/unit/plugins/providers/hyperv/config_test.rb index 467fc7f97..efce526be 100644 --- a/test/unit/plugins/providers/hyperv/config_test.rb +++ b/test/unit/plugins/providers/hyperv/config_test.rb @@ -3,6 +3,9 @@ require_relative "../../../base" require Vagrant.source_root.join("plugins/providers/hyperv/config") describe VagrantPlugins::HyperV::Config do + + let(:machine){ double("machine") } + describe "#ip_address_timeout" do it "can be set" do subject.ip_address_timeout = 180 @@ -30,7 +33,7 @@ describe VagrantPlugins::HyperV::Config do expect(subject.mac).to eq("001122334455") end end - + describe "#vmname" do it "can be set" do subject.vmname = "test" @@ -62,4 +65,152 @@ describe VagrantPlugins::HyperV::Config do expect(subject.cpus).to eq(2) end end + + describe "#vmname" do + it "can be set" do + subject.vmname = "custom" + subject.finalize! + expect(subject.vmname).to eq("custom") + end + end + + describe "#differencing_disk" do + it "is false by default" do + subject.finalize! + expect(subject.differencing_disk).to eq(false) + end + + it "can be set" do + subject.differencing_disk = true + subject.finalize! + expect(subject.differencing_disk).to eq(true) + end + + it "should set linked_clone" do + subject.differencing_disk = true + subject.finalize! + expect(subject.differencing_disk).to eq(true) + expect(subject.linked_clone).to eq(true) + end + end + + describe "#linked_clone" do + it "is false by default" do + subject.finalize! + expect(subject.linked_clone).to eq(false) + end + + it "can be set" do + subject.linked_clone = true + subject.finalize! + expect(subject.linked_clone).to eq(true) + end + + it "should set differencing_disk" do + subject.linked_clone = true + subject.finalize! + expect(subject.linked_clone).to eq(true) + expect(subject.differencing_disk).to eq(true) + end + end + + describe "#auto_start_action" do + it "should be Nothing by default" do + subject.finalize! + expect(subject.auto_start_action).to eq("Nothing") + end + + it "can be set" do + subject.auto_start_action = "Start" + subject.finalize! + expect(subject.auto_start_action).to eq("Start") + end + + it "does not accept invalid values" do + subject.auto_start_action = "Invalid" + subject.finalize! + result = subject.validate(machine) + expect(result["Hyper-V"]).not_to be_empty + end + end + + describe "#auto_stop_action" do + it "should be ShutDown by default" do + subject.finalize! + expect(subject.auto_stop_action).to eq("ShutDown") + end + + it "can be set" do + subject.auto_stop_action = "Save" + subject.finalize! + expect(subject.auto_stop_action).to eq("Save") + end + + it "does not accept invalid values" do + subject.auto_stop_action = "Invalid" + subject.finalize! + result = subject.validate(machine) + expect(result["Hyper-V"]).not_to be_empty + end + end + + describe "#enable_checkpoints" do + it "is false by default" do + subject.finalize! + expect(subject.enable_checkpoints).to eq(false) + end + + it "can be set" do + subject.enable_checkpoints = true + subject.finalize! + expect(subject.enable_checkpoints).to eq(true) + end + end + + describe "#enable_virtualization_extensions" do + it "is false by default" do + subject.finalize! + expect(subject.enable_virtualization_extensions).to eq(false) + end + + it "can be set" do + subject.enable_virtualization_extensions = true + subject.finalize! + expect(subject.enable_virtualization_extensions).to eq(true) + end + end + + describe "#vm_integration_services" do + it "is empty by default" do + subject.finalize! + expect(subject.vm_integration_services).to be_empty + end + + it "accepts new entries" do + subject.vm_integration_services["entry"] = "value" + subject.finalize! + expect(subject.vm_integration_services["entry"]).to eq("value") + end + + it "does not accept non-Hash types" do + subject.vm_integration_services = "value" + subject.finalize! + result = subject.validate(machine) + expect(result["Hyper-V"]).not_to be_empty + end + + it "accepts boolean values within Hash" do + subject.vm_integration_services["custom"] = true + subject.finalize! + result = subject.validate(machine) + expect(result["Hyper-V"]).to be_empty + end + + it "does not accept non-boolean values within Hash" do + subject.vm_integration_services["custom"] = "value" + subject.finalize! + result = subject.validate(machine) + expect(result["Hyper-V"]).not_to be_empty + end + end end