dstest

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

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"
)

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 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 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 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

Types

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
	// 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) 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