spec/vra_spec.rb in kitchen-vra-1.0.0 vs spec/vra_spec.rb in kitchen-vra-1.1.0

- old
+ new

@@ -39,11 +39,12 @@ cpus: 2, memory: 2048, requested_for: 'override_user@corp.local', notes: 'some notes', subtenant_id: '160b473a-0ec9-473d-8156-28dd96c0b6b7', - lease_days: 5 + lease_days: 5, + use_dns: false } end let(:instance) do instance_double(Kitchen::Instance, @@ -100,19 +101,27 @@ it 'sets the server ID in the state hash' do driver.create(state) expect(state[:resource_id]).to eq('e8706351-cf4c-4c12-acb7-c90cc683b22c') end - describe 'getting the IP address from the server' do - context 'when no IP addresses are returned' do - it 'raises an exception' do - allow(resource).to receive(:ip_addresses).and_return([]) + describe 'setting the hostname in the state hash' do + context 'when use_dns is true' do + let(:config) { { use_dns: true } } + it 'raises an exception if the server name is nil' do + allow(resource).to receive(:name).and_return(nil) expect { driver.create(state) }.to raise_error(RuntimeError) end + it 'uses the server name as the hostname' do + driver.create(state) + expect(state[:hostname]).to eq('server1') + end end - - context 'when IP addresses are returned' do - it 'sets the IP address as the hostname in the state hash' do + context 'when use_dns is false' do + it 'raises an exception if no IP address is available' do + allow(resource).to receive(:ip_addresses).and_return([]) + expect { driver.create(state) }.to raise_error(RuntimeError) + end + it 'uses the IP address as the hostname' do driver.create(state) expect(state[:hostname]).to eq('1.2.3.4') end end end