...
1
2
3
4
19
20 package fs
21
22 import (
23 "os/exec"
24 "testing"
25
26 "github.com/containerd/continuity/testutil"
27 "github.com/containerd/continuity/testutil/loopback"
28 )
29
30 func testSupportsDType(t *testing.T, expected bool, mkfs ...string) {
31 testutil.RequiresRoot(t)
32 mnt := t.TempDir()
33
34 loop, err := loopback.New(100 << 20)
35 if err != nil {
36 t.Fatal(err)
37 }
38 if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil {
39
40 t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out))
41 }
42 if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil {
43
44 t.Skipf("could not mount %s: %v (out: %q)", loop.Device, err, string(out))
45 }
46 defer func() {
47 testutil.Unmount(t, mnt)
48 loop.Close()
49 }()
50
51 result, err := SupportsDType(mnt)
52 if err != nil {
53 t.Fatal(err)
54 }
55 t.Logf("Supports d_type: %v", result)
56 if expected != result {
57 t.Fatalf("expected %+v, got: %+v", expected, result)
58 }
59 }
60
61 func TestSupportsDTypeWithFType0XFS(t *testing.T) {
62 testSupportsDType(t, false, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=0")
63 }
64
65 func TestSupportsDTypeWithFType1XFS(t *testing.T) {
66 testSupportsDType(t, true, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=1")
67 }
68
69 func TestSupportsDTypeWithExt4(t *testing.T) {
70 testSupportsDType(t, true, "mkfs.ext4", "-F")
71 }
72
View as plain text