Projet

Général

Profil

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

root / spec / defines / config_spec.rb @ c82b960a

Historique | Voir | Annoter | Télécharger (3,63 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
      context 'with source and content both unset' do
16
        it { is_expected.to compile }
17
        it { is_expected.to contain_concat('nftables-FOO-BAR') }
18

    
19
        it {
20
          expect(subject).to contain_concat('nftables-FOO-BAR').with(
21
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
22
            ensure_newline: true,
23
            mode: '0640'
24
          )
25
        }
26

    
27
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
28

    
29
        it {
30
          expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
31
            ensure: 'file',
32
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
33
            mode: '0640'
34
          )
35
        }
36

    
37
        it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
38

    
39
        it {
40
          expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
41
            target: 'nftables-FOO-BAR',
42
            order: '00',
43
            content: 'table FOO BAR {'
44
          )
45
        }
46

    
47
        it {
48
          expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
49
            target: 'nftables-FOO-BAR',
50
            order: '98',
51
            content: '  include "FOO-BAR-chain-*.nft"'
52
          )
53
        }
54
      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
          expect(subject).not_to compile
72
        }
73
      end
74

    
75
      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

    
85
        it {
86
          expect(subject).to contain_concat('nftables-FOO-BAR').with(
87
            path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
88
            ensure_newline: true,
89
            mode: '0640'
90
          )
91
        }
92

    
93
        it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
94

    
95
        it {
96
          expect(subject).to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
97
            ensure: 'file',
98
            source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
99
            mode: '0640'
100
          )
101
        }
102

    
103
        it { is_expected.to contain_concat_fragment('nftables-FOO-BAR-header') }
104

    
105
        it {
106
          expect(subject).to contain_concat_fragment('nftables-FOO-BAR-header').with(
107
            target: 'nftables-FOO-BAR',
108
            order: '00',
109
            content: 'table FOO BAR {'
110
          )
111
        }
112

    
113
        it {
114
          expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
115
            target: 'nftables-FOO-BAR',
116
            order: '98',
117
            content: 'strange content'
118
          )
119
        }
120
      end
121

    
122
      context 'with source set' do
123
        let(:params) do
124
          {
125
            source: 'puppet:///modules/foo',
126
          }
127
        end
128

    
129
        it {
130
          expect(subject).to contain_concat_fragment('nftables-FOO-BAR-body').with(
131
            target: 'nftables-FOO-BAR',
132
            order: '98',
133
            source: 'puppet:///modules/foo'
134
          )
135
        }
136
      end
137
    end
138
  end
139
end