inspec/test/unit/resources/mount_test.rb

42 lines
1.5 KiB
Ruby
Raw Normal View History

require "helper"
require "inspec/resource"
require "inspec/resources/file" # TODO: rename this test file?
require "inspec/resources/mount"
2015-12-31 00:10:06 +00:00
describe Inspec::Resources::FileResource do
let(:root_resource) { load_resource("mount", "/") }
2015-12-31 00:10:06 +00:00
it "generates the resource_id for current resource" do
_(root_resource.resource_id).must_equal "/"
end
it "parses the mount data properly" do
_(root_resource.send(:device)).must_equal("/dev/xvda1")
_(root_resource.send(:type)).must_equal("ext4")
_(root_resource.send(:options)).must_equal(%w{rw discard})
_(root_resource.send(:count)).must_equal(1)
end
let(:iso_resource) { load_resource("mount", "/mnt/iso-disk") }
it "generates resource_id for current resource" do
_(iso_resource.resource_id).must_equal "/mnt/iso-disk"
end
it "parses the mount data properly" do
_(iso_resource.send(:device)).must_equal("/root/alpine-3.3.0-x86_64_2.iso")
_(iso_resource.send(:type)).must_equal("iso9660")
_(iso_resource.send(:options)).must_equal(["ro"])
_(iso_resource.send(:count)).must_equal(2)
2015-12-31 00:10:06 +00:00
end
mount resource: fix for Device-/Sharenames and Mountpoints including … (#2257) * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Device-/Sharenames and Mountpoints on Linux may include whitespaces (\040), e.g. /etc/fstab entry like: ```//fileserver.corp.internal/Research\040&\040Development /mnt/Research\040&\040Development cifs OTHER_OPTS``` ... results in a mount line like: ```//fileserver.corp.internal/Research & Development on /mnt/Research & Development type cifs (OTHER_OPTS)``` The Linux mount command replaces \040 with whitspace automatically, so this should be tributed. I used a control like this: ``` describe mount('/mnt/Research & Development') do it { should be_mounted } its('device') { should eq '//fileserver.corp.internal/Research & Development' } end ``` Before: ``` × whitespaces-1: Mount with whitespace within sharename and mountpoint. (1 failed) ✔ Mount /mnt/Research & Development should be mounted × Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" expected: "//fileserver.corp.internal/Research & Development" got: "//fileserver.corp.internal/Research" (compared using ==) ``` After: ``` ✔ whitespaces-01: Mount with whitespace within sharename and mountpoint. ✔ Mount /mnt/Research & Development should be mounted ✔ Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" ``` Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mounts_with_whitespaces: make lint happy Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: added parentheses as suggested by https://github.com/chef/inspec/pull/2257/files Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Signed-off-by: Markus Grobelin <grobi@koppzu.de>
2017-11-01 11:01:21 +00:00
let(:ws_resource) { load_resource("mount", "/mnt/Research & Development") }
mount resource: fix for Device-/Sharenames and Mountpoints including … (#2257) * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Device-/Sharenames and Mountpoints on Linux may include whitespaces (\040), e.g. /etc/fstab entry like: ```//fileserver.corp.internal/Research\040&\040Development /mnt/Research\040&\040Development cifs OTHER_OPTS``` ... results in a mount line like: ```//fileserver.corp.internal/Research & Development on /mnt/Research & Development type cifs (OTHER_OPTS)``` The Linux mount command replaces \040 with whitspace automatically, so this should be tributed. I used a control like this: ``` describe mount('/mnt/Research & Development') do it { should be_mounted } its('device') { should eq '//fileserver.corp.internal/Research & Development' } end ``` Before: ``` × whitespaces-1: Mount with whitespace within sharename and mountpoint. (1 failed) ✔ Mount /mnt/Research & Development should be mounted × Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" expected: "//fileserver.corp.internal/Research & Development" got: "//fileserver.corp.internal/Research" (compared using ==) ``` After: ``` ✔ whitespaces-01: Mount with whitespace within sharename and mountpoint. ✔ Mount /mnt/Research & Development should be mounted ✔ Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" ``` Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mounts_with_whitespaces: make lint happy Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: added parentheses as suggested by https://github.com/chef/inspec/pull/2257/files Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Signed-off-by: Markus Grobelin <grobi@koppzu.de>
2017-11-01 11:01:21 +00:00
it "parses the mount data properly even if whitespaces are included" do
_(ws_resource.send(:device)).must_equal("//fileserver.corp.internal/Research & Development")
_(ws_resource.send(:type)).must_equal("cifs")
_(ws_resource.send(:options)).must_equal(["rw", "vers=1.0"])
_(ws_resource.send(:count)).must_equal(1)
mount resource: fix for Device-/Sharenames and Mountpoints including … (#2257) * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Device-/Sharenames and Mountpoints on Linux may include whitespaces (\040), e.g. /etc/fstab entry like: ```//fileserver.corp.internal/Research\040&\040Development /mnt/Research\040&\040Development cifs OTHER_OPTS``` ... results in a mount line like: ```//fileserver.corp.internal/Research & Development on /mnt/Research & Development type cifs (OTHER_OPTS)``` The Linux mount command replaces \040 with whitspace automatically, so this should be tributed. I used a control like this: ``` describe mount('/mnt/Research & Development') do it { should be_mounted } its('device') { should eq '//fileserver.corp.internal/Research & Development' } end ``` Before: ``` × whitespaces-1: Mount with whitespace within sharename and mountpoint. (1 failed) ✔ Mount /mnt/Research & Development should be mounted × Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" expected: "//fileserver.corp.internal/Research & Development" got: "//fileserver.corp.internal/Research" (compared using ==) ``` After: ``` ✔ whitespaces-01: Mount with whitespace within sharename and mountpoint. ✔ Mount /mnt/Research & Development should be mounted ✔ Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" ``` Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mounts_with_whitespaces: make lint happy Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: added parentheses as suggested by https://github.com/chef/inspec/pull/2257/files Signed-off-by: Markus Grobelin <grobi@koppzu.de> * mount resource: fix for Device-/Sharenames and Mountpoints including whitespaces Signed-off-by: Markus Grobelin <grobi@koppzu.de>
2017-11-01 11:01:21 +00:00
end
2015-12-31 00:10:06 +00:00
end