github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/rootfs_linux_test.go (about) 1 // +build linux 2 3 package libcontainer 4 5 import ( 6 "testing" 7 8 "github.com/opencontainers/runc/libcontainer/configs" 9 ) 10 11 func TestCheckMountDestOnProc(t *testing.T) { 12 dest := "/rootfs/proc/" 13 err := checkMountDestination("/rootfs", dest) 14 if err == nil { 15 t.Fatal("destination inside proc should return an error") 16 } 17 } 18 19 func TestCheckMountDestInSys(t *testing.T) { 20 dest := "/rootfs//sys/fs/cgroup" 21 err := checkMountDestination("/rootfs", dest) 22 if err != nil { 23 t.Fatal("destination inside /sys should not return an error") 24 } 25 } 26 27 func TestCheckMountDestFalsePositive(t *testing.T) { 28 dest := "/rootfs/sysfiles/fs/cgroup" 29 err := checkMountDestination("/rootfs", dest) 30 if err != nil { 31 t.Fatal(err) 32 } 33 } 34 35 func TestNeedsSetupDev(t *testing.T) { 36 config := &configs.Config{ 37 Mounts: []*configs.Mount{ 38 { 39 Device: "bind", 40 Source: "/dev", 41 Destination: "/dev", 42 }, 43 }, 44 } 45 if needsSetupDev(config) { 46 t.Fatal("expected needsSetupDev to be false, got true") 47 } 48 } 49 50 func TestNeedsSetupDevStrangeSource(t *testing.T) { 51 config := &configs.Config{ 52 Mounts: []*configs.Mount{ 53 { 54 Device: "bind", 55 Source: "/devx", 56 Destination: "/dev", 57 }, 58 }, 59 } 60 if needsSetupDev(config) { 61 t.Fatal("expected needsSetupDev to be false, got true") 62 } 63 } 64 65 func TestNeedsSetupDevStrangeDest(t *testing.T) { 66 config := &configs.Config{ 67 Mounts: []*configs.Mount{ 68 { 69 Device: "bind", 70 Source: "/dev", 71 Destination: "/devx", 72 }, 73 }, 74 } 75 if !needsSetupDev(config) { 76 t.Fatal("expected needsSetupDev to be true, got false") 77 } 78 } 79 80 func TestNeedsSetupDevStrangeSourceDest(t *testing.T) { 81 config := &configs.Config{ 82 Mounts: []*configs.Mount{ 83 { 84 Device: "bind", 85 Source: "/devx", 86 Destination: "/devx", 87 }, 88 }, 89 } 90 if !needsSetupDev(config) { 91 t.Fatal("expected needsSetupDev to be true, got false") 92 } 93 }