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

- old
+ new

@@ -1,15 +1,57 @@ require 'spec_helper' describe Ridley::HostConnector::SSH::Worker do - describe "ClassMethods" do - let(:host) { 'reset.riotgames.com' } + subject { ssh_worker } + let(:ssh_worker) { described_class.new(host, options) } + + let(:host) { 'reset.riotgames.com' } + let(:options) { {} } + + describe "#sudo" do + subject { ssh_worker.sudo } + + it { should be_false } + + context "with sudo" do + let(:options) { { ssh: { sudo: true } } } + + it { should be_true } + end + end + + describe "#chef_client" do + subject(:chef_client) { ssh_worker.chef_client } + + it { should be_a(Array) } + + context "with sudo" do + let(:options) { { ssh: { sudo: true } } } + + it "sends a run command with sudo" do + ssh_worker.should_receive(:run).with("sudo chef-client") + chef_client + end + end + end + + describe "#put_secret" do + subject(:put_secret) { ssh_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 } - subject { described_class } + it "receives a run command with echo" do + ssh_worker.should_receive(:run).with("echo '#{secret}' > /etc/chef/encrypted_data_bag_secret; chmod 0600 /etc/chef/encrypted_data_bag_secret") + put_secret + end + end - describe "::new" do - it { subject.new(host, ssh: {sudo: true}).sudo.should be_true } - it { subject.new(host, ssh: {sudo: false}).sudo.should be_false } - it { subject.new(host).sudo.should be_false } + describe "#ruby_script" do + subject(:ruby_script) { ssh_worker.ruby_script(command_lines) } + let(:command_lines) { ["puts 'hello'", "puts 'there'"] } + + it "receives a ruby call with the command" do + ssh_worker.should_receive(:run).with("#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"") + ruby_script end end end