Projet

Général

Profil

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

root / spec / defines / config_spec.rb @ fa92e118

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

1
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
        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
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
19
            ensure_newline: true,
20
            mode: '0640'
21
          )
22
        }
23
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
24
        it {
25
          is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
26
            ensure: 'file',
27
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
28
            mode: '0640'
29
          )
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
            content: 'table FOO BAR {'
37
          )
38
        }
39
        it {
40
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
41
            target: 'nftables-FOO-BAR',
42
            order: '98',
43
            content: '  include "FOO-BAR-chain-*.nft"'
44
          )
45
        }
46
      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
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
78
            ensure_newline: true,
79
            mode: '0640'
80
          )
81
        }
82
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
83
        it {
84
          is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
85
            ensure: 'file',
86
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
87
            mode: '0640'
88
          )
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
            content: 'table FOO BAR {'
96
          )
97
        }
98
        it {
99
          is_expected.to contain_concat_fragment('nftables-FOO-BAR-body').with(
100
            target: 'nftables-FOO-BAR',
101
            order: '98',
102
            content: 'strange content'
103
          )
104
        }
105
      end
106
      context 'with source set' do
107
        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
            source: 'puppet:///modules/foo'
118
          )
119
        }
120
      end
121
    end
122
  end
123
end