Sha256: e1175f81352164b1bc5a1d9186b46eb1df1ac81047f2b0ab12ceb249375080a9

Contents?: true

Size: 1.58 KB

Versions: 8

Compression:

Stored size: 1.58 KB

Contents

require 'vagrant-deltacloud-provider/spec_helper'

describe VagrantPlugins::Deltacloud::Action::WaitForServerToBeAccessible do

  let(:config) do
    double('config')
  end

  let(:env) do
    Hash.new.tap do |env|
      env[:ui] = double('ui')
      env[:ui].stub(:info).with(anything)
      env[:ui].stub(:error).with(anything)
      env[:machine] = double('machine').tap do |m|
        m.stub(:provider_config) { config }
      end
    end
  end

  let(:resolver) do
    double('resolver').tap do |r|
      r.stub(:resolve_ip).with(anything) { '1.2.3.4' }
    end
  end

  let(:ssh) do
    double('shh')
  end

  let(:app) do
    double('app').tap do |app|
      app.stub(:call).with(anything)
    end
  end

  class SSHMock
    def initialize(*exit_codes)
      @times = 0
      @exit_codes = exit_codes
    end

    def call(env)
      env[:ssh_run_exit_status] = @exit_codes[@times]
      @times += 1
    end
  end

  describe 'call' do
    context 'when server is not yet reachable' do
      it 'retry until server is reachable' do
        config.stub(:ssh_timeout) { 2 }
        expect(app).to receive(:call)

        @action = WaitForServerToBeAccessible.new(app, nil, resolver, SSHMock.new(1, 0))
        @action.call(env)
      end
    end
    context 'when server is not yet reachable after timeout' do
      it 'raise an error' do
        config.stub(:ssh_timeout) { 1 }
        expect(app).should_not_receive(:call)

        @action = WaitForServerToBeAccessible.new(app, nil, resolver, SSHMock.new(1, 1))
        expect { @action.call(env) }.to raise_error Errors::SshUnavailable
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-deltacloud-provider-0.0.9 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.8 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.7 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.6 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.5 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.4 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.3 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb
vagrant-deltacloud-provider-0.0.2 spec/vagrant-deltacloud-provider/action/wait_accessible_spec.rb