|
| 1 | +# encoding: UTF-8 |
| 2 | +# |
| 3 | +# Author:: Xabier de Zuazo (<[email protected]>) |
| 4 | +# Copyright:: Copyright (c) 2016 Xabier de Zuazo |
| 5 | +# License:: Apache License, Version 2.0 |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +require_relative '../spec_helper' |
| 21 | +require 'attribute_helpers' |
| 22 | + |
| 23 | +describe Chef::SslCertificateCookbook::AttributeHelpers, order: :random do |
| 24 | + let(:helpers) { described_class } |
| 25 | + let(:resolv_dns_config) { instance_double('Resolv::DNS::Config') } |
| 26 | + let(:nameserver_port) { [%w(1.2.3.4 53)] } |
| 27 | + |
| 28 | + context '.resolvers' do |
| 29 | + before do |
| 30 | + expect(Resolv::DNS::Config).to receive(:new) |
| 31 | + .and_return(resolv_dns_config) |
| 32 | + allow(resolv_dns_config).to receive(:lazy_initialize) |
| 33 | + .and_return(resolv_dns_config) |
| 34 | + allow(resolv_dns_config).to receive(:nameserver_port) |
| 35 | + .and_return(nameserver_port) |
| 36 | + end |
| 37 | + |
| 38 | + it 'returns the DNS resolver as a string' do |
| 39 | + expect(helpers.resolvers).to eq('1.2.3.4:53') |
| 40 | + end |
| 41 | + |
| 42 | + context 'with multiple DNS resolvers' do |
| 43 | + let(:nameserver_port) { [%w(1.2.3.4 53), %w(5.6.7.8 5353)] } |
| 44 | + |
| 45 | + it 'returns all DNS resolvers' do |
| 46 | + expect(helpers.resolvers).to eq('1.2.3.4:53 5.6.7.8:5353') |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context 'without DNS resolvers' do |
| 51 | + let(:nameserver_port) { [['0.0.0.0', 53]] } # tested on GNU/Linux |
| 52 | + |
| 53 | + it 'returns nil' do |
| 54 | + expect(helpers.resolvers).to eq(nil) |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments