MCPcopy
hub / github.com/helm/helm / TestExecErrors

Function TestExecErrors

pkg/engine/engine_test.go:474–536  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

472}
473
474func TestExecErrors(t *testing.T) {
475 vals := common.Values{"Values": map[string]any{}}
476 cases := []struct {
477 name string
478 tpls map[string]renderable
479 expected string
480 }{
481 {
482 name: "MissingRequired",
483 tpls: map[string]renderable{
484 "missing_required": {tpl: `{{required "foo is required" .Values.foo}}`, vals: vals},
485 },
486 expected: `execution error at (missing_required:1:2): foo is required`,
487 },
488 {
489 name: "MissingRequiredWithColons",
490 tpls: map[string]renderable{
491 "missing_required_with_colons": {tpl: `{{required ":this: message: has many: colons:" .Values.foo}}`, vals: vals},
492 },
493 expected: `execution error at (missing_required_with_colons:1:2): :this: message: has many: colons:`,
494 },
495 {
496 name: "Issue6044",
497 tpls: map[string]renderable{
498 "issue6044": {
499 vals: vals,
500 tpl: `{{ $someEmptyValue := "" }}
501{{ $myvar := "abc" }}
502{{- required (printf "%s: something is missing" $myvar) $someEmptyValue | repeat 0 }}`,
503 },
504 },
505 expected: `execution error at (issue6044:3:4): abc: something is missing`,
506 },
507 {
508 name: "MissingRequiredWithNewlines",
509 tpls: map[string]renderable{
510 "issue9981": {tpl: `{{required "foo is required\nmore info after the break" .Values.foo}}`, vals: vals},
511 },
512 expected: `execution error at (issue9981:1:2): foo is required
513more info after the break`,
514 },
515 {
516 name: "FailWithNewlines",
517 tpls: map[string]renderable{
518 "issue9981": {tpl: `{{fail "something is wrong\nlinebreak"}}`, vals: vals},
519 },
520 expected: `execution error at (issue9981:1:2): something is wrong
521linebreak`,
522 },
523 }
524
525 for _, tt := range cases {
526 t.Run(tt.name, func(t *testing.T) {
527 _, err := new(Engine).render(tt.tpls)
528 if err == nil {
529 t.Fatalf("Expected failures while rendering: %s", err)
530 }
531 if err.Error() != tt.expected {

Callers

nothing calls this directly

Calls 4

renderMethod · 0.80
FatalfMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…