root / spec / defines / config_spec.rb @ 9d02e9f8
Historique | Voir | Annoter | Télécharger (3,81 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables::config' do |
6 |
let(:pre_condition) { 'include nftables' } |
7 |
|
8 |
on_supported_os.each do |os, facts|
|
9 |
context "on #{os}" do |
10 |
let(:title) { 'FOO-BAR' } |
11 |
let(:facts) do |
12 |
facts |
13 |
end
|
14 |
|
15 |
nft_mode = case facts[:os]['family'] |
16 |
when 'RedHat' |
17 |
'0600'
|
18 |
else
|
19 |
'0640'
|
20 |
end
|
21 |
|
22 |
context 'with source and content both unset' do |
23 |
it { is_expected.to compile } |
24 |
it { is_expected.to contain_concat('nftables-FOO-BAR') }
|
25 |
|
26 |
it { |
27 |
expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
28 |
path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
29 |
ensure_newline: true, |
30 |
mode: nft_mode
|
31 |
) |
32 |
} |
33 |
|
34 |
it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
35 |
|
36 |
it { |
37 |
expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
38 |
ensure: 'file', |
39 |
source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
40 |
mode: nft_mode
|
41 |
) |
42 |
} |
43 |
|
44 |
it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
45 |
|
46 |
it { |
47 |
expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
48 |
target: 'nftables-FOO-BAR', |
49 |
order: '00', |
50 |
content: 'table FOO BAR {' |
51 |
) |
52 |
} |
53 |
|
54 |
it { |
55 |
expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
56 |
target: 'nftables-FOO-BAR', |
57 |
order: '98', |
58 |
content: ' include "FOO-BAR-chain-*.nft"' |
59 |
) |
60 |
} |
61 |
end
|
62 |
|
63 |
context 'with a non hyphenated title' do |
64 |
let(:title) { 'STRING' } |
65 |
|
66 |
it { is_expected.not_to compile } |
67 |
end
|
68 |
|
69 |
context 'with source and content both set' do |
70 |
let(:params) do |
71 |
{ |
72 |
source: 'foo', |
73 |
content: 'puppet:///modules/foo/bar', |
74 |
} |
75 |
end
|
76 |
|
77 |
it { |
78 |
expect(subject).not_to compile |
79 |
} |
80 |
end
|
81 |
|
82 |
context 'with content set' do |
83 |
let(:params) do |
84 |
{ |
85 |
content: 'strange content', |
86 |
} |
87 |
end
|
88 |
|
89 |
it { is_expected.to compile } |
90 |
it { is_expected.to contain_concat('nftables-FOO-BAR') }
|
91 |
|
92 |
it { |
93 |
expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
94 |
path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
95 |
ensure_newline: true, |
96 |
mode: nft_mode
|
97 |
) |
98 |
} |
99 |
|
100 |
it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
101 |
|
102 |
it { |
103 |
expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
104 |
ensure: 'file', |
105 |
source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
106 |
mode: nft_mode
|
107 |
) |
108 |
} |
109 |
|
110 |
it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
111 |
|
112 |
it { |
113 |
expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
114 |
target: 'nftables-FOO-BAR', |
115 |
order: '00', |
116 |
content: 'table FOO BAR {' |
117 |
) |
118 |
} |
119 |
|
120 |
it { |
121 |
expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
122 |
target: 'nftables-FOO-BAR', |
123 |
order: '98', |
124 |
content: 'strange content' |
125 |
) |
126 |
} |
127 |
end
|
128 |
|
129 |
context 'with source set' do |
130 |
let(:params) do |
131 |
{ |
132 |
source: 'puppet:///modules/foo', |
133 |
} |
134 |
end
|
135 |
|
136 |
it { |
137 |
expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
138 |
target: 'nftables-FOO-BAR', |
139 |
order: '98', |
140 |
source: 'puppet:///modules/foo' |
141 |
) |
142 |
} |
143 |
end
|
144 |
end
|
145 |
end
|
146 |
end
|