root / spec / defines / config_spec.rb @ 194e05d5
Historique | Voir | Annoter | Télécharger (3,63 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 | context 'with source and content both unset' do |
||
16 | fcb1d356 | Nacho Barrientos | it { is_expected.to compile } |
17 | it { is_expected.to contain_concat('nftables-FOO-BAR') }
|
||
18 | c82b960a | Steve Traylen | |
19 | fcb1d356 | Nacho Barrientos | it { |
20 | c82b960a | Steve Traylen | expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
21 | 948ebc98 | Nacho Barrientos | path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
22 | fcb1d356 | Nacho Barrientos | ensure_newline: true, |
23 | fa92e118 | Romain Tartière | mode: '0640' |
24 | fcb1d356 | Nacho Barrientos | ) |
25 | } |
||
26 | c82b960a | Steve Traylen | |
27 | 948ebc98 | Nacho Barrientos | it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
28 | c82b960a | Steve Traylen | |
29 | fcb1d356 | Nacho Barrientos | it { |
30 | c82b960a | Steve Traylen | expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
31 | fcb1d356 | Nacho Barrientos | ensure: 'file', |
32 | 948ebc98 | Nacho Barrientos | source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
33 | fa92e118 | Romain Tartière | mode: '0640' |
34 | fcb1d356 | Nacho Barrientos | ) |
35 | } |
||
36 | c82b960a | Steve Traylen | |
37 | fcb1d356 | Nacho Barrientos | it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
38 | c82b960a | Steve Traylen | |
39 | fcb1d356 | Nacho Barrientos | it { |
40 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
41 | fcb1d356 | Nacho Barrientos | target: 'nftables-FOO-BAR', |
42 | order: '00', |
||
43 | fa92e118 | Romain Tartière | content: 'table FOO BAR {' |
44 | fcb1d356 | Nacho Barrientos | ) |
45 | } |
||
46 | c82b960a | Steve Traylen | |
47 | fcb1d356 | Nacho Barrientos | it { |
48 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
49 | fcb1d356 | Nacho Barrientos | target: 'nftables-FOO-BAR', |
50 | order: '98', |
||
51 | fa92e118 | Romain Tartière | content: ' include "FOO-BAR-chain-*.nft"' |
52 | fcb1d356 | Nacho Barrientos | ) |
53 | } |
||
54 | 30462da1 | Steve Traylen | end
|
55 | |||
56 | context 'with a non hyphenated title' do |
||
57 | let(:title) { 'STRING' } |
||
58 | |||
59 | it { is_expected.not_to compile } |
||
60 | end
|
||
61 | |||
62 | context 'with source and content both set' do |
||
63 | let(:params) do |
||
64 | { |
||
65 | source: 'foo', |
||
66 | content: 'puppet:///modules/foo/bar', |
||
67 | } |
||
68 | end
|
||
69 | |||
70 | it { |
||
71 | c82b960a | Steve Traylen | expect(subject).not_to compile |
72 | 30462da1 | Steve Traylen | } |
73 | end
|
||
74 | c82b960a | Steve Traylen | |
75 | 30462da1 | Steve Traylen | context 'with content set' do |
76 | let(:params) do |
||
77 | { |
||
78 | content: 'strange content', |
||
79 | } |
||
80 | end
|
||
81 | |||
82 | it { is_expected.to compile } |
||
83 | it { is_expected.to contain_concat('nftables-FOO-BAR') }
|
||
84 | c82b960a | Steve Traylen | |
85 | 30462da1 | Steve Traylen | it { |
86 | c82b960a | Steve Traylen | expect(subject).to contain_concat('nftables-FOO-BAR').with(
|
87 | 948ebc98 | Nacho Barrientos | path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
88 | 30462da1 | Steve Traylen | ensure_newline: true, |
89 | fa92e118 | Romain Tartière | mode: '0640' |
90 | 30462da1 | Steve Traylen | ) |
91 | } |
||
92 | c82b960a | Steve Traylen | |
93 | 948ebc98 | Nacho Barrientos | it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
|
94 | c82b960a | Steve Traylen | |
95 | 30462da1 | Steve Traylen | it { |
96 | c82b960a | Steve Traylen | expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
|
97 | 30462da1 | Steve Traylen | ensure: 'file', |
98 | 948ebc98 | Nacho Barrientos | source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft', |
99 | fa92e118 | Romain Tartière | mode: '0640' |
100 | 30462da1 | Steve Traylen | ) |
101 | } |
||
102 | c82b960a | Steve Traylen | |
103 | 30462da1 | Steve Traylen | it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
|
104 | c82b960a | Steve Traylen | |
105 | 30462da1 | Steve Traylen | it { |
106 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
|
107 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
108 | order: '00', |
||
109 | fa92e118 | Romain Tartière | content: 'table FOO BAR {' |
110 | 30462da1 | Steve Traylen | ) |
111 | } |
||
112 | c82b960a | Steve Traylen | |
113 | 30462da1 | Steve Traylen | it { |
114 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
115 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
116 | order: '98', |
||
117 | fa92e118 | Romain Tartière | content: 'strange content' |
118 | 30462da1 | Steve Traylen | ) |
119 | } |
||
120 | end
|
||
121 | c82b960a | Steve Traylen | |
122 | 04f5c035 | Nacho Barrientos | context 'with source set' do |
123 | 30462da1 | Steve Traylen | let(:params) do |
124 | { |
||
125 | source: 'puppet:///modules/foo', |
||
126 | } |
||
127 | end
|
||
128 | |||
129 | it { |
||
130 | c82b960a | Steve Traylen | expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
|
131 | 30462da1 | Steve Traylen | target: 'nftables-FOO-BAR', |
132 | order: '98', |
||
133 | fa92e118 | Romain Tartière | source: 'puppet:///modules/foo' |
134 | 30462da1 | Steve Traylen | ) |
135 | } |
||
136 | end
|
||
137 | end
|
||
138 | end
|
||
139 | end |