diff --git a/connector_test.go b/connector_test.go index e7f8ed8..244ab2b 100644 --- a/connector_test.go +++ b/connector_test.go @@ -124,6 +124,16 @@ func bindMountHelper(t *testing.T, options string) { connector, _ := getConnector(t, fmt.Sprintf(volumeConfig, options)) + //goland:noinspection GoBoolExpressions // The linter cannot tell that this expression is not constant. + if runtime.GOOS == "linux" && options == "" { + // On Linux, when SELinux is enabled, then bind mounts without + // relabeling options will fail. So, to test this case, disable + // SELinux on the test folder in order to make the file readable + // from within the container. + cmd := exec.Command("chcon", "-Rt", "svirt_sandbox_file_t", "./tests/volume") //nolint:gosec + assert.NoError(t, cmd.Run()) + } + container, err := connector.Deploy( context.Background(), "quay.io/arcalot/podman-deployer-test-helper:0.1.0") @@ -136,16 +146,21 @@ func bindMountHelper(t *testing.T, options string) { // Note: If it ends up with length zero buffer, restarting the VM may help: // https://stackoverflow.com/questions/71977532/podman-mount-host-volume-return-error-statfs-no-such-file-or-directory-in-ma readBuffer := readOutputUntil(t, container, string(fileContent)) - assert.GreaterThan(t, len(readBuffer), 0) + assert.Contains(t, string(readBuffer), string(fileContent)) } func TestBindMount(t *testing.T) { scenarios := map[string]string{ - "No options": "", - "Private": ":Z", - "Shared": ":z", "ReadOnly": ":ro", - "Multiple": ":z,ro,noexec", + "Multiple": ":ro,noexec", + "No options": "", + } + //goland:noinspection GoBoolExpressions // The linter cannot tell that this expression is not constant. + if runtime.GOOS == "linux" { + // The SELinux options seem to cause problems on Mac OS X, so only test + // them on Linux. + scenarios["Private"] = ":Z" + scenarios["Shared"] = ":z" } for name, s := range scenarios { options := s