Sha256: eb39f3860147ca53900683c234504cca00c64d9d761533e950a07e453b5281fe

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe AutoNetwork::Pool do
  let(:ip_range) { '10.20.1.0/24' }
  let(:machine_a) do
    machine = double(
      :name => 'machine_a',
      :id   => 'some-uuid',
    )
    machine.stub_chain(:env, :root_path, :to_s).and_return('/some/Vagrantfile')

    machine
  end
  let(:machine_b) do
    machine = double(
      :name => 'machine_b',
      :id   => 'some-uuid',
    )
    machine.stub_chain(:env, :root_path, :to_s).and_return('/some/Vagrantfile')

    machine
  end

  subject { AutoNetwork::Pool.new(ip_range) }

  describe 'requesting an address for a machine' do

    it 'returns the next available address' do
      expect(subject.request(machine_a)).to eq('10.20.1.2')
    end

    it 'is idempotent' do
      subject.request(machine_a)
      expect(subject.request(machine_a)).to eq('10.20.1.2')
    end

    context 'when the pool is full' do
      subject { AutoNetwork::Pool.new('10.20.1.0/30') }

      it 'raises an error' do
        subject.request(machine_a)
        expect { subject.request(machine_b) }.to raise_error(AutoNetwork::Pool::PoolExhaustedError)
      end
    end

  end

  describe 'releasing an address from a machine' do

    it 'makes the address available' do
      subject.request(machine_a)
      subject.release(machine_a)
      expect(subject.request(machine_b)).to eq('10.20.1.2')
    end

  end

  describe 'looking up an address for a machine' do

    it 'returns the address assigned' do
      subject.request(machine_a)
      expect(subject.address_for(machine_a)).to eq('10.20.1.2')
    end

    it 'returns nil for unassigned machines' do
      expect(subject.address_for(machine_b)).to be_nil
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vagrant-auto_network-1.0.3 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.2 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.1 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.0 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.0.rc1 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.0.beta2 spec/unit/pool_spec.rb
vagrant-auto_network-1.0.0.beta1 spec/auto_network/pool/pool_spec.rb