testutils

package
v0.0.0-...-fe5df96 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ObjectsMap

func ObjectsMap(objects ...ast.Object) *orderedmap.Map[string, ast.Object]

func TrimSpacesDiffComparator

func TrimSpacesDiffComparator(t *testing.T, expectedContent []byte, gotContent []byte, filename string)

TrimSpacesDiffComparator compares the content of two files after trimming leading and trailing spaces.

Types

type FileComparator

type FileComparator func(t *testing.T, expectedContent []byte, gotContent []byte, filename string)

type GoldenFilesTestSuite

type GoldenFilesTestSuite struct {
	// Run the test suite on this directory.
	TestDataRoot string

	// Name is a unique name for this test. The golden files for this test are
	// expected to live under `${TestDataRoot}/[test]/${Name}`.
	Name string

	// Skip is a map of tests to skip; the key is the test name; the value is the
	// skip message.
	Skip map[string]string

	// FileComparator is called to compare a golden file with its test-generated equivalent.
	// TrimSpacesDiffComparator is used if no comparator is provided.
	FileComparator FileComparator
}

A GoldenFilesTestSuite represents a test run that processes inputs from a given directory and compares results against "golden files". See the Test documentation for more details.

func (*GoldenFilesTestSuite) Run

func (x *GoldenFilesTestSuite) Run(t *testing.T, f func(tc *Test))

Run runs tests defined in `x.TestDataRoot`.

type Test

type Test struct {
	// Allow Test to be used as a T.
	*testing.T

	// RootDir is the path of the current test directory.
	RootDir string

	// OutputDir is the path where golden files live for this test.
	OutputDir string
	// contains filtered or unexported fields
}

A Test represents a single test.

A Test embeds *testing.T and should be used to report errors.

When the test function has returned, output written with [Test.Write], [Test.Writer], Test.WriteFile and friends is checked against the expected output files.

If the output differs and $COG_UPDATE_GOLDEN is non-empty, the txtar file will be updated and written to disk with the actual output data replacing the out files.

func (*Test) BuildersContext

func (t *Test) BuildersContext() common.Context

BuildersContext locates and returns the builders intermediate representation described within the txtar archive.

func (*Test) TypesIR

func (t *Test) TypesIR() *ast.Schema

TypesIR locates and returns the raw types intermediate representation described within the txtar archive.

func (*Test) WriteFile

func (t *Test) WriteFile(f *codejen.File)

WriteFile writes a codejen.File to the main output.

func (*Test) WriteFiles

func (t *Test) WriteFiles(files codejen.Files)

WriteFiles writes a list of codejen.File to the main output.

Jump to

Keyboard shortcuts

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