Sha256: b8428a0128d96bbe5eab0692a05c6df08e28619c54074d481c3bda06d7c4de36

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'
require 'vagrant-cloudstack/model/cloudstack_resource'
require 'vagrant-cloudstack/service/cloudstack_resource_service'

include VagrantPlugins::Cloudstack::Model
include VagrantPlugins::Cloudstack::Service

describe CloudstackResourceService do
  let(:cloudstack_compute) { double('Fog::Compute::Cloudstack') }
  let(:ui) { double('Vagrant::UI') }
  let(:service) { CloudstackResourceService.new(cloudstack_compute, ui) }

  before do
    response = {
      'listkindsresponse' => {
        'kind' => [{ 'id' => 'resource id', 'name' => 'resource name' }]
      }
    }
    allow(cloudstack_compute).to receive(:send).with(:list_kinds, { 'id' => 'resource id' }).and_return(response)
    allow(cloudstack_compute).to receive(:send).with(:list_kinds, {}).and_return(response)

    allow(ui).to receive(:detail)
    allow(ui).to receive(:info)
  end

  describe '#sync_resource' do
    it 'retrives the missing name' do
      resource = CloudstackResource.new('resource id', nil, 'kind')
      service.sync_resource(resource)

      expect(resource.name).to be_eql 'resource name'
      expect(resource.id).to be_eql 'resource id'
    end

    it 'retrives the missing id' do
      resource = CloudstackResource.new(nil, 'resource name', 'kind')
      service.sync_resource(resource)

      expect(resource.id).to be_eql 'resource id'
      expect(resource.name).to be_eql 'resource name'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-cloudstack-1.5.2 spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb
vagrant-cloudstack-1.5.1 spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb
vagrant-cloudstack-1.5.0 spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb
vagrant-cloudstack-1.4.0 spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb