dstest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 19 Imported by: 1

Documentation

Overview

Package dstest defines an interface for reading test cases from static files leveraging directories of test dataset input files & expected output files

Index

Constants

View Source
const (
	// InputDatasetFilename is the filename to use for an input dataset
	InputDatasetFilename = "input.dataset.json"
	// ExpectDatasetFilename is the filename to use to compare expected outputs
	ExpectDatasetFilename = "expect.dataset.json"
	// RenderedFilename is the file that represents an executed viz script
	RenderedFilename = "rendered.html"
)
View Source
const UpdateGoldenFileEnvVarname = "QRI_UPDATE_GOLDEN_FILES"

UpdateGoldenFileEnvVarname is the envionment variable that dstest checks before writing

Variables

View Source
var (
	// PrivKey is a predefined private key for use in tests
	PrivKey crypto.PrivKey
	// PrivKeyPeerID is the base58-encoded multihash of PrivKey.PublicKey
	PrivKeyPeerID = "QmZePf5LeXow3RW5U1AgEiNbW46YnRGhZ7HPvm1UmPFPwt"
)

Functions

func BodyFilepath

func BodyFilepath(dir string) (string, error)

BodyFilepath retuns the path to the first valid data file it can find, which is a file named "data" that ends in an extension we support

func CompareCommits added in v0.3.0

func CompareCommits(expect, got *dataset.Commit, opts ...CompareOpts) string

CompareCommits is CompareDatasets, but for commit components

func CompareDatasets added in v0.3.0

func CompareDatasets(expect, got *dataset.Dataset, opts ...CompareOpts) string

CompareDatasets checks two given datasets for equality, returng a diff string describing the difference between each dataset/ return will be the empty string if datasets are equal CompareDatasets defaults to a strict compraison of all exported fields operates on copies of passed-in datasets to keep this function free of side effects

func CompareGoldenDatasetAndUpdateIfEnvVarSet added in v0.3.0

func CompareGoldenDatasetAndUpdateIfEnvVarSet(t *testing.T, goldenFilepath string, got *dataset.Dataset)

CompareGoldenDatasetAndUpdateIfEnvVarSet is a convenience wrapper for the common case of loading a golden file, comparing it to a dataset, and updating the dataset if it fails and the "update" enviornment variable is set

func CompareMetas added in v0.3.0

func CompareMetas(expect, got *dataset.Meta, opts ...CompareOpts) string

CompareMetas is CompareDatasets, but for meta components

func CompareStructures added in v0.3.0

func CompareStructures(expect, got *dataset.Structure, opts ...CompareOpts) string

CompareStructures is CompareDatasets, but for structure components

func DatasetChecksum

func DatasetChecksum(ds *dataset.Dataset) string

DatasetChecksum generates a fast, insecure hash of an encoded dataset, useful for checking that expected dataset values haven't changed

func LoadGoldenFile added in v0.3.0

func LoadGoldenFile(t *testing.T, filename string) *dataset.Dataset

LoadGoldenFile loads a dataset from a JSON file

func LoadTestCases

func LoadTestCases(dir string) (tcs map[string]TestCase, err error)

LoadTestCases loads a directory of case directories

func ReadBodyData

func ReadBodyData(dir string) ([]byte, string, error)

ReadBodyData grabs input data

func ReadDataset

func ReadDataset(dir, filename string) (*dataset.Dataset, error)

ReadDataset grabs a dataset for a given dir for a given filename

func ReadInputReadmeScript added in v0.3.0

func ReadInputReadmeScript(dir string) ([]byte, string, error)

ReadInputReadmeScript grabs input readme script bytes

func ReadInputTransformScript

func ReadInputTransformScript(dir string) ([]byte, string, error)

ReadInputTransformScript grabs input transform bytes

func ReadInputVizScript

func ReadInputVizScript(dir string) ([]byte, string, error)

ReadInputVizScript grabs input viz script bytes

func Template added in v0.3.0

func Template(t *testing.T, tmplStr string, data interface{}) string

Template executes & returns a template string, failing the test if the template fails to compile

func UpdateGoldenFileIfEnvVarSet added in v0.3.0

func UpdateGoldenFileIfEnvVarSet(filename string, got *dataset.Dataset)

UpdateGoldenFileIfEnvVarSet overwrites the given filename if QRI_UPDATED_GOLDEN_FILES env var is set

Types

type CompareConfig added in v0.3.0

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

CompareConfig defines configuration parameters, which are unexported, but settable via CompareOpt's supplied ot a Compare function

type CompareOpts added in v0.3.0

type CompareOpts interface {
	Apply(cfg *CompareConfig)
}

CompareOpts adusts component comparison functions

type OptDropTransientValues added in v0.3.0

type OptDropTransientValues int

OptDropTransientValues drops transients on both dataset before making the comparison, allowing things like dataset name &

func (OptDropTransientValues) Apply added in v0.3.0

Apply sets unexported configuration

type TestCase

type TestCase struct {
	// Path to the director on the local filesystem this test case is loaded from
	Path string
	// Name is the casename, should match directory name
	Name string
	// body.csv,body.json, etc
	BodyFilename string
	// test body in expected data format
	Body []byte
	// Filename of Transform Script
	TransformScriptFilename string
	// TransformScript bytes if one exists
	TransformScript []byte
	// Filename of Viz Script
	VizScriptFilename string
	// VizScript bytes if one exists
	VizScript []byte
	// Filename of Readme Script
	ReadmeScriptFilename string
	// ReadmeScript bytes is one exists
	ReadmeScript []byte
	// Input is intended file for test input
	// loads from input.dataset.json
	Input *dataset.Dataset
	//  Expect should match test output
	// loads from expect.dataset.json
	Expect *dataset.Dataset
}

TestCase is a dataset test case, usually built from a directory of files for use in tests. All files are optional for TestCase, but may be required by the test itself.

func NewTestCaseFromDir

func NewTestCaseFromDir(dir string) (tc TestCase, err error)

NewTestCaseFromDir creates a test case from a directory of static test files dir should be the path to the directory to check, and any parsing errors will be logged using t.Log methods

func (TestCase) BodyFile

func (t TestCase) BodyFile() qfs.File

BodyFile creates a new in-memory file from data & filename properties

func (TestCase) ReadmeScriptFile added in v0.3.0

func (t TestCase) ReadmeScriptFile() (qfs.File, bool)

ReadmeScriptFile creates a qfs.File from testCase readme script data

func (TestCase) RenderedFile

func (t TestCase) RenderedFile() (qfs.File, error)

RenderedFile returns a qfs.File of the rendered file if one exists

func (TestCase) TransformScriptFile

func (t TestCase) TransformScriptFile() (qfs.File, bool)

TransformScriptFile creates a qfs.File from testCase transform script data

func (TestCase) VizScriptFile

func (t TestCase) VizScriptFile() (qfs.File, bool)

VizScriptFile creates a qfs.File from testCase transform script data

Jump to

Keyboard shortcuts

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