| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require 'spec_helper' |
| 4 |
|
| 5 |
describe 'haproxy::resolver' do |
| 6 |
let(:pre_condition) { 'include haproxy' } |
| 7 |
let(:facts) do |
| 8 |
{ |
| 9 |
networking: { |
| 10 |
ip: '1.1.1.1' |
| 11 |
}, |
| 12 |
concat_basedir: '/dne', |
| 13 |
os: { |
| 14 |
family: 'RedHat' |
| 15 |
} |
| 16 |
} |
| 17 |
end |
| 18 |
|
| 19 |
context 'with two resolvers' do |
| 20 |
let(:title) { 'bar' } |
| 21 |
let(:params) do |
| 22 |
{ |
| 23 |
nameservers: { 'dns1' => '1.1.1.1:53', 'dns2' => '1.1.1.2:53' }, |
| 24 |
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' }, |
| 25 |
resolve_retries: 3, |
| 26 |
timeout: { 'retry' => '1s' } |
| 27 |
} |
| 28 |
end |
| 29 |
|
| 30 |
it { |
| 31 |
is_expected.to contain_concat__fragment('haproxy-bar_resolver_block').with( |
| 32 |
'order' => '20-bar-01', |
| 33 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 34 |
'content' => "\nresolvers bar\n nameserver dns1 1.1.1.1:53\n nameserver dns2 1.1.1.2:53\n resolve_retries 3\n timeout retry 1s\n hold other 30s\n hold refused 30s\n hold nx 30s\n hold timeout 30s\n hold valid 10s\n", # rubocop:disable Layout/LineLength |
| 35 |
) |
| 36 |
} |
| 37 |
end |
| 38 |
|
| 39 |
context 'with parse_resolv_conf' do |
| 40 |
let(:title) { 'bar' } |
| 41 |
let(:params) do |
| 42 |
{ |
| 43 |
parse_resolv_conf: true, |
| 44 |
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' }, |
| 45 |
resolve_retries: 3, |
| 46 |
timeout: { 'retry' => '1s' } |
| 47 |
} |
| 48 |
end |
| 49 |
|
| 50 |
it { |
| 51 |
is_expected.to contain_concat__fragment('haproxy-bar_resolver_block').with( |
| 52 |
'order' => '20-bar-01', |
| 53 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 54 |
'content' => "\nresolvers bar\n parse-resolv-conf\n resolve_retries 3\n timeout retry 1s\n hold other 30s\n hold refused 30s\n hold nx 30s\n hold timeout 30s\n hold valid 10s\n", |
| 55 |
) |
| 56 |
} |
| 57 |
end |
| 58 |
|
| 59 |
context 'with accepted_payload_size within range' do |
| 60 |
let(:title) { 'bar' } |
| 61 |
let(:params) do |
| 62 |
{ |
| 63 |
nameservers: { 'dns1' => '1.1.1.1:53', 'dns2' => '1.1.1.2:53' }, |
| 64 |
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' }, |
| 65 |
resolve_retries: 3, |
| 66 |
timeout: { 'retry' => '1s' }, |
| 67 |
accepted_payload_size: 512 |
| 68 |
} |
| 69 |
end |
| 70 |
|
| 71 |
it { |
| 72 |
is_expected.to contain_concat__fragment('haproxy-bar_resolver_block').with( |
| 73 |
'order' => '20-bar-01', |
| 74 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 75 |
'content' => "\nresolvers bar\n nameserver dns1 1.1.1.1:53\n nameserver dns2 1.1.1.2:53\n resolve_retries 3\n timeout retry 1s\n hold other 30s\n hold refused 30s\n hold nx 30s\n hold timeout 30s\n hold valid 10s\n accepted_payload_size 512\n", # rubocop:disable Layout/LineLength |
| 76 |
) |
| 77 |
} |
| 78 |
end |
| 79 |
|
| 80 |
context 'with accepted_payload_size too small' do |
| 81 |
let(:title) { 'bar' } |
| 82 |
let(:params) do |
| 83 |
{ |
| 84 |
nameservers: { 'dns1' => '1.1.1.1:53', 'dns2' => '1.1.1.2:53' }, |
| 85 |
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' }, |
| 86 |
resolve_retries: 3, |
| 87 |
timeout: { 'retry' => '1s' }, |
| 88 |
accepted_payload_size: 511 |
| 89 |
} |
| 90 |
end |
| 91 |
|
| 92 |
it { is_expected.to compile.and_raise_error(%r{expects a value of type Undef or Integer\[512, 8192\]}) } |
| 93 |
end |
| 94 |
|
| 95 |
context 'with accepted_payload_size too large' do |
| 96 |
let(:title) { 'bar' } |
| 97 |
let(:params) do |
| 98 |
{ |
| 99 |
nameservers: { 'dns1' => '1.1.1.1:53', 'dns2' => '1.1.1.2:53' }, |
| 100 |
hold: { 'other' => '30s', 'refused' => '30s', 'nx' => '30s', 'timeout' => '30s', 'valid' => '10s' }, |
| 101 |
resolve_retries: 3, |
| 102 |
timeout: { 'retry' => '1s' }, |
| 103 |
accepted_payload_size: 8193 |
| 104 |
} |
| 105 |
end |
| 106 |
|
| 107 |
it { is_expected.to compile.and_raise_error(%r{expects a value of type Undef or Integer\[512, 8192\]}) } |
| 108 |
end |
| 109 |
end |