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
- Variables
- func BodyFilepath(dir string) (string, error)
- func CompareCommits(expect, got *dataset.Commit, opts ...CompareOpts) string
- func CompareDatasets(expect, got *dataset.Dataset, opts ...CompareOpts) string
- func CompareGoldenDatasetAndUpdateIfEnvVarSet(t *testing.T, goldenFilepath string, got *dataset.Dataset)
- func CompareMetas(expect, got *dataset.Meta, opts ...CompareOpts) string
- func CompareStructures(expect, got *dataset.Structure, opts ...CompareOpts) string
- func DatasetChecksum(ds *dataset.Dataset) string
- func LoadGoldenFile(t *testing.T, filename string) *dataset.Dataset
- func LoadTestCases(dir string) (tcs map[string]TestCase, err error)
- func ReadBodyData(dir string) ([]byte, string, error)
- func ReadDataset(dir, filename string) (*dataset.Dataset, error)
- func ReadInputReadmeScript(dir string) ([]byte, string, error)
- func ReadInputTransformScript(dir string) ([]byte, string, error)
- func ReadInputVizScript(dir string) ([]byte, string, error)
- func Template(t *testing.T, tmplStr string, data interface{}) string
- func UpdateGoldenFileIfEnvVarSet(filename string, got *dataset.Dataset)
- type CompareConfig
- type CompareOpts
- type OptDropTransientValues
- type TestCase
Constants ¶
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" )
const UpdateGoldenFileEnvVarname = "QRI_UPDATE_GOLDEN_FILES"
UpdateGoldenFileEnvVarname is the envionment variable that dstest checks before writing
Variables ¶
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 ¶
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 ¶
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
LoadGoldenFile loads a dataset from a JSON file
func LoadTestCases ¶
LoadTestCases loads a directory of case directories
func ReadBodyData ¶
ReadBodyData grabs input data
func ReadDataset ¶
ReadDataset grabs a dataset for a given dir for a given filename
func ReadInputReadmeScript ¶ added in v0.3.0
ReadInputReadmeScript grabs input readme script bytes
func ReadInputTransformScript ¶
ReadInputTransformScript grabs input transform bytes
func ReadInputVizScript ¶
ReadInputVizScript grabs input viz script bytes
func Template ¶ added in v0.3.0
Template executes & returns a template string, failing the test if the template fails to compile
func UpdateGoldenFileIfEnvVarSet ¶ added in v0.3.0
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
func (OptDropTransientValues) Apply(cfg *CompareConfig)
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 ¶
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) ReadmeScriptFile ¶ added in v0.3.0
ReadmeScriptFile creates a qfs.File from testCase readme script data
func (TestCase) RenderedFile ¶
RenderedFile returns a qfs.File of the rendered file if one exists
func (TestCase) TransformScriptFile ¶
TransformScriptFile creates a qfs.File from testCase transform script data