testrunner

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: GPL-2.0 Imports: 19 Imported by: 0

README

GoDoc Go Report Card

go-testrunner - Test harness for script driven tests

What is it?

A library to simplify writing golang tests that act on files and directories. This library was written to help simplify testing for go-fio's cmp module. Many of the commands are specifically for the go-fio module.

How do I use it?

This library implements common script commands:

  • mkfile: Make a file or dir in the test dir; usage:

    mkfile [options] name [name...]

    The optional arguments are:

    -m X | --min-file-size X Make files at least as big X -M Y | --max-file-size Y Make files no bigger than Y -d | --dir Make directories instead of files -t WhERE | --target WhERE Make dirs in 'lhs', 'rhs' or 'both

  • touch: Sync the timestamps of all dirs and files to be the same. The time of start of test is used as the singular reference timestamp.

  • mutate: modify one or more files

    mutate name [name ...]

  • symlink: make one or more symlinks in lhs or rhs or both

    symlink lhs="newname@oldname new2@old2" rhs="newname@oldname"

    Where lhs= and rhs= denote the target where this is made

How can I extend it?

Take a look at go-fio/cmp; this module extends the commands by adding the expect command:

  • Implements the testrunnner.Cmd interface
  • Register the command with testrunner by calling testrunner.RegisterCommand() from a init() function.

Implementation Notes

License

GPL v2.0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func DirExists

func DirExists(dn string) (bool, error)

Return true if dir exists, false otherwise Wot a complicated way to do things in golang!

func FileExists

func FileExists(dn string) (bool, error)

Return true if file exists, false otherwise Wot a complicated way to do things in golang!

func RegisterCommand

func RegisterCommand(cmd Cmd)

Register a test-harness command; called by init() functions in the cmd_xxx.go files.

func Split

func Split(s string) (string, []string, error)

split a string of the form key="a b c" and return

<key, []{a, b, c}>

Types

type Cmd

type Cmd interface {
	Run(e *TestEnv, args []string) error
	Name() string
}

a command is an executor of one of the test-harness commands.

type Config

type Config struct {
	Tempdir string

	LogStdout bool
	Ncpu      int
}

type SizeValue

type SizeValue uint64

func NewSizeValue

func NewSizeValue() *SizeValue

func (*SizeValue) Set

func (v *SizeValue) Set(s string) error

func (*SizeValue) String

func (v *SizeValue) String() string

func (*SizeValue) Type

func (v *SizeValue) Type() string

func (*SizeValue) Value

func (v *SizeValue) Value() uint64

type TestEnv

type TestEnv struct {
	Lhs string
	Rhs string

	TestRoot string
	TestName string

	Log logger.Logger

	// number of concurrenct cpus to use
	Ncpu int

	Start time.Time
}

TestEnv captures the runtime environment of the current testsuite

func (*TestEnv) String

func (t *TestEnv) String() string

type TestRunner

type TestRunner struct {
	Config
}

func New

func New(c *Config) *TestRunner

func (*TestRunner) Run

func (tr *TestRunner) Run(args []string, par bool) error

func (*TestRunner) RunOne

func (tr *TestRunner) RunOne(fn string) error

Jump to

Keyboard shortcuts

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