Add shortcut for SELinux detection

Skip parsing of /proc/mounts if SELinux is disabled on the machine.
This commit is contained in:
Jan Safranek
2021-11-01 14:32:30 +01:00
parent 186810eb47
commit 7b07b1ef0e
2 changed files with 22 additions and 3 deletions

View File

@@ -157,27 +157,37 @@ func TestGetSELinuxSupport(t *testing.T) {
tests := []struct {
name string
mountPoint string
selinuxEnabled bool
expectedResult bool
}{
{
"ext4 on / with disabled SELinux",
"/",
false,
false,
},
{
"ext4 on /",
"/",
true,
true,
},
{
"tmpfs on /var/lib/bar",
"/var/lib/bar",
true,
false,
},
{
"nfsv4",
"/media/nfs_vol",
true,
false,
},
}
for _, test := range tests {
out, err := GetSELinux(test.mountPoint, filename)
out, err := GetSELinux(test.mountPoint, filename, func() bool { return test.selinuxEnabled })
if err != nil {
t.Errorf("Test %s failed with error: %s", test.name, err)
}