mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-21 07:56:59 +02:00
Introduce Helmfile's own filesystem abstraction to correctly unit test some components (#307)
Use abstracted FS Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com> Signed-off-by: Arkaitz Jimenez <arkaitzj@gmail.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
ffs "github.com/helmfile/helmfile/pkg/filesystem"
|
||||
)
|
||||
|
||||
type TestFs struct {
|
||||
@@ -13,6 +15,7 @@ type TestFs struct {
|
||||
files map[string]string
|
||||
|
||||
GlobFixtures map[string][]string
|
||||
DeleteFile func(string) error
|
||||
|
||||
fileReaderCalls int
|
||||
successfulReads []string
|
||||
@@ -34,9 +37,26 @@ func NewTestFs(files map[string]string) *TestFs {
|
||||
successfulReads: []string{},
|
||||
|
||||
GlobFixtures: map[string][]string{},
|
||||
DeleteFile: func(string) (ret error) { return },
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TestFs) ToFileSystem() *ffs.FileSystem {
|
||||
curfs := ffs.FileSystem{
|
||||
FileExistsAt: f.FileExistsAt,
|
||||
FileExists: f.FileExists,
|
||||
DirectoryExistsAt: f.DirectoryExistsAt,
|
||||
ReadFile: f.ReadFile,
|
||||
Glob: f.Glob,
|
||||
Getwd: f.Getwd,
|
||||
Chdir: f.Chdir,
|
||||
Abs: f.Abs,
|
||||
DeleteFile: f.DeleteFile,
|
||||
}
|
||||
trfs := ffs.FromFileSystem(curfs)
|
||||
return trfs
|
||||
}
|
||||
|
||||
func (f *TestFs) FileExistsAt(path string) bool {
|
||||
var ok bool
|
||||
if strings.HasPrefix(path, "/") {
|
||||
|
||||
Reference in New Issue
Block a user