From 66bfd4d9fef5df871348964526b64b700ee6a19c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 19 Jun 2025 13:44:18 +0200 Subject: testing: reverse: factor out newReverseFS Will be used soon in a new gitignore test. Relates-to: https://github.com/rfjakob/gocryptfs/issues/927 --- tests/reverse/main_test.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/reverse/main_test.go b/tests/reverse/main_test.go index 2fc9e5e..142e3eb 100644 --- a/tests/reverse/main_test.go +++ b/tests/reverse/main_test.go @@ -40,23 +40,14 @@ func TestMain(m *testing.M) { {false, true}, } for i, tc := range testcases { - argsA := []string{"-reverse"} + // Fill the global vars plaintextnames, deterministic_names = tc.plaintextnames, tc.deterministic_names - if tc.plaintextnames { - argsA = append(argsA, "-plaintextnames") - } else if tc.deterministic_names { - argsA = append(argsA, "-deterministic-names") - } - dirA = test_helpers.InitFS(nil, argsA...) - dirB = test_helpers.TmpDir + "/b" + + dirA, dirB, _ = newReverseFS(nil) dirC = test_helpers.TmpDir + "/c" - if err := os.Mkdir(dirB, 0700); err != nil { - panic(err) - } if err := os.Mkdir(dirC, 0700); err != nil { panic(err) } - test_helpers.MountOrExit(dirA, dirB, "-reverse", "-extpass", "echo test") test_helpers.MountOrExit(dirB, dirC, "-extpass", "echo test") r = m.Run() test_helpers.UnmountPanic(dirC) @@ -73,3 +64,20 @@ func TestMain(m *testing.M) { } os.Exit(r) } + +// newReverseFS creates and mounts a new, empty reverse filesystem. +func newReverseFS(extraMountArgs []string) (backingDir, mntDir, ctlsockPath string) { + args := []string{"-reverse"} + if plaintextnames { + args = append(args, "-plaintextnames") + } else if deterministic_names { + args = append(args, "-deterministic-names") + } + backingDir = test_helpers.InitFS(nil, args...) + mntDir = backingDir + ".mnt" + ctlsockPath = mntDir + ".sock" + mountArgs := []string{"-reverse", "-extpass", "echo test", "-ctlsock", ctlsockPath} + mountArgs = append(mountArgs, extraMountArgs...) + test_helpers.MountOrExit(backingDir, mntDir, mountArgs...) + return +} -- cgit v1.2.3