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:
Arkaitz Jimenez
2022-08-24 12:58:43 +09:00
committed by GitHub
parent a626664f46
commit cc33e7b7d8
44 changed files with 513 additions and 425 deletions
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"go.uber.org/zap"
"github.com/helmfile/helmfile/pkg/environment"
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/tmpl"
)
@@ -35,9 +36,9 @@ type Bus struct {
Chart string
Env environment.Environment
Fs *filesystem.FileSystem
ReadFile func(string) ([]byte, error)
Logger *zap.SugaredLogger
Logger *zap.SugaredLogger
}
func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{}) (bool, error) {
@@ -100,7 +101,7 @@ func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{}
for k, v := range context {
data[k] = v
}
render := tmpl.NewTextRenderer(bus.ReadFile, bus.BasePath, data)
render := tmpl.NewTextRenderer(bus.Fs, bus.BasePath, data)
bus.Logger.Debugf("hook[%s]: triggered by event \"%s\"\n", name, evt)
+2 -1
View File
@@ -9,6 +9,7 @@ import (
"go.uber.org/zap/zaptest/observer"
"github.com/helmfile/helmfile/pkg/environment"
ffs "github.com/helmfile/helmfile/pkg/filesystem"
)
type runner struct {
@@ -154,7 +155,7 @@ func TestTrigger(t *testing.T) {
Namespace: "myns",
Env: environment.Environment{Name: "prod"},
Logger: zeLogger,
ReadFile: readFile,
Fs: &ffs.FileSystem{ReadFile: readFile},
}
bus.Runner = &runner{}