summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Albertson <lance@osuosl.org>2021-03-29 16:43:42 -0700
committerLance Albertson <lance@osuosl.org>2021-03-29 16:43:42 -0700
commit7e830122368206c562cde0b3198575be7baf3cfb (patch)
tree7f731a6a9586ade50fd00b913389a49965aeab26
parent0dce37c18e54823eb8728f1bc0cbdc10ecb449e7 (diff)
downloadchef-7e830122368206c562cde0b3198575be7baf3cfb.tar.gz
Add unit test for network mounts
Signed-off-by: Lance Albertson <lance@osuosl.org>
-rw-r--r--spec/unit/provider/mount/mount_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index 015e0038c8..13b2443b8f 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -506,6 +506,57 @@ describe Chef::Provider::Mount::Mount do
end
end
+ context "network mount" do
+ before(:each) do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+
+ @new_resource = Chef::Resource::Mount.new("/tmp/bar")
+ @new_resource.device "cephserver:6789:/"
+ @new_resource.device_type :device
+ @new_resource.fstype "cephfs"
+
+ @new_resource.supports remount: false
+
+ @provider = Chef::Provider::Mount::Mount.new(@new_resource, @run_context)
+
+ allow(::File).to receive(:exists?).with("cephserver:6789:/").and_return true
+ allow(::File).to receive(:exists?).with("/tmp/bar").and_return true
+ allow(::File).to receive(:realpath).with("cephserver:6789:/").and_return "cephserver:6789:/"
+ allow(::File).to receive(:realpath).with("/tmp/bar").and_return "/tmp/foo"
+ end
+
+ before do
+ @current_resource = Chef::Resource::Mount.new("/tmp/foo")
+ @current_resource.device "cephserver:6789:/"
+ @current_resource.device_type :device
+ @current_resource.fstype "cephfs"
+
+ @provider.current_resource = @current_resource
+ end
+
+ it "should enable network mount if enabled isn't true" do
+ @current_resource.enabled(false)
+
+ @fstab = StringIO.new
+ allow(::File).to receive(:open).with("/etc/fstab", "a").and_yield(@fstab)
+ @provider.enable_fs
+ expect(@fstab.string).to match(%r{^cephserver:6789:/\s+/tmp/bar\s+cephfs\s+defaults\s+0\s+2\s*$})
+ end
+
+ it "should not enable network if enabled is true and resources match" do
+ @current_resource.enabled(true)
+ @current_resource.fstype("cephfs")
+ @current_resource.options(["defaults"])
+ @current_resource.dump(0)
+ @current_resource.pass(2)
+ expect(::File).not_to receive(:open).with("/etc/fstab", "a")
+
+ @provider.enable_fs
+ end
+ end
+
# the fstab might contain the mount with the device as a device but the resource has a label.
# we should not create two mount lines, but update the existing one
# not supported on solaris because it can't cope with a UUID device type