Sha256: 1c8ef7605981d38f683b098ba578354d5e0e38df73463edf48f0b58472b4151f

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

require 'vagrant-deltacloud-provider/spec_helper'

describe VagrantPlugins::Deltacloud::Action::ReadState do

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

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

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

  describe 'call' do
    context 'when server id is present' do
      it 'set the state to the one returned by deltacloud' do
        env[:machine].id = 'server_id'
        deltacloud.stub(:get_instance_details).and_return('status' => 'RUNNING')

        expect(deltacloud).to receive(:get_instance_details).with(env, 'server_id')
        expect(app).to receive(:call)

        @action = ReadState.new(app, nil)
        @action.call(env)

        expect(env[:machine_state_id]).to eq(:active)
      end
    end
    context 'when server id is not present' do
      it 'set the state to :not_created' do
        env[:machine].id = nil
        expect(deltacloud).to_not receive(:get_instance_details)
        expect(app).to receive(:call)

        @action = ReadState.new(app, nil)
        @action.call(env)

        expect(env[:machine_state_id]).to eq(:not_created)
      end
    end
    context 'when server cannot be found' do
      it 'set the state to :not_created' do
        env[:machine].id = 'server_id'
        deltacloud.stub(:get_instance_details).and_return(nil)

        expect(deltacloud).to receive(:get_instance_details).with(env, 'server_id')
        expect(app).to receive(:call)

        @action = ReadState.new(app, nil)
        @action.call(env)

        expect(env[:machine_state_id]).to eq(:not_created)
      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/read_state_spec.rb
vagrant-deltacloud-provider-0.0.8 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.7 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.6 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.5 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.4 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.3 spec/vagrant-deltacloud-provider/action/read_state_spec.rb
vagrant-deltacloud-provider-0.0.2 spec/vagrant-deltacloud-provider/action/read_state_spec.rb