From 88b80c1df62b88e22737e016865bc88b042d788e Mon Sep 17 00:00:00 2001
From: Paul Holzinger <pholzing@redhat.com>
Date: Fri, 26 Apr 2024 18:16:27 +0200
Subject: [PATCH] test/e2e: podman unshare image mount fix tmpdir leak

Because the test left the image mounted the cleanup failed to remove the
tmpdir as it contained an active mount point. Thus ensure we unmount the
image again to prevent this leak.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
---
 test/e2e/mount_rootless_test.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/test/e2e/mount_rootless_test.go b/test/e2e/mount_rootless_test.go
index 7b2a5badfa..7e4af2eb68 100644
--- a/test/e2e/mount_rootless_test.go
+++ b/test/e2e/mount_rootless_test.go
@@ -1,6 +1,8 @@
 package integration
 
 import (
+	"slices"
+
 	. "github.com/containers/podman/v5/test/utils"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
@@ -63,5 +65,14 @@ var _ = Describe("Podman mount", func() {
 		session.WaitWithDefaultTimeout()
 		Expect(session).Should(ExitCleanly())
 		Expect(session.OutputToString()).To(ContainSubstring(podmanTest.TempDir))
+
+		// We have to unmount the image again otherwise we leak the tmpdir
+		// as active mount points cannot be removed.
+		index := slices.Index(args, "mount")
+		Expect(index).To(BeNumerically(">", 0), "index should be found")
+		args[index] = "unmount"
+		session = podmanTest.Podman(args)
+		session.WaitWithDefaultTimeout()
+		Expect(session).Should(ExitCleanly())
 	})
 })