File: concat_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-concat 7.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 532 kB
  • sloc: ruby: 2,584; sh: 46; makefile: 2
file content (173 lines) | stat: -rw-r--r-- 4,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# frozen_string_literal: true

require 'spec_helper_acceptance'

case os[:family]
when 'aix'
  username = 'root'
  groupname = 'system'
when 'darwin'
  username = 'root'
  groupname = 'wheel'
when 'windows'
  username = 'Administrator'
  groupname = 'Administrators'
else
  username = 'root'
  groupname = 'root'
end

describe 'basic concat test' do
  attr_reader :basedir

  before(:all) do
    @basedir = setup_test_directory
  end

  describe 'with owner/group root' do
    let(:pp) do
      <<-MANIFEST
        concat { '#{basedir}/file':
          owner => '#{username}',
          group => '#{groupname}',
          mode  => '0644',
        }

        concat::fragment { '1':
          target  => '#{basedir}/file',
          content => '1',
          order   => '01',
        }

        concat::fragment { '2':
          target  => '#{basedir}/file',
          content => '2',
          order   => '02',
        }
      MANIFEST
    end

    it 'idempotent, file matches' do
      idempotent_apply(pp)
      expect(file("#{basedir}/file")).to be_file
      expect(file("#{basedir}/file")).to be_owned_by username unless os[:family] == 'windows'
      expect(file("#{basedir}/file")).to be_grouped_into groupname unless os[:family] == 'windows' || os[:family] == 'darwin'
      expect(file("#{basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
      expect(file("#{basedir}/file").content).to match '1'
      expect(file("#{basedir}/file").content).to match '2'
    end
  end

  describe 'when present with path set' do
    let(:pp) do
      <<-MANIFEST
        concat { 'file':
          ensure => present,
          path   => '#{basedir}/file',
          mode   => '0644',
        }
        concat::fragment { '1':
          target  => 'file',
          content => '1',
          order   => '01',
        }
      MANIFEST
    end

    it 'idempotent, file matches' do
      idempotent_apply(pp)
      expect(file("#{basedir}/file")).to be_file
      expect(file("#{basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
      expect(file("#{basedir}/file").content).to match '1'
    end
  end

  describe 'with no fragments declared' do
    let(:pp) do
      <<-MANIFEST
        concat { 'file':
          ensure => present,
          path   => '#{basedir}/file',
          mode   => '0644',
        }
      MANIFEST
    end

    it 'applies manifest twice with no stderr' do
      idempotent_apply(pp)
      expect(file("#{basedir}/file")).to be_file
      expect(file("#{basedir}/file").content).to eq ''
    end
  end

  describe 'when absent with path set' do
    let(:pp) do
      <<-MANIFEST
        concat { 'file':
          ensure => absent,
          path   => '#{basedir}/file',
          mode   => '0644',
        }
        concat::fragment { '1':
          target  => 'file',
          content => '1',
          order   => '01',
        }
      MANIFEST
    end

    it 'applies the manifest twice with no stderr' do
      idempotent_apply(pp)
      expect(file("#{basedir}/file")).not_to be_file
    end
  end

  describe 'when present with path that has special characters' do
    filename = (os[:family] == 'windows') ? 'file(1)' : 'file(1:2)'

    let(:pp) do
      <<-MANIFEST
        concat { '#{filename}':
          ensure => present,
          path   => '#{basedir}/#{filename}',
          mode   => '0644',
        }
        concat::fragment { '1':
          target  => '#{filename}',
          content => '1',
          order   => '01',
        }
      MANIFEST
    end

    it 'idempotent, file matches' do
      idempotent_apply(pp)
      expect(file("#{basedir}/#{filename}")).to be_file
      expect(file("#{basedir}/#{filename}")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
      expect(file("#{basedir}/#{filename}").content).to match '1'
    end
  end

  describe 'with noop properly' do
    let(:pp) do
      <<-MANIFEST
        concat { 'file':
          ensure => present,
          path   => '#{basedir}/file',
          mode   => '0644',
          noop   => true,
        }
        concat::fragment { '1':
          target  => 'file',
          content => '1',
          order   => '01',
        }
      MANIFEST
    end

    it 'applies manifest twice with no stderr' do
      idempotent_apply(pp)
      expect(file("#{basedir}/file")).not_to be_file
    end
  end
end