diff options
author | Lance Albertson <lance@osuosl.org> | 2021-03-29 16:43:42 -0700 |
---|---|---|
committer | Lance Albertson <lance@osuosl.org> | 2021-03-29 17:29:24 -0700 |
commit | 9c1c490a24c47935fbe5a9c752207540063bd74b (patch) | |
tree | aea621bb7e4d72233c5632b034555e3403a9c840 /spec | |
parent | db941bf50aa35c64ede1b731f0368a760885985a (diff) | |
download | chef-9c1c490a24c47935fbe5a9c752207540063bd74b.tar.gz |
Add unit test for network mounts
Signed-off-by: Lance Albertson <lance@osuosl.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/mount/mount_spec.rb | 51 |
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 |