1010package lookuptest
1111
1212import (
13+ "fmt"
1314 "io/ioutil"
1415 "os"
1516 "os/exec"
@@ -20,18 +21,19 @@ import (
2021 "github.com/containerd/containerd/mount"
2122 "github.com/containerd/containerd/testutil"
2223 "github.com/stretchr/testify/assert"
24+ "github.com/stretchr/testify/require"
2325)
2426
25- func testLookup (t * testing.T , fsType string ) {
26- checkLookup := func (mntPoint , dir string ) {
27- info , err := mount .Lookup (dir )
28- if err != nil {
29- t .Fatal (err )
30- }
31- assert .Equal (t , fsType , info .FSType )
32- assert .Equal (t , mntPoint , info .Mountpoint )
27+ func checkLookup (t * testing.T , fsType , mntPoint , dir string ) {
28+ info , err := mount .Lookup (dir )
29+ if err != nil {
30+ t .Fatal (err )
3331 }
32+ assert .Equal (t , fsType , info .FSType )
33+ assert .Equal (t , mntPoint , info .Mountpoint )
34+ }
3435
36+ func testLookup (t * testing.T , fsType string ) {
3537 testutil .RequiresRoot (t )
3638 mnt , err := ioutil .TempDir ("" , "containerd-mountinfo-test-lookup" )
3739 if err != nil {
@@ -56,7 +58,7 @@ func testLookup(t *testing.T, fsType string) {
5658 cleanupDevice ()
5759 }()
5860 assert .True (t , strings .HasPrefix (deviceName , "/dev/loop" ))
59- checkLookup (mnt , mnt )
61+ checkLookup (t , fsType , mnt , mnt )
6062
6163 newMnt , err := ioutil .TempDir ("" , "containerd-mountinfo-test-newMnt" )
6264 if err != nil {
@@ -70,14 +72,14 @@ func testLookup(t *testing.T, fsType string) {
7072 defer func () {
7173 testutil .Unmount (t , newMnt )
7274 }()
73- checkLookup (newMnt , newMnt )
75+ checkLookup (t , fsType , newMnt , newMnt )
7476
7577 subDir := filepath .Join (newMnt , "subDir" )
7678 err = os .MkdirAll (subDir , 0700 )
7779 if err != nil {
7880 t .Fatal (err )
7981 }
80- checkLookup (newMnt , subDir )
82+ checkLookup (t , fsType , newMnt , subDir )
8183}
8284
8385func TestLookupWithExt4 (t * testing.T ) {
@@ -87,3 +89,39 @@ func TestLookupWithExt4(t *testing.T) {
8789func TestLookupWithXFS (t * testing.T ) {
8890 testLookup (t , "xfs" )
8991}
92+
93+ func TestLookupWithOverlay (t * testing.T ) {
94+ lower , err := ioutil .TempDir ("" , "containerd-mountinfo-test-lower" )
95+ require .NoError (t , err )
96+ defer os .RemoveAll (lower )
97+
98+ upper , err := ioutil .TempDir ("" , "containerd-mountinfo-test-upper" )
99+ require .NoError (t , err )
100+ defer os .RemoveAll (upper )
101+
102+ work , err := ioutil .TempDir ("" , "containerd-mountinfo-test-work" )
103+ require .NoError (t , err )
104+ defer os .RemoveAll (work )
105+
106+ overlay , err := ioutil .TempDir ("" , "containerd-mountinfo-test-overlay" )
107+ require .NoError (t , err )
108+ defer os .RemoveAll (overlay )
109+
110+ if out , err := exec .Command ("mount" , "-t" , "overlay" , "overlay" , "-o" , fmt .Sprintf ("lowerdir=%s,upperdir=%s,workdir=%s" ,
111+ lower , upper , work ), overlay ).CombinedOutput (); err != nil {
112+ // not fatal
113+ t .Skipf ("could not mount overlay: %v (out: %q)" , err , string (out ))
114+ }
115+ defer testutil .Unmount (t , overlay )
116+
117+ testdir := filepath .Join (overlay , "testdir" )
118+ err = os .Mkdir (testdir , 0777 )
119+ require .NoError (t , err )
120+
121+ testfile := filepath .Join (overlay , "testfile" )
122+ _ , err = os .Create (testfile )
123+ require .NoError (t , err )
124+
125+ checkLookup (t , "overlay" , overlay , testdir )
126+ checkLookup (t , "overlay" , overlay , testfile )
127+ }
0 commit comments