// Copyright 2024 Matthew Rich . All rights reserved. package fs import ( "github.com/stretchr/testify/assert" "testing" "os" "log/slog" "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) { }