Implement ReadDir

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/3/head v0.0.2
jolheiser 2021-02-19 20:41:44 -06:00
parent 5f001da59e
commit ea7687d011
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
2 changed files with 49 additions and 0 deletions

View File

@ -39,6 +39,12 @@ func (f *FS) Open(name string) (fs.File, error) {
return f.fs.Open(name)
}
// ReadDir reads []fs.DirEntry
// This method will prefer EMBEDDED, because that is the "real" FS for overlay
func (f *FS) ReadDir(name string) ([]fs.DirEntry, error) {
return fs.ReadDir(f.fs, name)
}
// Option is a functional option for an FS
type Option func(*FS) error

View File

@ -3,6 +3,7 @@ package overlay
import (
"embed"
"io"
"io/fs"
"os"
"strings"
"testing"
@ -62,6 +63,48 @@ func TestOverlay(t *testing.T) {
}
}
func TestWalk(t *testing.T) {
expected := []string{"test1.txt", "test2.txt"}
x, err := New("_test/disk", embedded, WithSub("_test/embed"), WithCaching(false))
if err != nil {
t.Log(err)
t.FailNow()
}
found := make([]string, 0)
if err := fs.WalkDir(x, ".", func(walkPath string, walkEntry fs.DirEntry, walkErr error) error {
if walkErr != nil {
return walkErr
}
if walkEntry.IsDir() {
return nil
}
found = append(found, walkEntry.Name())
return nil
}); err != nil {
t.Log(err)
t.FailNow()
}
for _, e := range expected {
exists := false
for _, f := range found {
if e == f {
exists = true
break
}
}
if !exists {
t.Logf("could not find %s in %s\n", e, found)
t.Fail()
}
}
}
var emptyFS embed.FS
func TestInvalid(t *testing.T) {