Sha256: 987ef276d881d53b1159c4c503fa21721ba6d919775253e6a2c673a9e7c26cf5

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'
require 'vagrant-openstack-cloud-provider/errors'
require 'vagrant-openstack-cloud-provider/action/connect_openstack'
require "fog"

RSpec.describe VagrantPlugins::OpenStack::Action::ConnectOpenStack do
  describe '#call?' do
    let (:app) { double }
    let (:machine) { double }
    let (:config) { double(
        :config,
        :region    => nil,
        :username  => 'username',
        :api_key   => 'password',
        :endpoint  => 'http://openstack.invalid/',
        :tenant    => nil,
      )
    }

    subject {
      described_class.new(app, nil)
    }

    after(:each) {
      $openstack_compute = nil
      $openstack_network = nil
    }

    it "should new members in env" do
      expect(app).to receive(:call)
      expect(machine).to receive(:provider_config).and_return(config)
      env = { :machine => machine }

      subject.call(env)

      expect(env).to have_key(:openstack_compute)
      expect(env).to have_key(:openstack_network)
    end

    {Fog::Compute => :openstack_compute,
     Fog::Network => :openstack_network}.each do |klass, attribute|
      it "should late-evaluate #{klass}" do
        expect(app).to receive(:call)
        expect(machine).to receive(:provider_config).and_return(config)
        env = { :machine => machine }

        expect(klass).to receive(:new).and_raise(MyError)

        subject.call(env)

        expect { env[attribute].any_call }.to raise_error(MyError)
      end
    end

    it "should memoize the fog call" do
      expect(app).to receive(:call).at_least(:once)
      expect(machine).to receive(:provider_config).at_least(:once).and_return(config)
      env = { :machine => machine }

      expect(Kernel).to receive(:promise).twice.and_return('TEST') # 1x compute, 1x network
      10.times { subject.call(env) }
    end
  end
end

class MyError < StandardError

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-openstack-cloud-provider-1.1.13 spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb
vagrant-openstack-cloud-provider-1.1.12 spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb
vagrant-openstack-cloud-provider-1.1.11 spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb
vagrant-openstack-cloud-provider-1.1.10 spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb