Remove Chdir from util.FindFiles
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,40 @@ func TryCreatePath(t *testing.T, elem ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FindFiles(t *testing.T) {
|
||||
var tests = map[string]struct {
|
||||
createFiles []string
|
||||
findFiles []string
|
||||
}{
|
||||
"no files": {
|
||||
createFiles: []string{},
|
||||
findFiles: nil,
|
||||
},
|
||||
"single file": {
|
||||
createFiles: []string{"testfile"},
|
||||
findFiles: []string{"testfile"},
|
||||
},
|
||||
"nested file": {
|
||||
createFiles: []string{"testdir/testfile"},
|
||||
findFiles: []string{"testdir/", "testdir/testfile"},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
env.MkdirAll(t, "/test")
|
||||
for _, file_ := range tt.createFiles {
|
||||
env.CreateFile(t, filepath.Join("/test", file_))
|
||||
}
|
||||
|
||||
files := FindFiles(env.GetPath("/test"))
|
||||
assert.Equal(t, tt.findFiles, files)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FindFilterFiles(t *testing.T) {
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
dir, err := os.MkdirTemp(os.TempDir(), "warewulf-test")
|
||||
|
||||
Reference in New Issue
Block a user