2024-09-19 05:25:24 +00:00
|
|
|
// 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"
|
2024-09-19 05:25:24 +00:00
|
|
|
_ "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) {
|
|
|
|
}
|