Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / spec / defines / config_spec.rb @ 20eaf3c2

Historique | Voir | Annoter | Télécharger (3,55 ko)

1 30462da1 Steve Traylen
require 'spec_helper'
2
3
describe 'nftables::config' do
4
  let(:pre_condition) { 'include nftables' }
5
6
  on_supported_os.each do |os, facts|
7
    context "on #{os}" do
8
      let(:title) { 'FOO-BAR' }
9
      let(:facts) do
10
        facts
11
      end
12
13
      context 'with source and content both unset' do
14 fcb1d356 Nacho Barrientos
        it { is_expected.to compile }
15
        it { is_expected.to contain_concat('nftables-FOO-BAR') }
16
        it {
17
          is_expected.to contain_concat('nftables-FOO-BAR').with(
18 948ebc98 Nacho Barrientos
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
19 fcb1d356 Nacho Barrientos
            ensure_newline: true,
20 fa92e118 Romain Tartière
            mode: '0640'
21 fcb1d356 Nacho Barrientos
          )
22
        }
23 948ebc98 Nacho Barrientos
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
24 fcb1d356 Nacho Barrientos
        it {
25 948ebc98 Nacho Barrientos
          is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
26 fcb1d356 Nacho Barrientos
            ensure: 'file',
27 948ebc98 Nacho Barrientos
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
28 fa92e118 Romain Tartière
            mode: '0640'
29 fcb1d356 Nacho Barrientos
          )
30
        }
31
        it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
32
        it {
33
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-header').with(
34
            target: 'nftables-FOO-BAR',
35
            order: '00',
36 fa92e118 Romain Tartière
            content: 'table FOO BAR {'
37 fcb1d356 Nacho Barrientos
          )
38
        }
39
        it {
40
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
41
            target: 'nftables-FOO-BAR',
42
            order: '98',
43 fa92e118 Romain Tartière
            content: '  include "FOO-BAR-chain-*.nft"'
44 fcb1d356 Nacho Barrientos
          )
45
        }
46 30462da1 Steve Traylen
      end
47
48
      context 'with a non hyphenated title' do
49
        let(:title) { 'STRING' }
50
51
        it { is_expected.not_to compile }
52
      end
53
54
      context 'with source and content both set' do
55
        let(:params) do
56
          {
57
            source: 'foo',
58
            content: 'puppet:///modules/foo/bar',
59
          }
60
        end
61
62
        it {
63
          is_expected.not_to compile
64
        }
65
      end
66
      context 'with content set' do
67
        let(:params) do
68
          {
69
            content: 'strange content',
70
          }
71
        end
72
73
        it { is_expected.to compile }
74
        it { is_expected.to contain_concat('nftables-FOO-BAR') }
75
        it {
76
          is_expected.to contain_concat('nftables-FOO-BAR').with(
77 948ebc98 Nacho Barrientos
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
78 30462da1 Steve Traylen
            ensure_newline: true,
79 fa92e118 Romain Tartière
            mode: '0640'
80 30462da1 Steve Traylen
          )
81
        }
82 948ebc98 Nacho Barrientos
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
83 30462da1 Steve Traylen
        it {
84 948ebc98 Nacho Barrientos
          is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
85 30462da1 Steve Traylen
            ensure: 'file',
86 948ebc98 Nacho Barrientos
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
87 fa92e118 Romain Tartière
            mode: '0640'
88 30462da1 Steve Traylen
          )
89
        }
90
        it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
91
        it {
92
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-header').with(
93
            target: 'nftables-FOO-BAR',
94
            order: '00',
95 fa92e118 Romain Tartière
            content: 'table FOO BAR {'
96 30462da1 Steve Traylen
          )
97
        }
98
        it {
99
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
100
            target: 'nftables-FOO-BAR',
101
            order: '98',
102 fa92e118 Romain Tartière
            content: 'strange content'
103 30462da1 Steve Traylen
          )
104
        }
105
      end
106 04f5c035 Nacho Barrientos
      context 'with source set' do
107 30462da1 Steve Traylen
        let(:params) do
108
          {
109
            source: 'puppet:///modules/foo',
110
          }
111
        end
112
113
        it {
114
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
115
            target: 'nftables-FOO-BAR',
116
            order: '98',
117 fa92e118 Romain Tartière
            source: 'puppet:///modules/foo'
118 30462da1 Steve Traylen
          )
119
        }
120
      end
121
    end
122
  end
123
end