From 63d1b5e33d027da366fafefed7de43da210cf9af Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 21 Dec 2017 08:07:24 -0800 Subject: [PATCH] Add test coverage for windows host configured IP addresses capability --- .../cap/configure_ip_addresses_test.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/unit/plugins/hosts/windows/cap/configure_ip_addresses_test.rb diff --git a/test/unit/plugins/hosts/windows/cap/configure_ip_addresses_test.rb b/test/unit/plugins/hosts/windows/cap/configure_ip_addresses_test.rb new file mode 100644 index 000000000..b9f298c1e --- /dev/null +++ b/test/unit/plugins/hosts/windows/cap/configure_ip_addresses_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +require_relative "../../../../../../plugins/hosts/windows/cap/configured_ip_addresses" + +describe VagrantPlugins::HostWindows::Cap::ConfiguredIPAddresses do + + let(:subject){ VagrantPlugins::HostWindows::Cap::ConfiguredIPAddresses } + let(:result){ Vagrant::Util::Subprocess::Result } + let(:addresses){ [] } + let(:execute_result){ result.new(0, {ip_addresses: addresses}.to_json, "") } + + before{ allow(Vagrant::Util::PowerShell).to receive(:execute). + and_return(execute_result) } + + it "should return an array" do + expect(subject.configured_ip_addresses(nil)).to be_kind_of(Array) + end + + context "with single address returned" do + let(:addresses){ "ADDRESS" } + + it "should return an array" do + expect(subject.configured_ip_addresses(nil)).to eq([addresses]) + end + end + + context "with multiple addresses returned" do + let(:addresses){ ["ADDRESS1", "ADDRESS2"] } + + it "should return an array" do + expect(subject.configured_ip_addresses(nil)).to eq(addresses) + end + end + + context "with failed script execution" do + let(:execute_result){ result.new(1, "", "") } + + it "should raise error" do + expect{ subject.configured_ip_addresses(nil) }.to raise_error( + Vagrant::Errors::PowerShellError) + end + end +end