Sha256: 4963e00200acbddb38a85ea0d2e961696578dc8bc2b86ea0dada25f21e768b41

Contents?: true

Size: 1.26 KB

Versions: 32

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

module Serverspec::Backend
  describe Exec do
    subject(:exec) { Serverspec::Backend::Exec.instance }

    describe '#run_command' do
      context 'when #chroot_dir is NOT set' do
        before do
          exec.stub(chroot_dir: nil) # because "include Singleton"
        end

        it 'runs the provided command as expected' do
          exec.should_receive(:`).with('echo "FOO" 2>&1')

          exec.run_command('echo "FOO"')
        end
      end

      context 'when #chroot_dir is set' do
        before do
          exec.stub(chroot_dir: '/path/to/chroot') # because "include Singleton"
        end

        it 'runs the provided command within the chroot' do
          chroot_command = %Q{
sudo chroot /path/to/chroot /bin/bash <<CHROOT_CMD
  echo "FOO" 2>&1; echo EXIT_CODE=\\$?
CHROOT_CMD
 2>&1}
          exec.should_receive(:`).with(chroot_command).and_return("FOO\nEXIT_CODE=0\n")

          exec.run_command('echo "FOO"')
        end

        it 'extracts the exit code returned from within the chroot into an Integer' do
          exec.stub(:` => "ATTENTION\nDO NOT CARE\nEXIT_CODE=8675309\n")

          result = exec.run_command('do_not_care')

          expect(result[:exit_status]).to eq(867_5309)
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bosh-stemcell-1.5.0.pre.1226 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1215 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1211 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1210 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1209 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1193 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1190 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1181 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1179 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1178 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1177 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1176 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1173 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1172 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1168 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1166 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1165 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1164 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1154 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb
bosh-stemcell-1.5.0.pre.1153 spec/bosh/monkeypatch/serverspec/backend/exec_spec.rb