mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Fail message is now the same as the required message.
Fixed #8973 Helm function 'fail' should not fail when doing 'helm lint'
Signed-off-by: Marcus Speight <marcus.speight@hotmail.co.uk>
(cherry picked from commit 7a0739a863)
This commit is contained in:
parent
80402dc078
commit
bcee7a30fe
2 changed files with 27 additions and 0 deletions
|
|
@ -173,6 +173,16 @@ func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]render
|
|||
return val, nil
|
||||
}
|
||||
|
||||
// Override sprig fail function for linting and wrapping message
|
||||
funcMap["fail"] = func(msg string) (string, error) {
|
||||
if e.LintMode {
|
||||
// Don't fail when linting
|
||||
log.Printf("[INFO] Fail: %s", msg)
|
||||
return "", nil
|
||||
}
|
||||
return "", errors.New(warnWrap(msg))
|
||||
}
|
||||
|
||||
// If we are not linting and have a cluster connection, provide a Kubernetes-backed
|
||||
// implementation.
|
||||
if !e.LintMode && e.config != nil {
|
||||
|
|
|
|||
|
|
@ -286,6 +286,23 @@ func TestExecErrors(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFailErrors(t *testing.T) {
|
||||
vals := chartutil.Values{"Values": map[string]interface{}{}}
|
||||
|
||||
failtpl := `{{ fail "This is an error" }}`
|
||||
tplsFailed := map[string]renderable{
|
||||
"failtpl": {tpl: failtpl, vals: vals},
|
||||
}
|
||||
_, err := new(Engine).render(tplsFailed)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected failures while rendering: %s", err)
|
||||
}
|
||||
expected := `execution error at (failtpl:1:3): This is an error`
|
||||
if err.Error() != expected {
|
||||
t.Errorf("Expected '%s', got %q", expected, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllTemplates(t *testing.T) {
|
||||
ch1 := &chart.Chart{
|
||||
Metadata: &chart.Metadata{Name: "ch1"},
|
||||
|
|
|
|||
Loading…
Reference in a new issue