jx/internal/fs/fs_test.go

47 lines
994 B
Go
Raw Normal View History

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package fs
import (
"github.com/stretchr/testify/assert"
"testing"
"os"
"log/slog"
2024-09-27 03:18:13 +00:00
"decl/internal/tempdir"
_ "path/filepath"
)
var TempDir tempdir.Path = "testfswalkdir"
func TestMain(m *testing.M) {
err := TempDir.Create()
if err != nil || TempDir == "" {
slog.Error("Failed creating temp dir", "error", err)
}
rc := m.Run()
TempDir.Remove()
os.Exit(rc)
}
func TestNewWalkDir(t *testing.T) {
expected := []string { "bar", "foo.txt" }
assert.Nil(t, TempDir.CreateFile("foo.txt", "testdata"))
assert.Nil(t, TempDir.Mkdir("bar", 0700))
fileSystem := TempDir.DirFS()
i := 0
d := NewWalkDir(fileSystem, string(TempDir), func(fsys FS, path string, entry DirEntry) (err error) {
slog.Info("TestWalkDir()", "path", path, "entry", entry)
assert.Equal(t, expected[i], entry.Name())
i++
return nil
})
assert.NotNil(t, d)
assert.Nil(t, d.Walk(nil))
}
func TestWalk(t *testing.T) {
}