|
2 | 2 | require 'spec_helper'
|
3 | 3 | require 'shared_behaviours/all_parsedfile_providers'
|
4 | 4 |
|
5 |
| -provider_class = Puppet::Type.type(:mount).provider(:parsed) |
| 5 | +describe Puppet::Type.type(:mount).provider(:parsed), :unless => Puppet.features.microsoft_windows? do |
6 | 6 |
|
7 |
| -describe provider_class, :unless => Puppet.features.microsoft_windows? do |
| 7 | + let :vfstab_sample do |
| 8 | + "/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 \t\t / \t ufs 1 no\t-" |
| 9 | + end |
8 | 10 |
|
9 |
| - before :each do |
10 |
| - @mount_class = Puppet::Type.type(:mount) |
11 |
| - @provider = @mount_class.provider(:parsed) |
| 11 | + let :fstab_sample do |
| 12 | + "/dev/vg00/lv01\t/spare \t \t ext3 defaults\t1 2" |
12 | 13 | end
|
13 | 14 |
|
14 | 15 | # LAK:FIXME I can't mock Facter because this test happens at parse-time.
|
15 | 16 | it "should default to /etc/vfstab on Solaris" do
|
16 | 17 | pending "This test only works on Solaris" unless Facter.value(:osfamily) == 'Solaris'
|
17 |
| - Puppet::Type.type(:mount).provider(:parsed).default_target.should == '/etc/vfstab' |
| 18 | + described_class.default_target.should == '/etc/vfstab' |
18 | 19 | end
|
19 | 20 |
|
20 | 21 | it "should default to /etc/fstab on anything else" do
|
21 | 22 | pending "This test does not work on Solaris" if Facter.value(:osfamily) == 'Solaris'
|
22 |
| - Puppet::Type.type(:mount).provider(:parsed).default_target.should == '/etc/fstab' |
| 23 | + described_class.default_target.should == '/etc/fstab' |
23 | 24 | end
|
24 | 25 |
|
25 | 26 | describe "when parsing a line" do
|
26 |
| - |
27 | 27 | it "should not crash on incomplete lines in fstab" do
|
28 |
| - parse = @provider.parse <<-FSTAB |
| 28 | + parse = described_class.parse <<-FSTAB |
29 | 29 | /dev/incomplete
|
30 | 30 | /dev/device name
|
31 | 31 | FSTAB
|
32 |
| - lambda{ @provider.to_line(parse[0]) }.should_not raise_error |
| 32 | + expect { described_class.to_line(parse[0]) }.to_not raise_error |
33 | 33 | end
|
34 | 34 |
|
35 | 35 | # it_should_behave_like "all parsedfile providers",
|
36 | 36 | # provider_class, my_fixtures('*.fstab')
|
37 | 37 |
|
38 | 38 | describe "on Solaris", :if => Facter.value(:osfamily) == 'Solaris' do
|
39 |
| - |
40 |
| - before :each do |
41 |
| - @example_line = "/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 \t\t / \t ufs 1 no\t-" |
42 |
| - end |
43 |
| - |
44 | 39 | it "should extract device from the first field" do
|
45 |
| - @provider.parse_line(@example_line)[:device].should == '/dev/dsk/c0d0s0' |
| 40 | + described_class.parse_line(vfstab_sample)[:device].should == '/dev/dsk/c0d0s0' |
46 | 41 | end
|
47 | 42 |
|
48 | 43 | it "should extract blockdevice from second field" do
|
49 |
| - @provider.parse_line(@example_line)[:blockdevice].should == "/dev/rdsk/c0d0s0" |
| 44 | + described_class.parse_line(vfstab_sample)[:blockdevice].should == "/dev/rdsk/c0d0s0" |
50 | 45 | end
|
51 | 46 |
|
52 | 47 | it "should extract name from third field" do
|
53 |
| - @provider.parse_line(@example_line)[:name].should == "/" |
| 48 | + described_class.parse_line(vfstab_sample)[:name].should == "/" |
54 | 49 | end
|
55 | 50 |
|
56 | 51 | it "should extract fstype from fourth field" do
|
57 |
| - @provider.parse_line(@example_line)[:fstype].should == "ufs" |
| 52 | + described_class.parse_line(vfstab_sample)[:fstype].should == "ufs" |
58 | 53 | end
|
59 | 54 |
|
60 | 55 | it "should extract pass from fifth field" do
|
61 |
| - @provider.parse_line(@example_line)[:pass].should == "1" |
| 56 | + described_class.parse_line(vfstab_sample)[:pass].should == "1" |
62 | 57 | end
|
63 | 58 |
|
64 | 59 | it "should extract atboot from sixth field" do
|
65 |
| - @provider.parse_line(@example_line)[:atboot].should == "no" |
| 60 | + described_class.parse_line(vfstab_sample)[:atboot].should == "no" |
66 | 61 | end
|
67 | 62 |
|
68 | 63 | it "should extract options from seventh field" do
|
69 |
| - @provider.parse_line(@example_line)[:options].should == "-" |
| 64 | + described_class.parse_line(vfstab_sample)[:options].should == "-" |
70 | 65 | end
|
71 |
| - |
72 | 66 | end
|
73 | 67 |
|
74 | 68 | describe "on other platforms than Solaris", :if => Facter.value(:osfamily) != 'Solaris' do
|
75 |
| - |
76 |
| - before :each do |
77 |
| - @example_line = "/dev/vg00/lv01\t/spare \t \t ext3 defaults\t1 2" |
78 |
| - end |
79 |
| - |
80 | 69 | it "should extract device from the first field" do
|
81 |
| - @provider.parse_line(@example_line)[:device].should == '/dev/vg00/lv01' |
| 70 | + described_class.parse_line(fstab_sample)[:device].should == '/dev/vg00/lv01' |
82 | 71 | end
|
83 | 72 |
|
84 | 73 | it "should extract name from second field" do
|
85 |
| - @provider.parse_line(@example_line)[:name].should == "/spare" |
| 74 | + described_class.parse_line(fstab_sample)[:name].should == "/spare" |
86 | 75 | end
|
87 | 76 |
|
88 | 77 | it "should extract fstype from third field" do
|
89 |
| - @provider.parse_line(@example_line)[:fstype].should == "ext3" |
| 78 | + described_class.parse_line(fstab_sample)[:fstype].should == "ext3" |
90 | 79 | end
|
91 | 80 |
|
92 | 81 | it "should extract options from fourth field" do
|
93 |
| - @provider.parse_line(@example_line)[:options].should == "defaults" |
| 82 | + described_class.parse_line(fstab_sample)[:options].should == "defaults" |
94 | 83 | end
|
95 | 84 |
|
96 | 85 | it "should extract dump from fifth field" do
|
97 |
| - @provider.parse_line(@example_line)[:dump].should == "1" |
| 86 | + described_class.parse_line(fstab_sample)[:dump].should == "1" |
98 | 87 | end
|
99 | 88 |
|
100 | 89 | it "should extract options from sixth field" do
|
101 |
| - @provider.parse_line(@example_line)[:pass].should == "2" |
| 90 | + described_class.parse_line(fstab_sample)[:pass].should == "2" |
102 | 91 | end
|
103 |
| - |
104 | 92 | end
|
105 | 93 |
|
106 | 94 | end
|
107 | 95 |
|
108 | 96 | describe "mountinstances" do
|
109 | 97 | it "should get name from mountoutput found on Solaris" do
|
110 | 98 | Facter.stubs(:value).with(:osfamily).returns 'Solaris'
|
111 |
| - @provider.stubs(:mountcmd).returns(File.read(my_fixture('solaris.mount'))) |
112 |
| - mounts = @provider.mountinstances |
| 99 | + described_class.stubs(:mountcmd).returns(File.read(my_fixture('solaris.mount'))) |
| 100 | + mounts = described_class.mountinstances |
113 | 101 | mounts.size.should == 6
|
114 | 102 | mounts[0].should == { :name => '/', :mounted => :yes }
|
115 | 103 | mounts[1].should == { :name => '/proc', :mounted => :yes }
|
|
121 | 109 |
|
122 | 110 | it "should get name from mountoutput found on HP-UX" do
|
123 | 111 | Facter.stubs(:value).with(:osfamily).returns 'HP-UX'
|
124 |
| - @provider.stubs(:mountcmd).returns(File.read(my_fixture('hpux.mount'))) |
125 |
| - mounts = @provider.mountinstances |
| 112 | + described_class.stubs(:mountcmd).returns(File.read(my_fixture('hpux.mount'))) |
| 113 | + mounts = described_class.mountinstances |
126 | 114 | mounts.size.should == 17
|
127 | 115 | mounts[0].should == { :name => '/', :mounted => :yes }
|
128 | 116 | mounts[1].should == { :name => '/devices', :mounted => :yes }
|
|
145 | 133 |
|
146 | 134 | it "should get name from mountoutput found on Darwin" do
|
147 | 135 | Facter.stubs(:value).with(:osfamily).returns 'Darwin'
|
148 |
| - @provider.stubs(:mountcmd).returns(File.read(my_fixture('darwin.mount'))) |
149 |
| - mounts = @provider.mountinstances |
| 136 | + described_class.stubs(:mountcmd).returns(File.read(my_fixture('darwin.mount'))) |
| 137 | + mounts = described_class.mountinstances |
150 | 138 | mounts.size.should == 6
|
151 | 139 | mounts[0].should == { :name => '/', :mounted => :yes }
|
152 | 140 | mounts[1].should == { :name => '/dev', :mounted => :yes }
|
|
158 | 146 |
|
159 | 147 | it "should get name from mountoutput found on Linux" do
|
160 | 148 | Facter.stubs(:value).with(:osfamily).returns 'Gentoo'
|
161 |
| - @provider.stubs(:mountcmd).returns(File.read(my_fixture('linux.mount'))) |
162 |
| - mounts = @provider.mountinstances |
| 149 | + described_class.stubs(:mountcmd).returns(File.read(my_fixture('linux.mount'))) |
| 150 | + mounts = described_class.mountinstances |
163 | 151 | mounts[0].should == { :name => '/', :mounted => :yes }
|
164 | 152 | mounts[1].should == { :name => '/lib64/rc/init.d', :mounted => :yes }
|
165 | 153 | mounts[2].should == { :name => '/sys', :mounted => :yes }
|
|
169 | 157 |
|
170 | 158 | it "should get name from mountoutput found on AIX" do
|
171 | 159 | Facter.stubs(:value).with(:osfamily).returns 'AIX'
|
172 |
| - @provider.stubs(:mountcmd).returns(File.read(my_fixture('aix.mount'))) |
173 |
| - mounts = @provider.mountinstances |
| 160 | + described_class.stubs(:mountcmd).returns(File.read(my_fixture('aix.mount'))) |
| 161 | + mounts = described_class.mountinstances |
174 | 162 | mounts[0].should == { :name => '/', :mounted => :yes }
|
175 | 163 | mounts[1].should == { :name => '/tmp', :mounted => :yes }
|
176 | 164 | mounts[2].should == { :name => '/home', :mounted => :yes }
|
|
179 | 167 | end
|
180 | 168 |
|
181 | 169 | it "should raise an error if a line is not understandable" do
|
182 |
| - @provider.stubs(:mountcmd).returns("bazinga!") |
183 |
| - lambda { @provider.mountinstances }.should raise_error Puppet::Error |
| 170 | + described_class.stubs(:mountcmd).returns("bazinga!") |
| 171 | + expect { described_class.mountinstances }.to raise_error Puppet::Error, 'Could not understand line bazinga! from mount output' |
184 | 172 | end
|
185 | 173 |
|
186 | 174 | end
|
|
203 | 191 | # Stub the mount output to our fixture.
|
204 | 192 | begin
|
205 | 193 | mount = my_fixture(platform + '.mount')
|
206 |
| - @provider.stubs(:mountcmd).returns File.read(mount) |
| 194 | + described_class.stubs(:mountcmd).returns File.read(mount) |
207 | 195 | rescue
|
208 | 196 | pending "is #{platform}.mount missing at this point?"
|
209 | 197 | end
|
210 | 198 |
|
211 | 199 | # Note: we have to stub default_target before creating resources
|
212 | 200 | # because it is used by Puppet::Type::Mount.new to populate the
|
213 | 201 | # :target property.
|
214 |
| - @provider.stubs(:default_target).returns fstab |
215 |
| - @retrieve = @provider.instances.collect { |prov| {:name => prov.get(:name), :ensure => prov.get(:ensure)}} |
| 202 | + described_class.stubs(:default_target).returns fstab |
| 203 | + @retrieve = described_class.instances.collect { |prov| {:name => prov.get(:name), :ensure => prov.get(:ensure)}} |
216 | 204 | end
|
217 | 205 |
|
218 | 206 | # Following mountpoint are present in all fstabs/mountoutputs
|
|
246 | 234 | # Stub the mount output to our fixture.
|
247 | 235 | begin
|
248 | 236 | mount = my_fixture(platform + '.mount')
|
249 |
| - @provider.stubs(:mountcmd).returns File.read(mount) |
| 237 | + described_class.stubs(:mountcmd).returns File.read(mount) |
250 | 238 | rescue
|
251 | 239 | pending "is #{platform}.mount missing at this point?"
|
252 | 240 | end
|
253 | 241 |
|
254 | 242 | # Note: we have to stub default_target before creating resources
|
255 | 243 | # because it is used by Puppet::Type::Mount.new to populate the
|
256 | 244 | # :target property.
|
257 |
| - @provider.stubs(:default_target).returns fstab |
| 245 | + described_class.stubs(:default_target).returns fstab |
258 | 246 |
|
259 | 247 | @res_ghost = Puppet::Type::Mount.new(:name => '/ghost') # in no fake fstab
|
260 | 248 | @res_mounted = Puppet::Type::Mount.new(:name => '/') # in every fake fstab
|
|
270 | 258 |
|
271 | 259 | it "should set :ensure to :unmounted if found in fstab but not mounted" do
|
272 | 260 | pending("Solaris:Unable to stub Operating System Fact at runtime", :if => Facter.value(:osfamily) == "Solaris")
|
273 |
| - @provider.prefetch(@resource_hash) |
| 261 | + described_class.prefetch(@resource_hash) |
274 | 262 | @res_unmounted.provider.get(:ensure).should == :unmounted
|
275 | 263 | end
|
276 | 264 |
|
277 | 265 | it "should set :ensure to :ghost if not found in fstab but mounted" do
|
278 | 266 | pending("Solaris:Unable to stub Operating System Fact at runtime", :if => Facter.value(:osfamily) == "Solaris")
|
279 |
| - @provider.prefetch(@resource_hash) |
| 267 | + described_class.prefetch(@resource_hash) |
280 | 268 | @res_ghost.provider.get(:ensure).should == :ghost
|
281 | 269 | end
|
282 | 270 |
|
283 | 271 | it "should set :ensure to :mounted if found in fstab and mounted" do
|
284 | 272 | pending("Solaris:Unable to stub Operating System Fact at runtime", :if => Facter.value(:osfamily) == "Solaris")
|
285 |
| - @provider.prefetch(@resource_hash) |
| 273 | + described_class.prefetch(@resource_hash) |
286 | 274 | @res_mounted.provider.get(:ensure).should == :mounted
|
287 | 275 | end
|
288 | 276 |
|
289 | 277 | it "should set :ensure to :absent if not found in fstab and not mounted" do
|
290 |
| - @provider.prefetch(@resource_hash) |
| 278 | + described_class.prefetch(@resource_hash) |
291 | 279 | @res_absent.provider.get(:ensure).should == :absent
|
292 | 280 | end
|
293 | 281 | end
|
|
0 commit comments