github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/file/fsnodefuse/dirstream_test.go (about) 1 package fsnodefuse 2 3 import ( 4 "os" 5 "sync/atomic" 6 "testing" 7 8 "github.com/Schaudge/grailbase/file/fsnode" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 // TestNameCollision verifies that we can list a directory in which there are 14 // entries with duplicate names without panicking. 15 func TestNameCollision(t *testing.T) { 16 makeTest := func(children ...fsnode.T) func(*testing.T) { 17 return func(t *testing.T) { 18 root := fsnode.NewParent( 19 fsnode.NewDirInfo("test"), 20 fsnode.ConstChildren(children...), 21 ) 22 withMounted(t, root, func(mountDir string) { 23 f, err := os.Open(mountDir) 24 require.NoError(t, err, "opening mounted directory") 25 defer func() { assert.NoError(t, f.Close()) }() 26 _, err = f.Readdir(0) 27 assert.NoError(t, err, "reading mounted directory") 28 assert.Zero(t, atomic.LoadUint32(&numHandledPanics), "checking number of panics") 29 }) 30 } 31 } 32 var ( 33 aReg = fsnode.ConstLeaf(fsnode.NewRegInfo("a"), []byte{}) 34 aDir = fsnode.NewParent(fsnode.NewDirInfo("a"), fsnode.ConstChildren()) 35 bReg = fsnode.ConstLeaf(fsnode.NewRegInfo("b"), []byte{}) 36 bDir = fsnode.NewParent(fsnode.NewDirInfo("b"), fsnode.ConstChildren()) 37 ) 38 t.Run("reg_first", makeTest(aReg, aDir)) 39 t.Run("dir_first", makeTest(aDir, aReg)) 40 t.Run("mixed", makeTest(aReg, aDir, aDir, bReg, aReg, bReg, aReg, bDir, aReg, aDir)) 41 }