MCPcopy
hub / github.com/carvel-dev/ytt / EvalAndValidateTemplate

Function EvalAndValidateTemplate

pkg/validations/validations_test.go:56–81  ·  view source on GitHub ↗
(ft filetests.FileTests)

Source from the content-addressed store, hash-verified

54}
55
56func EvalAndValidateTemplate(ft filetests.FileTests) filetests.EvaluateTemplate {
57 return func(src string) (filetests.MarshalableResult, *filetests.TestErr) {
58 result, testErr := ft.DefaultEvalTemplate(src)
59 if testErr != nil {
60 return nil, testErr
61 }
62
63 err := validations.ProcessAssertValidateAnns(result.(yamlmeta.Node))
64 if err != nil {
65 return nil, filetests.NewTestErr(err, fmt.Errorf("Failed to process @assert/validate annotations: %s", err))
66 }
67
68 chk, err := validations.Run(result.(yamlmeta.Node), "template-test")
69 if err != nil {
70 err := fmt.Errorf("\n%s", err)
71 return nil, filetests.NewTestErr(err, fmt.Errorf("Unexpected error (did you include the \"ERR:\" marker in the output?):%v", err))
72 }
73 // TODO: proper error handling!
74 if chk.HasInvalidations() {
75 err := fmt.Errorf("\n%s", chk.ResultsAsString())
76 return nil, filetests.NewTestErr(err, fmt.Errorf("Unexpected violations (did you include the \"ERR:\" marker in the output?):%v", err))
77 }
78
79 return result, testErr
80 }
81}
82
83func showTemplateCode(showTemplateCodeFlag string) bool {
84 return strings.HasPrefix(strings.ToLower(showTemplateCodeFlag), "t")

Callers 1

TestValidationsFunction · 0.85

Calls 6

NewTestErrFunction · 0.92
RunFunction · 0.92
DefaultEvalTemplateMethod · 0.80
HasInvalidationsMethod · 0.80
ResultsAsStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…