local

package
v0.0.0-...-b74a4f7 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GroupFileName is the name of the group script (without the extension)
	GroupFileName = "group"
	// PreTestFileName is the name of a pre-test script (without the extension)
	PreTestFileName = "pre-test"
	// PostTestFileName is the name of a post-test script (without the extension)
	PostTestFileName = "post-test"
	// TestFileName is the name of a test script (without the extension)
	TestFileName = "test"
)
View Source
const (
	// Pass is a test pass
	Pass = iota
	// Fail is a test failure
	Fail
	// Skip is a test skip
	Skip
	// Cancel is a test cancellation
	Cancel
)

Variables

View Source
var TestResultColorFunc = map[TestResult]func(a ...interface{}) string{}

TestResultColorFunc provides a mapping of numerical result values to a fmt.Sprintf() style function

View Source
var TestResultNames = map[TestResult]string{
	Pass:   "Pass",
	Fail:   "Fail",
	Skip:   "Skip",
	Cancel: "Cancel",
}

TestResultNames provides a mapping of numerical result values to human readable strings

Functions

func CheckLabel

func CheckLabel(labels, notLabels map[string]bool, config RunConfig) bool

CheckLabel determines if a group or test should run based on its labels and the RunConfig

func IsGroup

func IsGroup(path string) bool

IsGroup determines if a path contains a group

func IsTest

func IsTest(path string) bool

IsTest determines if a path contains a test or not

func ParseLabels

func ParseLabels(labels string) (map[string]bool, map[string]bool)

ParseLabels constucts a map[string]bool for both positive and negative labels from a comma separated list

func ValidatePattern

func ValidatePattern(args []string) (string, error)

ValidatePattern validates that an arg string is a valid test pattern

Types

type ByOrder

type ByOrder []TestContainer

ByOrder implements the sort.Sorter interface for TestContainer

func (ByOrder) Len

func (a ByOrder) Len() int

Len returns the length of the []TestContainer

func (ByOrder) Less

func (a ByOrder) Less(i, j int) bool

Less compares whether the order of i is less than that of j

func (ByOrder) Swap

func (a ByOrder) Swap(i, j int)

Swap swaps two items in a []TestContainer

type Group

type Group struct {
	Parent        *Group
	Tags          *Tags
	Path          string
	GroupFilePath string
	PreTestPath   string
	PostTestPath  string

	Labels    map[string]bool
	NotLabels map[string]bool
	Children  []TestContainer
	// contains filtered or unexported fields
}

Group is a group of tests and other groups

func NewGroup

func NewGroup(parent *Group, path string) (*Group, error)

NewGroup creates a new Group with the given parent and path

func (*Group) Gather

func (g *Group) Gather(config RunConfig) ([]TestContainer, int)

Gather gathers all runnable child groups and tests

func (*Group) Init

func (g *Group) Init() error

Init is the group initialization function and should be called immediately after a group has been created

func (*Group) LabelString

func (g *Group) LabelString() string

LabelString provides all labels in a comma separated list

func (*Group) List

func (g *Group) List(config RunConfig) []Info

List lists all child groups and tests

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the group

func (*Group) Order

func (g *Group) Order() int

Order returns the order of a group

func (*Group) Run

func (g *Group) Run(config RunConfig) ([]Result, error)

Run will run all child groups and tests

type GroupCommand

type GroupCommand struct {
	Name     string
	Type     string
	FilePath string
	Path     string
}

GroupCommand is a command that is runnable, either a test or pre/post script.

func (GroupCommand) Gather

func (g GroupCommand) Gather(config RunConfig) ([]TestContainer, int)

Gather satisfies the TestContainer interface

func (GroupCommand) List

func (g GroupCommand) List(config RunConfig) []Info

List satisfies the TestContainer interface

func (GroupCommand) Order

func (g GroupCommand) Order() int

Order returns a tests order

func (GroupCommand) Run

func (g GroupCommand) Run(config RunConfig) ([]Result, error)

Run satisfies the TestContainer interface. Run the group init or deinit command.

type Info

type Info struct {
	Name       string
	TestResult TestResult
	Summary    string
	Issue      string
	Labels     map[string]bool
	NotLabels  map[string]bool
}

Info encapsulates the information necessary to list tests and test groups

func (*Info) LabelString

func (i *Info) LabelString() string

LabelString returns all labels in a comma separated string

type OSInfo

type OSInfo struct {
	OS      string
	Version string
	Name    string
	Arch    string
}

OSInfo contains information about the OS the tests are running on

type Project

type Project struct {
	*Group
	// contains filtered or unexported fields
}

Project is a group of tests and other groups with a few higher level functions

func InitNewProject

func InitNewProject(path string) (*Project, error)

InitNewProject creates a new Group, and calls Init() on it

func NewProject

func NewProject(path string) (*Project, error)

NewProject creates a new top-level Group at the provided path

func (*Project) List

func (p *Project) List(config RunConfig) []Info

List lists all child groups and tests, limited by the provided shards

func (*Project) Run

func (p *Project) Run(config RunConfig) ([]Result, error)

Run runs all child groups and tests, limited by the provided shards

func (*Project) SetShard

func (p *Project) SetShard(shard, totalShards int) error

SetShard returns a subset of the group based on the shards

type Result

type Result struct {
	Test            *Test         `json:"-"`
	Name            string        `json:"name,omitempty"` // Name may be different to Test.Name() for repeated tests.
	TestResult      TestResult    `json:"result"`
	BenchmarkResult string        `json:"benchmark,omitempty"`
	StartTime       time.Time     `json:"start,omitempty"`
	EndTime         time.Time     `json:"end,omitempty"`
	Duration        time.Duration `json:"duration,omitempty"`
}

Result encapsulates a TestResult and additional data about a test run

type RunConfig

type RunConfig struct {
	Extra       bool
	CaseDir     string
	LogDir      string
	Logger      logger.LogDispatcher
	SystemInfo  sysinfo.SystemInfo
	Labels      map[string]bool
	NotLabels   map[string]bool
	TestPattern string
	Parallel    bool
	IncludeInit bool
	// contains filtered or unexported fields
}

RunConfig contains runtime configuration information

func NewRunConfig

func NewRunConfig(labels string, pattern string) RunConfig

NewRunConfig returns a new RunConfig from test labels and a pattern

type Summary

type Summary struct {
	ID         string             `json:"id,omitempty"`
	StartTime  time.Time          `json:"start,omitempty"`
	EndTime    time.Time          `json:"end,omitempty"`
	SystemInfo sysinfo.SystemInfo `json:"system,omitempty"`
	Labels     []string           `json:"labels,omitempty"`
	Results    []Result           `json:"results,omitempty"`
}

Summary contains a summary of a whole run, mostly used for writing out a JSON file

type Tags

type Tags struct {
	Name    string `rt:"NAME"`
	Summary string `rt:"SUMMARY"`
	Author  string `rt:"AUTHOR,allowmultiple"`
	Labels  string `rt:"LABELS"`
	Repeat  int    `rt:"REPEAT"`
	Issue   string `rt:"ISSUE,allowmultiple"`
}

Tags are the permitted tags within a test file

func ParseTags

func ParseTags(file string) (*Tags, error)

ParseTags reads the provided file and returns all discovered tags or an error

type Test

type Test struct {
	Parent       *Group
	Tags         *Tags
	Path         string
	TestFilePath string
	Command      exec.Cmd
	Repeat       int

	Summary   string
	Author    string
	Labels    map[string]bool
	NotLabels map[string]bool
	// contains filtered or unexported fields
}

Test is a test

func NewTest

func NewTest(group *Group, path string) (*Test, error)

NewTest creates a new test

func (*Test) Gather

func (t *Test) Gather(config RunConfig) ([]TestContainer, int)

Gather satisfies the TestContainer interface

func (*Test) Init

func (t *Test) Init() error

Init initializes a test and should be run immmediately after NewTest

func (*Test) LabelString

func (t *Test) LabelString() string

LabelString returns all labels in a comma separated string

func (*Test) List

func (t *Test) List(config RunConfig) []Info

List satisfies the TestContainer interface

func (*Test) Name

func (t *Test) Name() string

Name returns the test's name

func (*Test) Order

func (t *Test) Order() int

Order returns a tests order

func (*Test) Run

func (t *Test) Run(config RunConfig) ([]Result, error)

Run runs a test

type TestContainer

type TestContainer interface {
	Order() int
	List(config RunConfig) []Info
	Run(config RunConfig) ([]Result, error)
	Gather(config RunConfig) ([]TestContainer, int)
}

TestContainer is a container that can hold one or more tests

type TestResult

type TestResult int

TestResult is the result of a test run

func (TestResult) Sprintf

func (r TestResult) Sprintf(format string, a ...interface{}) string

Sprintf prints the arguments using fmt.Sprintf but colours it depending on the TestResult

Jump to

Keyboard shortcuts

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