spec/unit/ridley/host_connector/winrm/worker_spec.rb in ridley-0.10.0.rc1 vs spec/unit/ridley/host_connector/winrm/worker_spec.rb in ridley-0.10.0.rc2

- old
+ new

@@ -1,41 +1,87 @@ require 'spec_helper' describe Ridley::HostConnector::WinRM::Worker do + subject { winrm_worker } + let(:winrm_worker) { described_class.new(host, options) } let(:host) { 'reset.riotgames.com' } - - let(:options) do - { - winrm: { - port: 1234 - } - } + let(:options) { {} } + + before do + Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(double('command_uploader')) end - subject { Ridley::HostConnector::WinRM::Worker.new(host, options) } - describe "#winrm_port" do - it "can be overridden if options contains :winrm_port" do - subject.winrm_port.should eq(1234) - end + subject(:winrm_port) { winrm_worker.winrm_port } - it "defaults to Ridley::HostConnector::DEFAULT_WINRM_PORT when not overridden" do - options.delete(:winrm) - subject.winrm_port.should eq(Ridley::HostConnector::DEFAULT_WINRM_PORT) + it { should eq(Ridley::HostConnector::DEFAULT_WINRM_PORT) } + + context "when overridden" do + let(:options) { { winrm: { port: 1234 } } } + + it { should eq(1234) } end end describe "#winrm" do - it "returns a WinRM::WinRMWebService" do - subject.winrm.should be_a(WinRM::WinRMWebService) - end + subject { winrm_worker.winrm } + + it { should be_a(WinRM::WinRMWebService) } end describe "#get_command" do + subject(:get_command) { winrm_worker.get_command(command, command_uploader_stub) } + let(:command) { "echo %TEMP%" } - context "when a command is less than 2047 characters" do - it "returns the command" do - subject.get_command(command).should eq(command) + let(:command_uploader_stub) { double('CommandUploader') } + + it { should eq(command) } + + context "when a command is more than 2047 characters" do + let(:command) { "a" * 2048 } + + it "uploads and returns a command" do + Ridley::HostConnector::WinRM::CommandUploader.stub new: command_uploader_stub + + command_uploader_stub.should_receive :upload + command_uploader_stub.stub command: "my command" + command_uploader_stub.stub(:cleanup) + + get_command.should eq("my command") end + end + end + + describe "#chef_client" do + subject(:chef_client) { winrm_worker.chef_client } + + it "receives a command to run chef-client" do + winrm_worker.should_receive(:run).with("chef-client") + + chef_client + end + end + + describe "#put_secret" do + subject(:put_secret) { winrm_worker.put_secret(encrypted_data_bag_secret_path) } + + let(:encrypted_data_bag_secret_path) { fixtures_path.join("encrypted_data_bag_secret").to_s } + let(:secret) { File.read(encrypted_data_bag_secret_path).chomp } + + it "receives a command to copy the secret" do + winrm_worker.should_receive(:run).with("echo #{secret} > C:\\chef\\encrypted_data_bag_secret") + + put_secret + end + end + + describe "#ruby_script" do + subject(:ruby_script) { winrm_worker.ruby_script(command_lines) } + let(:command_lines) { ["puts 'hello'", "puts 'there'"] } + + it "receives a ruby call with the command" do + winrm_worker.should_receive(:run).with("#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"") + + ruby_script end end end