diff options
Diffstat (limited to 'libgo/go/io/fs/readdir_test.go')
-rw-r--r-- | libgo/go/io/fs/readdir_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libgo/go/io/fs/readdir_test.go b/libgo/go/io/fs/readdir_test.go index 405bfa67ca4..a2b2c121ffa 100644 --- a/libgo/go/io/fs/readdir_test.go +++ b/libgo/go/io/fs/readdir_test.go @@ -6,7 +6,10 @@ package fs_test import ( . "io/fs" + "os" "testing" + "testing/fstest" + "time" ) type readDirOnly struct{ ReadDirFS } @@ -41,3 +44,50 @@ func TestReadDir(t *testing.T) { dirs, err = ReadDir(sub, ".") check("sub(.)", dirs, err) } + +func TestFileInfoToDirEntry(t *testing.T) { + testFs := fstest.MapFS{ + "notadir.txt": { + Data: []byte("hello, world"), + Mode: 0, + ModTime: time.Now(), + Sys: &sysValue, + }, + "adir": { + Data: nil, + Mode: os.ModeDir, + ModTime: time.Now(), + Sys: &sysValue, + }, + } + + tests := []struct { + path string + wantMode FileMode + wantDir bool + }{ + {path: "notadir.txt", wantMode: 0, wantDir: false}, + {path: "adir", wantMode: os.ModeDir, wantDir: true}, + } + + for _, test := range tests { + test := test + t.Run(test.path, func(t *testing.T) { + fi, err := Stat(testFs, test.path) + if err != nil { + t.Fatal(err) + } + + dirEntry := FileInfoToDirEntry(fi) + if g, w := dirEntry.Type(), test.wantMode; g != w { + t.Errorf("FileMode mismatch: got=%v, want=%v", g, w) + } + if g, w := dirEntry.Name(), test.path; g != w { + t.Errorf("Name mismatch: got=%v, want=%v", g, w) + } + if g, w := dirEntry.IsDir(), test.wantDir; g != w { + t.Errorf("IsDir mismatch: got=%v, want=%v", g, w) + } + }) + } +} |