~ubuntu-branches/ubuntu/vivid/puppet-module-puppetlabs-concat/vivid-proposed

« back to all changes in this revision

Viewing changes to spec/acceptance/replace_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-10-24 22:11:25 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141024221125-rqg7i2eo53afnz8d
Tags: 1.1.1-1
* Imported upstream relase 1.1.1
* Declare compliance with Debian policy 3.9.6
* Update debian/control metadata with cme (Vcs-*)
* Update dependencies
* Update file lists

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'spec_helper_acceptance'
 
2
 
 
3
describe 'replacement of' do
 
4
  basedir = default.tmpdir('concat')
 
5
  context 'file' do
 
6
    context 'should not succeed' do
 
7
      before(:all) do
 
8
        pp = <<-EOS
 
9
          file { '#{basedir}':
 
10
            ensure => directory,
 
11
          }
 
12
          file { '#{basedir}/file':
 
13
            content => "file exists\n"
 
14
          }
 
15
        EOS
 
16
        apply_manifest(pp)
 
17
      end
 
18
      pp = <<-EOS
 
19
        concat { '#{basedir}/file':
 
20
          replace => false,
 
21
        }
 
22
 
 
23
        concat::fragment { '1':
 
24
          target  => '#{basedir}/file',
 
25
          content => '1',
 
26
        }
 
27
 
 
28
        concat::fragment { '2':
 
29
          target  => '#{basedir}/file',
 
30
          content => '2',
 
31
        }
 
32
      EOS
 
33
 
 
34
      it 'applies the manifest twice with no stderr' do
 
35
        apply_manifest(pp, :catch_failures => true)
 
36
        apply_manifest(pp, :catch_changes => true)
 
37
      end
 
38
 
 
39
      describe file("#{basedir}/file") do
 
40
        it { should be_file }
 
41
        it { should contain 'file exists' }
 
42
        it { should_not contain '1' }
 
43
        it { should_not contain '2' }
 
44
      end
 
45
    end
 
46
 
 
47
    context 'should succeed' do
 
48
      before(:all) do
 
49
        pp = <<-EOS
 
50
          file { '#{basedir}':
 
51
            ensure => directory,
 
52
          }
 
53
          file { '#{basedir}/file':
 
54
            content => "file exists\n"
 
55
          }
 
56
        EOS
 
57
        apply_manifest(pp)
 
58
      end
 
59
      pp = <<-EOS
 
60
        concat { '#{basedir}/file':
 
61
          replace => true,
 
62
        }
 
63
 
 
64
        concat::fragment { '1':
 
65
          target  => '#{basedir}/file',
 
66
          content => '1',
 
67
        }
 
68
 
 
69
        concat::fragment { '2':
 
70
          target  => '#{basedir}/file',
 
71
          content => '2',
 
72
        }
 
73
      EOS
 
74
 
 
75
      it 'applies the manifest twice with no stderr' do
 
76
        apply_manifest(pp, :catch_failures => true)
 
77
        apply_manifest(pp, :catch_changes => true)
 
78
      end
 
79
 
 
80
      describe file("#{basedir}/file") do
 
81
        it { should be_file }
 
82
        it { should_not contain 'file exists' }
 
83
        it { should contain '1' }
 
84
        it { should contain '2' }
 
85
      end
 
86
    end
 
87
  end # file
 
88
 
 
89
  context 'symlink', :unless => (fact("osfamily") == "windows") do
 
90
    context 'should not succeed' do
 
91
      # XXX the core puppet file type will replace a symlink with a plain file
 
92
      # when using ensure => present and source => ... but it will not when using
 
93
      # ensure => present and content => ...; this is somewhat confusing behavior
 
94
      before(:all) do
 
95
        pp = <<-EOS
 
96
          file { '#{basedir}':
 
97
            ensure => directory,
 
98
          }
 
99
          file { '#{basedir}/file':
 
100
            ensure => link,
 
101
            target => '#{basedir}/dangling',
 
102
          }
 
103
        EOS
 
104
        apply_manifest(pp)
 
105
      end
 
106
 
 
107
      pp = <<-EOS
 
108
        concat { '#{basedir}/file':
 
109
          replace => false,
 
110
        }
 
111
 
 
112
        concat::fragment { '1':
 
113
          target  => '#{basedir}/file',
 
114
          content => '1',
 
115
        }
 
116
 
 
117
        concat::fragment { '2':
 
118
          target  => '#{basedir}/file',
 
119
          content => '2',
 
120
        }
 
121
      EOS
 
122
 
 
123
      it 'applies the manifest twice with no stderr' do
 
124
        apply_manifest(pp, :catch_failures => true)
 
125
        apply_manifest(pp, :catch_changes => true)
 
126
      end
 
127
 
 
128
      # XXX specinfra doesn't support be_linked_to on AIX
 
129
      describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX") do
 
130
        it { should be_linked_to "#{basedir}/dangling" }
 
131
      end
 
132
 
 
133
      describe file("#{basedir}/dangling") do
 
134
        # XXX serverspec does not have a matcher for 'exists'
 
135
        it { should_not be_file }
 
136
        it { should_not be_directory }
 
137
      end
 
138
    end
 
139
 
 
140
    context 'should succeed' do
 
141
      # XXX the core puppet file type will replace a symlink with a plain file
 
142
      # when using ensure => present and source => ... but it will not when using
 
143
      # ensure => present and content => ...; this is somewhat confusing behavior
 
144
      before(:all) do
 
145
        pp = <<-EOS
 
146
          file { '#{basedir}':
 
147
            ensure => directory,
 
148
          }
 
149
          file { '#{basedir}/file':
 
150
            ensure => link,
 
151
            target => '#{basedir}/dangling',
 
152
          }
 
153
        EOS
 
154
        apply_manifest(pp)
 
155
      end
 
156
 
 
157
      pp = <<-EOS
 
158
        concat { '#{basedir}/file':
 
159
          replace => true,
 
160
        }
 
161
 
 
162
        concat::fragment { '1':
 
163
          target  => '#{basedir}/file',
 
164
          content => '1',
 
165
        }
 
166
 
 
167
        concat::fragment { '2':
 
168
          target  => '#{basedir}/file',
 
169
          content => '2',
 
170
        }
 
171
      EOS
 
172
 
 
173
      it 'applies the manifest twice with no stderr' do
 
174
        apply_manifest(pp, :catch_failures => true)
 
175
        apply_manifest(pp, :catch_changes => true)
 
176
      end
 
177
 
 
178
      describe file("#{basedir}/file") do
 
179
        it { should be_file }
 
180
        it { should contain '1' }
 
181
        it { should contain '2' }
 
182
      end
 
183
    end
 
184
  end # symlink
 
185
 
 
186
  context 'directory' do
 
187
    context 'should not succeed' do
 
188
      before(:all) do
 
189
        pp = <<-EOS
 
190
          file { '#{basedir}':
 
191
            ensure => directory,
 
192
          }
 
193
          file { '#{basedir}/file':
 
194
            ensure => directory,
 
195
          }
 
196
        EOS
 
197
        apply_manifest(pp)
 
198
      end
 
199
      pp = <<-EOS
 
200
        concat { '#{basedir}/file': }
 
201
 
 
202
        concat::fragment { '1':
 
203
          target  => '#{basedir}/file',
 
204
          content => '1',
 
205
        }
 
206
 
 
207
        concat::fragment { '2':
 
208
          target  => '#{basedir}/file',
 
209
          content => '2',
 
210
        }
 
211
      EOS
 
212
 
 
213
      it 'applies the manifest twice with stderr for changing to file' do
 
214
        expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/)
 
215
        expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/)
 
216
      end
 
217
 
 
218
      describe file("#{basedir}/file") do
 
219
        it { should be_directory }
 
220
      end
 
221
    end
 
222
 
 
223
    # XXX concat's force param currently enables the creation of empty files
 
224
    # when there are no fragments, and the replace param will only replace
 
225
    # files and symlinks, not directories.  The semantics either need to be
 
226
    # changed, extended, or a new param introduced to control directory
 
227
    # replacement.
 
228
    context 'should succeed', :pending => 'not yet implemented' do
 
229
      pp = <<-EOS
 
230
        concat { '#{basedir}/file':
 
231
          force => true,
 
232
        }
 
233
 
 
234
        concat::fragment { '1':
 
235
          target  => '#{basedir}/file',
 
236
          content => '1',
 
237
        }
 
238
 
 
239
        concat::fragment { '2':
 
240
          target  => '#{basedir}/file',
 
241
          content => '2',
 
242
        }
 
243
      EOS
 
244
 
 
245
      it 'applies the manifest twice with no stderr' do
 
246
        apply_manifest(pp, :catch_failures => true)
 
247
        apply_manifest(pp, :catch_changes => true)
 
248
      end
 
249
 
 
250
      describe file("#{basedir}/file") do
 
251
        it { should be_file }
 
252
        it { should contain '1' }
 
253
      end
 
254
    end
 
255
  end # directory
 
256
end