feat: add helmfile unittest command for helm-unittest integration (#2400)

Adds a new `helmfile unittest` command that integrates the helm-unittest
plugin, allowing users to define unit test paths per release and run them
via helmfile.

Closes #2376

Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
This commit is contained in:
Aditya Menon
2026-02-16 09:45:10 +08:00
committed by GitHub
parent 503c397810
commit 0129681222
30 changed files with 981 additions and 13 deletions
+26
View File
@@ -51,6 +51,8 @@ type execer struct {
decryptedSecretMutex sync.Mutex
decryptedSecrets map[string]*decryptedSecret
writeTempFile func([]byte) (string, error)
unittestPluginOnce sync.Once
unittestPluginErr error
}
func NewLogger(writer io.Writer, logLevel string) *zap.SugaredLogger {
@@ -744,6 +746,30 @@ func (helm *execer) Lint(name, chart string, flags ...string) error {
return err
}
func (helm *execer) Unittest(name, chart string, flags ...string) error {
// Check if the helm-unittest plugin is installed (cached across invocations)
helm.unittestPluginOnce.Do(func() {
var pluginsDir string
if helm.IsHelm3() {
pluginsDir = cliv3.New().PluginsDirectory
} else {
pluginsDir = cliv4.New().PluginsDirectory
}
_, err := GetPluginVersion("unittest", pluginsDir)
if err != nil {
helm.unittestPluginErr = fmt.Errorf("helm-unittest plugin is required for `helmfile unittest`. Install it with: helm plugin install https://github.com/helm-unittest/helm-unittest: %w", err)
}
})
if helm.unittestPluginErr != nil {
return helm.unittestPluginErr
}
helm.logger.Infof("Unit testing release=%v, chart=%v", name, chart)
out, err := helm.exec(append([]string{"unittest", chart}, flags...), map[string]string{}, nil)
helm.write(nil, out)
return err
}
func (helm *execer) Fetch(chart string, flags ...string) error {
helm.logger.Infof("Fetching %v", redactedURL(chart))
out, err := helm.exec(append([]string{"fetch", chart}, flags...), map[string]string{}, nil)