github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/file/fsnode/fsnodetesting/make.go (about) 1 package fsnodetesting 2 3 import ( 4 "testing" 5 6 "github.com/Schaudge/grailbase/file/fsnode" 7 "github.com/stretchr/testify/require" 8 ) 9 10 // MakeT is the inverse of (Walker).WalkContents. 11 // It keeps no references to node and its children after it returns. 12 func MakeT(t testing.TB, name string, node T) fsnode.T { 13 switch n := node.(type) { 14 case Parent: 15 var children []fsnode.T 16 for childName, child := range n { 17 children = append(children, MakeT(t, childName, child)) 18 } 19 return fsnode.NewParent(fsnode.NewDirInfo(name), fsnode.ConstChildren(children...)) 20 case Leaf: 21 return fsnode.ConstLeaf(fsnode.NewRegInfo(name), append([]byte{}, n...)) 22 } 23 require.Failf(t, "invalid node type", "node: %T", node) 24 panic("unreachable") 25 }