Documentation ¶
Overview ¶
Package filetests houses a test harness for evaluating templates and asserting the expected output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TrimTrailingMultilineWhitespace ¶
TrimTrailingMultilineWhitespace returns a string with trailing whitespace trimmed from every line as well as trimmed trailing empty lines
Types ¶
type DefaultTemplateLoader ¶
type DefaultTemplateLoader struct { template.NoopCompiledTemplateLoader CompiledTemplate *template.CompiledTemplate DataValues yamlmeta.Document }
DefaultTemplateLoader is a template.NoopCompiledTemplateLoader that allows any standard library module to be loaded (including "@ytt:data", populated with "DataValues")
func (DefaultTemplateLoader) FindCompiledTemplate ¶
func (l DefaultTemplateLoader) FindCompiledTemplate(_ string) *template.CompiledTemplate
FindCompiledTemplate returns the compiled template that is the subject of the current executing test.
func (DefaultTemplateLoader) Load ¶
func (l DefaultTemplateLoader) Load(_ *starlark.Thread, module string) (starlark.StringDict, error)
Load provides the ability to load any module from the ytt standard library (including `@ytt:data` populated with DefaultTemplateLoader.DataValues)
type EvaluateTemplate ¶
type EvaluateTemplate func(src string) (MarshalableResult, *TestErr)
EvaluateTemplate is the processing desired from a source template to the final result.
type FileTests ¶
type FileTests struct { PathToTests string EvalFunc EvaluateTemplate ShowTemplateCode bool DataValues yamlmeta.Document }
FileTests contain a suite of test cases, each described in a separate file, verifying the behavior of templates.
Test cases: - are found within the directory at "PathToTests" - conventionally have a .tpltest extension - top-half is the template; bottom-half is the expected output; divided by `+++` and a blank line.
Types of template tests: - expected output starting with `ERR:` indicate that expected output is an error message - expected output starting with `OUTPUT POSITION:` indicate that expected output is "pos" format - otherwise expected output is the literal output from template
For example:
#! my-test.tpltest --- #@ msg = "hello" msg: #@ msg +++ msg: hello
func (FileTests) DefaultEvalTemplate ¶
func (f FileTests) DefaultEvalTemplate(src string) (MarshalableResult, *TestErr)
DefaultEvalTemplate evaluates the YAML template "src"
func (FileTests) Run ¶
Run runs each tests: enumerates each file within FileTests.PathToTests; splits and evaluates using FileTests.EvalFunc optionally supplying FileTests.DataValues to that evaluation.
If an error occurs and FileTests.ShowTemplateCode is set, then the output includes the debug output of the template.
type MarshalableResult ¶
MarshalableResult is a template evaluation result that can be (likely) marshaled into a slice of bytes.