root / spec / defines / config_spec.rb @ 3e2b5119
Historique | Voir | Annoter | Télécharger (3,81 ko)
1 | c82b960a | Steve Traylen | # frozen_string_literal: true
|
---|---|---|---|
2 | |||
3 | 30462da1 | Steve Traylen | 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 | 0b7bcb5d | mh | nft_mode = case facts[:os]['family'] |
16 | when 'RedHat' |
||
17 | '0600'
|
||
18 | else
|
||
19 | '0640'
|
||
20 | end
|
||
21 | |||
22 | 30462da1 | Steve Traylen | context 'with source and content both unset' do |
23 | fcb1d356 | Nacho Barrientos | it { is_expected.to compile } |
24 | it { is_expected.to contain_concat('nftables-FOO-BAR') }
|
||
25 | c82b960a | Steve Traylen | |
26 | fcb1d356 | Nacho Barrientos | it { |
27 | c82b960a | Steve Traylen | expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
28 | 948ebc98 | Nacho Barrientos | path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
29 | fcb1d356 | Nacho Barrientos | ensure_newline: true, |
30 | 0b7bcb5d | mh | mode: nft_mode
|
31 | fcb1d356 | Nacho Barrientos | ) |
32 | } |
||
33 | c82b960a | Steve Traylen | |
34 | 948ebc98 | Nacho Barrientos | it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
35 | c82b960a | Steve Traylen | |
36 | fcb1d356 | Nacho Barrientos | it { |
37 | c82b960a | Steve Traylen | expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
38 | fcb1d356 | Nacho Barrientos | ensure: 'file', |
39 | 948ebc98 | Nacho Barrientos | source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
40 | 0b7bcb5d | mh | mode: nft_mode
|
41 | fcb1d356 | Nacho Barrientos | ) |
42 | } |
||
43 | c82b960a | Steve Traylen | |
44 | fcb1d356 | Nacho Barrientos | it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
45 | c82b960a | Steve Traylen | |
46 | fcb1d356 | Nacho Barrientos | it { |
47 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
48 | fcb1d356 | Nacho Barrientos | target: 'nftables-FOO-BAR', |
49 | order: '00', |
||
50 | fa92e118 | Romain Tartière | content: 'table FOO BAR {' |
51 | fcb1d356 | Nacho Barrientos | ) |
52 | } |
||
53 | c82b960a | Steve Traylen | |
54 | fcb1d356 | Nacho Barrientos | it { |
55 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
56 | fcb1d356 | Nacho Barrientos | target: 'nftables-FOO-BAR', |
57 | order: '98', |
||
58 | fa92e118 | Romain Tartière | content: ' include "FOO-BAR-chain-*.nft"' |
59 | fcb1d356 | Nacho Barrientos | ) |
60 | } |
||
61 | 30462da1 | Steve Traylen | 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 | c82b960a | Steve Traylen | expect(subject).not_to compile |
79 | 30462da1 | Steve Traylen | } |
80 | end
|
||
81 | c82b960a | Steve Traylen | |
82 | 30462da1 | Steve Traylen | 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 | c82b960a | Steve Traylen | |
92 | 30462da1 | Steve Traylen | it { |
93 | c82b960a | Steve Traylen | expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
94 | 948ebc98 | Nacho Barrientos | path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
95 | 30462da1 | Steve Traylen | ensure_newline: true, |
96 | 0b7bcb5d | mh | mode: nft_mode
|
97 | 30462da1 | Steve Traylen | ) |
98 | } |
||
99 | c82b960a | Steve Traylen | |
100 | 948ebc98 | Nacho Barrientos | it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
101 | c82b960a | Steve Traylen | |
102 | 30462da1 | Steve Traylen | it { |
103 | c82b960a | Steve Traylen | expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
104 | 30462da1 | Steve Traylen | ensure: 'file', |
105 | 948ebc98 | Nacho Barrientos | source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
106 | 0b7bcb5d | mh | mode: nft_mode
|
107 | 30462da1 | Steve Traylen | ) |
108 | } |
||
109 | c82b960a | Steve Traylen | |
110 | 30462da1 | Steve Traylen | it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
111 | c82b960a | Steve Traylen | |
112 | 30462da1 | Steve Traylen | it { |
113 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
114 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
115 | order: '00', |
||
116 | fa92e118 | Romain Tartière | content: 'table FOO BAR {' |
117 | 30462da1 | Steve Traylen | ) |
118 | } |
||
119 | c82b960a | Steve Traylen | |
120 | 30462da1 | Steve Traylen | it { |
121 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
122 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
123 | order: '98', |
||
124 | fa92e118 | Romain Tartière | content: 'strange content' |
125 | 30462da1 | Steve Traylen | ) |
126 | } |
||
127 | end
|
||
128 | c82b960a | Steve Traylen | |
129 | 04f5c035 | Nacho Barrientos | context 'with source set' do |
130 | 30462da1 | Steve Traylen | let(:params) do |
131 | { |
||
132 | source: 'puppet:///modules/foo', |
||
133 | } |
||
134 | end
|
||
135 | |||
136 | it { |
||
137 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
138 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
139 | order: '98', |
||
140 | fa92e118 | Romain Tartière | source: 'puppet:///modules/foo' |
141 | 30462da1 | Steve Traylen | ) |
142 | } |
||
143 | end
|
||
144 | end
|
||
145 | end
|
||
146 | end |