diff options
author | Jakob Unterwurzacher | 2017-12-03 17:57:08 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2017-12-03 19:33:26 +0100 |
commit | 70bcf58a9bda5f95a3037fb785858f5d7ce3f930 (patch) | |
tree | 15122949d8adede1b6e8a68e7e2a2b19d42a1660 /internal/syscallcompat/getdents_test.go | |
parent | e33593d30d9dee6fd6b0e7c0d01832e478815d88 (diff) |
syscallcompat: convert Getdents to fd input, add emulation
Now that we have Fstatat we can use it in Getdents to
get rid of the path name.
Also, add an emulated version of getdents for MacOS. This allows
to drop the !HaveGetdents special cases from fusefrontend.
Modify the getdents test to test both native getdents and the emulated
version.
Diffstat (limited to 'internal/syscallcompat/getdents_test.go')
-rw-r--r-- | internal/syscallcompat/getdents_test.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/internal/syscallcompat/getdents_test.go b/internal/syscallcompat/getdents_test.go index 8f2bd09..131ffee 100644 --- a/internal/syscallcompat/getdents_test.go +++ b/internal/syscallcompat/getdents_test.go @@ -12,9 +12,19 @@ import ( "github.com/hanwen/go-fuse/fuse" ) +var getdentsUnderTest = getdents + func TestGetdents(t *testing.T) { + t.Logf("testing native getdents") + testGetdents(t) + t.Logf("testing emulateGetdents") + getdentsUnderTest = emulateGetdents + testGetdents(t) +} + +func testGetdents(t *testing.T) { // Fill a directory with filenames of length 1 ... 255 - testDir, err := ioutil.TempDir("", "TestGetdents") + testDir, err := ioutil.TempDir(tmpDir, "TestGetdents") if err != nil { t.Fatal(err) } @@ -35,17 +45,21 @@ func TestGetdents(t *testing.T) { if err != nil { t.Fatal(err) } + defer fd.Close() readdirEntries, err := fd.Readdir(0) if err != nil { t.Fatal(err) } - fd.Close() readdirMap := make(map[string]*syscall.Stat_t) for _, v := range readdirEntries { readdirMap[v.Name()] = fuse.ToStatT(v) } - // Read using our Getdents() - getdentsEntries, err := Getdents(dir) + // Read using our Getdents() implementation + _, err = fd.Seek(0, 0) // Rewind directory + if err != nil { + t.Fatal(err) + } + getdentsEntries, err := getdentsUnderTest(int(fd.Fd())) if err != nil { t.Fatal(err) } |