summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-08-11 20:21:32 +0200
committerJakob Unterwurzacher2021-08-11 20:23:35 +0200
commit2d386fc92e88be5384d1654db5d6e23ef4682354 (patch)
tree32ad6c71cad91bc64f162d81ce7e64903b6e6b4f /tests
parent0c16616117e9866cc49adc85738e3c9e3adf413a (diff)
syscallcompat: move quirks logic here & fix darwin
We need to look at f_fstypename acc. to https://stackoverflow.com/a/52299141/1380267 : > As filesystem type numbers are now assigned at runtime in > recent versions of MacOS, you must use f_fstypename to > determine the type. https://github.com/rfjakob/gocryptfs/issues/585
Diffstat (limited to 'tests')
-rw-r--r--tests/root_test/root_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/root_test/root_test.go b/tests/root_test/root_test.go
index 8547e4e..e68f86a 100644
--- a/tests/root_test/root_test.go
+++ b/tests/root_test/root_test.go
@@ -12,6 +12,8 @@ import (
"syscall"
"testing"
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
+
"golang.org/x/sys/unix"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
@@ -311,3 +313,50 @@ func TestAcl(t *testing.T) {
dumpAcl()
}
}
+
+// TestBtrfsQuirks needs root permissions because it creates a loop disk
+func TestBtrfsQuirks(t *testing.T) {
+ if os.Getuid() != 0 {
+ t.Skip("must run as root")
+ }
+
+ img := filepath.Join(test_helpers.TmpDir, t.Name()+".img")
+ f, err := os.Create(img)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ // minimum size for each btrfs device is 114294784
+ err = f.Truncate(200 * 1024 * 1024)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // Format as Btrfs
+ cmd := exec.Command("mkfs.btrfs", img)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Log(string(out))
+ t.Fatal(err)
+ }
+
+ // Mount
+ mnt := img + ".mnt"
+ err = os.Mkdir(mnt, 0600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cmd = exec.Command("mount", img, mnt)
+ out, err = cmd.CombinedOutput()
+ if err != nil {
+ t.Log(string(out))
+ t.Fatal(err)
+ }
+ defer syscall.Unlink(img)
+ defer syscall.Unmount(mnt, 0)
+
+ quirk := syscallcompat.DetectQuirks(mnt)
+ if quirk != syscallcompat.QuirkBrokenFalloc {
+ t.Errorf("wrong quirk: %v", quirk)
+ }
+}