add helm-unittest integration

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2024-04-15 07:46:40 +08:00
parent 400a67fd88
commit 0ecbe8429b
10 changed files with 382 additions and 0 deletions
+23
View File
@@ -1584,6 +1584,29 @@ Do you really want to delete?
return true, errs
}
func (a *App) unittest(r *Run, c UnittestConfigProvider) (bool, []error) {
ok, errs := a.withNeeds(r, c, true, func(st *state.HelmState) []error {
helm := r.helm
opts := &state.UnittestOpts{
Color: c.Color(),
DebugPlugin: c.DebugPlugin(),
FailFast: c.FailFast(),
UnittestArgs: c.UnittestArgs(),
}
filtered := &Run{
state: st,
helm: helm,
ctx: r.ctx,
Ask: r.Ask,
}
return filtered.unittest(true, c, opts)
})
return ok, errs
}
func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error) {
var (
infoMsg *string
+4
View File
@@ -2510,6 +2510,10 @@ func (helm *mockHelmExec) SyncRelease(context helmexec.HelmContext, name, chart
func (helm *mockHelmExec) DiffRelease(context helmexec.HelmContext, name, chart string, suppressDiff bool, flags ...string) error {
return nil
}
func (helm *mockHelmExec) UnittestRelease(context helmexec.HelmContext, name, chart string, flags ...string) error {
return nil
}
func (helm *mockHelmExec) ReleaseStatus(context helmexec.HelmContext, release string, flags ...string) error {
return nil
}
+9
View File
@@ -121,6 +121,15 @@ type SyncConfigProvider interface {
valuesControlMode
}
type UnittestConfigProvider interface {
Color() bool
DebugPlugin() bool
Values() []string
FailFast() bool
UnittestArgs() []string
concurrencyConfig
DAGConfig
}
type DiffConfigProvider interface {
Args() string
PostRenderer() string
+6
View File
@@ -23,6 +23,7 @@ const (
HelmSecretsRecommendedVersion = "v4.6.0"
HelmGitRecommendedVersion = "v0.15.1"
HelmS3RecommendedVersion = "v0.16.0"
HelmUninttestVersion = "v0.4.4"
HelmInstallCommand = "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
)
@@ -53,6 +54,11 @@ var (
version: HelmGitRecommendedVersion,
repo: "https://github.com/aslafy-z/helm-git.git",
},
{
name: "helm-unittest",
version: HelmUninttestVersion,
repo: "https://github.com/helm-unittest/helm-unittest.git",
},
}
)
+26
View File
@@ -213,3 +213,29 @@ func (r *Run) diff(triggerCleanupEvent bool, detailedExitCode bool, c DiffConfig
return &infoMsg, releasesToBeUpdated, releasesToBeDeleted, nil
}
func (r *Run) unittest(triggerCleanupEvent bool, c UnittestConfigProvider, unittestOpts *state.UnittestOpts) []error {
st := r.state
helm := r.helm
planningErrs := st.UninttestReleases(helm, c.Values(), c.Concurrency(), triggerCleanupEvent, unittestOpts)
fatalErrs := []error{}
for _, e := range planningErrs {
switch err := e.(type) {
case *state.ReleaseError:
if err.Code != 2 {
fatalErrs = append(fatalErrs, e)
}
default:
fatalErrs = append(fatalErrs, e)
}
}
if len(fatalErrs) > 0 {
return fatalErrs
}
return nil
}