jx/internal/fs/fs_test.go
Matthew Rich d815419c7b
Some checks failed
Lint / golangci-lint (push) Failing after 10m28s
Declarative Tests / test (push) Failing after 12s
Declarative Tests / build-fedora (push) Failing after 1m57s
Declarative Tests / build-ubuntu-focal (push) Successful in 1m50s
remove duplicate tempdir pkg
2024-09-27 03:18:13 +00:00

47 lines
994 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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) {
}