kit

package
v0.0.0-...-6e51ac9 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileConflictName - filename conflict with test data.
	ErrFileConflictName = errors.New("filename conflict with test data")
	// ErrFileNotFound - must be at least one test.
	ErrFileNotFound = errors.New("file not found")
	// ErrNotFoundTestData - not found test data.
	ErrNotFoundTestData = errors.New("not found test data")
	// ErrParsing - json parsing error.
	ErrParsing = errors.New("json parsing error")
	// ErrNotSupportingImplementation - not supporting implementation.
	ErrNotSupportingImplementation = errors.New("not supporting implementation")
)

Parse errors.

Functions

func LoadTests

func LoadTests[D any](fs embed.FS, path string) (tests []D, err error)

LoadTests - parser test data_assistant from JSON by path.

func MustLoadTests

func MustLoadTests[T any](fs embed.FS, path string) (tests []T)

MustLoadTests - must parser test data_assistant from JSON by path.

func RequireRun

func RequireRun[T testing.TB, D TestData](t T, fs embed.FS, runner func(t T, data D))

RequireRun - .

func RequireRunWithAddons

func RequireRunWithAddons[T testing.TB, D TestData](t T, fs embed.FS, addons []Addon, runner func(t T, data D))

RequireRunWithAddons - .

func Run

func Run[T testing.TB, D TestData](t T, fs embed.FS, runner func(t T, data D)) error

Run - .

func RunWithAddons

func RunWithAddons[T testing.TB, D TestData](t T, fs embed.FS, addons []Addon, runner func(t T, data D)) error

RunWithAddons - .

Types

type Addon

type Addon interface {
	Start() error
	io.Closer
}

Addon - interface for addon matching. The addon allows you to enable add-ons that will finish their work along with test processing.

type Empty

type Empty struct{}

Empty - placeholder in case there is no return value.

func (Empty) Error

func (Empty) Error() string

type In

type In[A any] struct {
	// Args - can use a query model/structure with a struct (if multiple results are required).
	Args A `json:"args"`
}

In - unified in test format.

type Out

type Out[R any, E error] struct {
	// Result - can use a query model/structure with a struct (if multiple results are required).
	Result R `json:"result"`
	// Error - returned error.
	// * Note: for the base case use the standard error interface.
	Error E `json:"error"`
}

Out - for the case when a function returns only two values: the result itself and an error, it is best to use this composition.

func (*Out[R, E]) UnmarshalJSON

func (o *Out[R, E]) UnmarshalJSON(raw []byte) error

UnmarshalJSON - implementation json unmarshal interface.

type Test

type Test[I, O any] struct {
	// Title - allows you to set a short title that can be easily found when needed.
	Title string `json:"title"`
	// Description - allows you to add an extended description for the test (improves the readability of tests).
	Description string `json:"description"`
	// Arguments - can use a query model/structure with a struct (if multiple arguments are required).
	// * Note: use kit.In, kit.Empty  as a base solution.
	// * Can be replaced with any custom solution.
	In I `json:"in"`
	// Results - expected results.
	// * Note: use kit.Out as a base solutions.
	// * Can be replaced with any custom solution.
	Out O `json:"out"`
}

Test - unified test format.

func (Test[I, O]) TestName

func (t Test[I, O]) TestName() string

TestName - function to get test name.

type TestData

type TestData interface {
	TestName() string
}

TestData - interface that determines whether an entity is a test.

Jump to

Keyboard shortcuts

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