test

package
v0.6.0-alpha-benchmark Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package test provides some utilities for construct test files. * Debugf provides a simplistic logging for use in test cases. * Case defines test cases stored in JSON files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugLevel

func DebugLevel() uint

DebugLevel returns the level set by the -debug flag or 0 for default.

func Debugf

func Debugf(level uint, format string, args ...interface{})

Debugf will only print the specified data if the -debug command flag is set. The level field determines whether the statement will be printed. The -debug flag must be greater than or equal to the specified level for printing.

func Files

func Files(t *testing.T, dir string) []string

Files returns a list of file names found in the 'test' subdirectory of the specified directory. If the directory is not provided (the string is empty) then 'testdata' is used.

func Load

func Load(t *testing.T, dir string, file string, tc Case)

Load reads a test case JSON file and unmarshals it into the provided Case instantiation. The pathname is constructed from the named file in the 'test' subdirectory of the specified directory:

<dir>/test/<file>

If the directory is not provided (the string is empty) then 'testdata' is used.

Types

type BasicCase

type BasicCase struct {
	BasicName   string `json:"Description"`
	BasicSource string `json:"Source"`
	// contains filtered or unexported fields
}

BasicCase provides the common test definition items and methods. Compose the specific test case struct with this struct to inherit. Normally the BasicName and BasicSource fields would be private, but they can't be because of the JSON unmarshaler. Do not reference them externally.

func (*BasicCase) Name

func (bc *BasicCase) Name() string

Name returns the test case name.

func (*BasicCase) Source

func (bc *BasicCase) Source(t *testing.T) string

Source returns the test case source string. If the Source field was empty the data will be loaded from The pathname constructed from the named file in the 'json' subdirectory of the specified directory:

<dir>/json/<file>

where the dir was specified in the preceding Load call and saved to the basic test case struct.

type Case

type Case interface {
	Name() string

	Source(t *testing.T) string
	// contains filtered or unexported methods
}

Case defines an interface for test case definitions. The interface provides functions to access common data items. Cases are read from JSON files in 'test' subdirectory of the specified test directory. The JSON files must contain the following common fields:

Description                   test name
Source                 test source string

If the Source field is empty the test file name is used to read the source data from a JSON file in the 'json' subdirectory of the specified test directory.

type CountWriter

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

CountWriter is an io.Writer that throws away all input but counts `Write` calls and the number of bytes that would have been written. This is used during benchmarking.

func (*CountWriter) Bytes

func (cw *CountWriter) Bytes() uint64

Bytes returns the number of bytes that the `CountWriter` ignored.

func (*CountWriter) Write

func (cw *CountWriter) Write(p []byte) (n int, err error)

Write supplies the required io.Writer interface method.

func (*CountWriter) Written

func (cw *CountWriter) Written() uint64

Written returns the number of `Write` calls that the `CountWriter` ignored.

Jump to

Keyboard shortcuts

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