1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# frozen_string_literal: true
require 'spec_helper'
require 'puppet/util/network_device/simple/device'
RSpec.describe Puppet::Util::NetworkDevice::Simple::Device do
subject(:device) { described_class.new(url_or_config) }
context 'when initialized with a file:// URL' do
context 'when the file exists' do
let(:tempfile) { Tempfile.new('foo.txt') }
let(:url_or_config) { 'file://' + tempfile.path }
before(:each) do
tempfile.write('{ foo: bar }')
tempfile.close
end
after(:each) { tempfile.unlink }
it 'provides an empty facts set' do
expect(device.facts).to eq({})
end
it 'makes the configured configuration available' do
expect(device.config).to eq('foo' => 'bar')
end
end
context 'when the file does not exist' do
let(:url_or_config) { 'file:///tmp/foo.txt' }
it 'raises an error' do
expect { device.config }.to raise_error RuntimeError, %r{foo\.txt.*file does not exist}
end
end
end
context 'when initialized with a non-file:// URL' do
let(:url_or_config) { 'http://example.com/' }
it 'raises an error' do
expect { device }.to raise_error RuntimeError, %r{example.com.*Only file:/// URLs for configuration supported}
end
end
context 'when initialized with a config hash' do
let(:url_or_config) { { key: :value } }
it 'makes the configured configuration available' do
expect(device.config).to eq(key: :value)
end
end
end
|