Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

test: add Directory.ListNames test #81

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ require (
github.com/ipfs/go-unixfs v0.1.0
github.com/libp2p/go-libp2p-testing v0.0.4
)

go 1.13
42 changes: 42 additions & 0 deletions mfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,48 @@ func TestMfsFile(t *testing.T) {
}
}

func TestMfsDirListNames(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ds, rt := setupRoot(ctx, t)

rootdir := rt.GetDirectory()

rand.Seed(time.Now().UTC().UnixNano())

total := rand.Intn(10) + 1
fNames := make([]string, 0, total)

for i := 0; i < total; i++ {
fn := randomName()
fNames = append(fNames, fn)
nd := getRandFile(t, ds, rand.Int63n(1000)+1)
err := rootdir.AddChild(fn, nd)
if err != nil {
t.Fatal(err)
}
}

list, err := rootdir.ListNames(ctx)

if err != nil {
t.Fatal(err)
}

for _, lName := range list {
found := false
for _, fName := range fNames {
if lName == fName {
found = true
break
}
}
if !found {
t.Fatal(lName + " not found in directory listing")
}
}
}

func randomWalk(d *Directory, n int) (*Directory, error) {
for i := 0; i < n; i++ {
dirents, err := d.List(context.Background())
Expand Down