difftests

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package difftests provides utilities for writing tests that compare against golden output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestCase

type TestCase struct {
	Name string
	// contains filtered or unexported fields
}

TestCase provides methods load and save data for a diff test.

func DiscoverTestCases

func DiscoverTestCases(t *testing.T, root string) []TestCase

DiscoverTestCases discovers test cases for expectation tests.

DiscoverTestCases assumes the following filesystem layout under `root`: - Input files, named ${root}/**/*.input, contain the input protobuf payload. - Golden files are named correspondingly ${root}/**/*.golden

Golden files may be missing in some cases, and will be created by the UpdateGoldenIfRequested() method on TestCase.

func (*TestCase) LoadGolden

func (tc *TestCase) LoadGolden(t *testing.T) (contents []string, loaded bool)

LoadGolden loads the golden file for a test case.

Failures to load golden file contents reported as non-fatal errors so that the golden file can be updated later.

Callers should skip TestCases where golden file can not be loaded.

func (*TestCase) LoadInput

func (tc *TestCase) LoadInput(t *testing.T, outM proto.Message)

LoadInput loads the input payload for the test case into the provided protobuf message.

func (*TestCase) UpdateGoldenIfRequested

func (tc *TestCase) UpdateGoldenIfRequested(t *testing.T, data []string)

UpdateGoldenIfRequested updates the golden file for a test case.

Golden file updates can be enabled from the command line by setting the -update-lint-golden-files flag.

Jump to

Keyboard shortcuts

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