From 5f2661eb3bbd25054fdd5e39f394ef70aced158c Mon Sep 17 00:00:00 2001 From: yxxhero Date: Thu, 27 Apr 2023 07:54:07 +0800 Subject: [PATCH] fix tests Signed-off-by: yxxhero --- pkg/testhelper/testfs.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/testhelper/testfs.go b/pkg/testhelper/testfs.go index 97583b5d..db0e212d 100644 --- a/pkg/testhelper/testfs.go +++ b/pkg/testhelper/testfs.go @@ -5,10 +5,32 @@ import ( "os" "path/filepath" "strings" + "time" ffs "github.com/helmfile/helmfile/pkg/filesystem" ) +type TestFileInfo struct { + name string + mode os.FileMode + size int64 + modTime time.Time +} + +func (f TestFileInfo) Name() string { return f.name } +func (f TestFileInfo) Size() int64 { return f.size } +func (f TestFileInfo) Mode() os.FileMode { + return f.mode +} +func (f TestFileInfo) ModTime() time.Time { return f.modTime } +func (f TestFileInfo) IsDir() bool { + return f.Mode() == os.ModeDir +} + +func (f TestFileInfo) Sys() interface{} { + return nil +} + type TestFs struct { Cwd string dirs map[string]bool @@ -51,6 +73,7 @@ func (f *TestFs) ToFileSystem() *ffs.FileSystem { Chdir: f.Chdir, Abs: f.Abs, DeleteFile: f.DeleteFile, + Stat: f.Stat, } trfs := ffs.FromFileSystem(curfs) return trfs @@ -80,6 +103,23 @@ func (f *TestFs) DirectoryExistsAt(path string) bool { return ok } +func (f *TestFs) Stat(path string) (os.FileInfo, error) { + if _, ok := f.dirs[path]; ok { + return TestFileInfo{ + name: path, + mode: os.ModeDir, + }, nil + } + + if _, ok := f.files[path]; ok { + return TestFileInfo{ + name: path, + mode: os.ModePerm, + }, nil + } + return nil, fmt.Errorf("%s does not exist", path) +} + func (f *TestFs) ReadFile(filename string) ([]byte, error) { var str string var ok bool