Merge pull request #3527 from mitchellh/windows-unit-test-code-review-feedback

Windows unit test code review feedback
This commit is contained in:
Mitchell Hashimoto 2014-04-23 21:36:59 -07:00
commit 0b4b9296ae
2 changed files with 17 additions and 17 deletions

View File

@ -12,14 +12,14 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
let(:shell) { double("shell") } let(:shell) { double("shell") }
subject do subject do
comm = described_class.new(machine) described_class.new(machine).tap do |comm|
allow(comm).to receive(:create_shell).and_return(shell) allow(comm).to receive(:create_shell).and_return(shell)
comm end
end end
describe ".ready?" do describe ".ready?" do
it "returns true if hostname command executes without error" do it "returns true if hostname command executes without error" do
expect(shell).to receive(:powershell).with("hostname").and_return({ :exitcode => 0 }) expect(shell).to receive(:powershell).with("hostname").and_return({ exitcode: 0 })
expect(subject.ready?).to be_true expect(subject.ready?).to be_true
end end
@ -38,35 +38,35 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
describe ".execute" do describe ".execute" do
it "defaults to running in powershell" do it "defaults to running in powershell" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 0 }) expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 0 })
expect(subject.execute("dir")).to eq(0) expect(subject.execute("dir")).to eq(0)
end end
it "can use cmd shell" do it "can use cmd shell" do
expect(shell).to receive(:cmd).with(kind_of(String)).and_return({ :exitcode => 0 }) expect(shell).to receive(:cmd).with(kind_of(String)).and_return({ exitcode: 0 })
expect(subject.execute("dir", { :shell => :cmd })).to eq(0) expect(subject.execute("dir", { :shell => :cmd })).to eq(0)
end end
it "raises error when error_check is true and exit code is non-zero" do it "raises error when error_check is true and exit code is non-zero" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 })
expect { subject.execute("dir") }.to raise_error( expect { subject.execute("dir") }.to raise_error(
VagrantPlugins::CommunicatorWinRM::Errors::ExecutionError) VagrantPlugins::CommunicatorWinRM::Errors::ExecutionError)
end end
it "does not raise error when error_check is false and exit code is non-zero" do it "does not raise error when error_check is false and exit code is non-zero" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 })
expect(subject.execute("dir", { :error_check => false })).to eq(1) expect(subject.execute("dir", { :error_check => false })).to eq(1)
end end
end end
describe ".test" do describe ".test" do
it "returns true when exit code is zero" do it "returns true when exit code is zero" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 0 }) expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 0 })
expect(subject.test("test -d c:/windows")).to be_true expect(subject.test("test -d c:/windows")).to be_true
end end
it "returns false when exit code is non-zero" do it "returns false when exit code is non-zero" do
expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ :exitcode => 1 }) expect(shell).to receive(:powershell).with(kind_of(String)).and_return({ exitcode: 1 })
expect(subject.test("test -d /tmp/foobar")).to be_false expect(subject.test("test -d /tmp/foobar")).to be_false
end end

View File

@ -8,14 +8,14 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
let(:session) { double("winrm_session") } let(:session) { double("winrm_session") }
subject do subject do
comm = described_class.new('localhost', 'username', 'password') described_class.new('localhost', 'username', 'password').tap do |comm|
allow(comm).to receive(:new_session).and_return(session) allow(comm).to receive(:new_session).and_return(session)
comm end
end end
describe ".powershell" do describe ".powershell" do
it "should call winrm powershell" do it "should call winrm powershell" do
expect(session).to receive(:powershell).with("dir").and_return({ :exitcode => 0 }) expect(session).to receive(:powershell).with("dir").and_return({ exitcode: 0 })
expect(subject.powershell("dir")[:exitcode]).to eq(0) expect(subject.powershell("dir")[:exitcode]).to eq(0)
end end
@ -36,7 +36,7 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
describe ".cmd" do describe ".cmd" do
it "should call winrm cmd" do it "should call winrm cmd" do
expect(session).to receive(:cmd).with("dir").and_return({ :exitcode => 0 }) expect(session).to receive(:cmd).with("dir").and_return({ exitcode: 0 })
expect(subject.cmd("dir")[:exitcode]).to eq(0) expect(subject.cmd("dir")[:exitcode]).to eq(0)
end end
end end
@ -50,8 +50,8 @@ describe VagrantPlugins::CommunicatorWinRM::WinRMShell do
describe ".endpoint_options" do describe ".endpoint_options" do
it "should create endpoint options" do it "should create endpoint options" do
expect(subject.send(:endpoint_options)).to eq( expect(subject.send(:endpoint_options)).to eq(
{ :user => "username", :pass => "password", :host => "localhost", :port => 5985, { user: "username", pass: "password", host: "localhost", port: 5985,
:operation_timeout => 60, :basic_auth_only => true }) operation_timeout: 60, basic_auth_only: true })
end end
end end