summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/provider/mount/solaris_spec.rb157
1 files changed, 87 insertions, 70 deletions
diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb
index 9ac079a11c..e3f5ec555f 100644
--- a/spec/unit/provider/mount/solaris_spec.rb
+++ b/spec/unit/provider/mount/solaris_spec.rb
@@ -532,97 +532,114 @@ describe Chef::Provider::Mount::Solaris do
end
end
- describe "when enabling the fs" do
- it "should enable if enabled isn't true" do
- @current_resource.enabled(false)
+# describe "when enabling the fs" do
+# it "should enable if enabled isn't true" do
+# @current_resource.enabled(false)
+#
+# @fstab = StringIO.new
+# File.stub(:open).with("/etc/fstab", "a").and_yield(@fstab)
+# provider.enable_fs
+# @fstab.string.should match(%r{^/dev/sdz1\s+/tmp/foo\s+ext3\s+defaults\s+0\s+2\s*$})
+# end
+#
+# it "should not enable if enabled is true and resources match" do
+# @current_resource.enabled(true)
+# @current_resource.fstype("ext3")
+# @current_resource.options(["defaults"])
+# @current_resource.dump(0)
+# @current_resource.pass(2)
+# File.should_not_receive(:open).with("/etc/fstab", "a")
+#
+# provider.enable_fs
+# end
+#
+# it "should enable if enabled is true and resources do not match" do
+# @current_resource.enabled(true)
+# @current_resource.fstype("auto")
+# @current_resource.options(["defaults"])
+# @current_resource.dump(0)
+# @current_resource.pass(2)
+# @fstab = StringIO.new
+# File.stub(:readlines).and_return([])
+# File.should_receive(:open).once.with("/etc/fstab", "w").and_yield(@fstab)
+# File.should_receive(:open).once.with("/etc/fstab", "a").and_yield(@fstab)
+#
+# provider.enable_fs
+# end
+# end
- @fstab = StringIO.new
- File.stub(:open).with("/etc/fstab", "a").and_yield(@fstab)
- provider.enable_fs
- @fstab.string.should match(%r{^/dev/sdz1\s+/tmp/foo\s+ext3\s+defaults\s+0\s+2\s*$})
- end
+ describe "when disabling the fs" do
+ context "in the typical case" do
+ let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
- it "should not enable if enabled is true and resources match" do
- @current_resource.enabled(true)
- @current_resource.fstype("ext3")
- @current_resource.options(["defaults"])
- @current_resource.dump(0)
- @current_resource.pass(2)
- File.should_not_receive(:open).with("/etc/fstab", "a")
+ let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
- provider.enable_fs
- end
+ let(:vfstab_file_contents) { [other_mount, this_mount].join("\n") }
- it "should enable if enabled is true and resources do not match" do
- @current_resource.enabled(true)
- @current_resource.fstype("auto")
- @current_resource.options(["defaults"])
- @current_resource.dump(0)
- @current_resource.pass(2)
- @fstab = StringIO.new
- File.stub(:readlines).and_return([])
- File.should_receive(:open).once.with("/etc/fstab", "w").and_yield(@fstab)
- File.should_receive(:open).once.with("/etc/fstab", "a").and_yield(@fstab)
+ before do
+ provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
+ provider.disable_fs
+ end
- provider.enable_fs
+ it "should leave the other mountpoint alone" do
+ IO.read(vfstab_file.path).should match(Regexp.escape(other_mount))
+ end
+
+ it "should disable the mountpoint we care about" do
+ IO.read(vfstab_file.path).should_not match(Regexp.escape(this_mount))
+ end
end
- end
- describe "when disabling the fs" do
- it "should disable if enabled is true" do
- @current_resource.enabled(true)
+ context "when there is a commented out line" do
+ let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
- other_mount = "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n"
- this_mount = "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n"
+ let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
- @fstab_read = [this_mount, other_mount]
- File.stub(:readlines).with("/etc/fstab").and_return(@fstab_read)
- @fstab_write = StringIO.new
- File.stub(:open).with("/etc/fstab", "w").and_yield(@fstab_write)
+ let(:comment) { "#/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
- provider.disable_fs
- @fstab_write.string.should match(Regexp.escape(other_mount))
- @fstab_write.string.should_not match(Regexp.escape(this_mount))
- end
+ let(:vfstab_file_contents) { [other_mount, this_mount, comment].join("\n") }
- it "should disable if enabled is true and ignore commented lines" do
- @current_resource.enabled(true)
+ before do
+ provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
+ provider.disable_fs
+ end
- fstab_read = [%q{/dev/sdy1 /tmp/foo ext3 defaults 1 2},
- %q{/dev/sdz1 /tmp/foo ext3 defaults 1 2},
- %q{#/dev/sdz1 /tmp/foo ext3 defaults 1 2}]
- fstab_write = StringIO.new
+ it "should leave the other mountpoint alone" do
+ IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
+ end
- File.stub(:readlines).with("/etc/fstab").and_return(fstab_read)
- File.stub(:open).with("/etc/fstab", "w").and_yield(fstab_write)
+ it "should disable the mountpoint we care about" do
+ IO.read(vfstab_file.path).should_not match(/^#{Regexp.escape(this_mount)}/)
+ end
- provider.disable_fs
- fstab_write.string.should match(%r{^/dev/sdy1 /tmp/foo ext3 defaults 1 2$})
- fstab_write.string.should match(%r{^#/dev/sdz1 /tmp/foo ext3 defaults 1 2$})
- fstab_write.string.should_not match(%r{^/dev/sdz1 /tmp/foo ext3 defaults 1 2$})
+ it "should keep the comment" do
+ IO.read(vfstab_file.path).should match(/^#{Regexp.escape(comment)}/)
+ end
end
- it "should disable only the last entry if enabled is true" do
- @current_resource.stub(:enabled).and_return(true)
- fstab_read = ["/dev/sdz1 /tmp/foo ext3 defaults 1 2\n",
- "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n",
- "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n"]
+ context "when there is a duplicated line" do
+ let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
- fstab_write = StringIO.new
- File.stub(:readlines).with("/etc/fstab").and_return(fstab_read)
- File.stub(:open).with("/etc/fstab", "w").and_yield(fstab_write)
+ let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
- provider.disable_fs
- fstab_write.string.should == "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n/dev/sdy1 /tmp/foo ext3 defaults 1 2\n"
- end
+ let(:vfstab_file_contents) { [this_mount, other_mount, this_mount].join("\n") }
- it "should not disable if enabled is false" do
- @current_resource.stub(:enabled).and_return(false)
+ before do
+ provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
+ provider.disable_fs
+ end
- File.stub(:readlines).with("/etc/fstab").and_return([])
- File.should_not_receive(:open).and_yield(@fstab)
+ it "should leave the other mountpoint alone" do
+ IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
+ end
- provider.disable_fs
+ it "should still match the duplicated mountpoint" do
+ IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/)
+ end
+
+ it "should have removed the last line" do
+ IO.read(vfstab_file.path).should eql( "#{this_mount}\n#{other_mount}\n" )
+ end
end
end
end