stenciltest

package
v1.28.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package stenciltest contains code for testing templates

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is a template that is being tested by the stenciltest framework.

func New

func New(t *testing.T, templatePath string, additionalTemplates ...string) *Template

New creates a new test for a given template.

func (*Template) Args

func (t *Template) Args(args map[string]interface{}) *Template

Args sets the arguments to the template.

func (*Template) ErrorContains

func (t *Template) ErrorContains(msg string)

ErrorContains denotes that this test run should fail, and the message should contain the provided string.

t.ErrorContains("i am an error")

func (*Template) Ext added in v1.20.0

func (t *Template) Ext(name string, ext apiv1.Implementation) *Template

Ext registers an in-proc extension with the current stencil template. The stenciltest library does not load the real extensions (because extensions can invoke outbound network calls). It is up to the unit test to provide each extension used by their template with this API. Unit tests can decide if they can use the real implementation of the extension AS IS or if a mock extension is needed to feed fake data per test case.

Note: even though input extension is registered inproc, its response to ExecuteTemplateFunction will be encoded as JSON and decoded back as a plain inteface{} to simulate the GRPC transport layer between stencil and the same extension. Refer to the inprocExt struct docs for details.

func (*Template) Run

func (t *Template) Run(save bool)

Run runs the test.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL