tst

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 7 Imported by: 1

README

tst

Go package for unit testing

Documentation

Overview

Package tst contains unit testing functions and TestCase structs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](t *testing.T, pairs [][2]T, name string, assert assertFn[T])

All checks if all pairs are equal using the assert function

func AllActionPost

func AllActionPost[T HasPostTest](t *testing.T, testCases []T, name string, actionFn func(T))

AllActionPost performs the action for all generic test cases and checks the post-test

func AllCompare1

func AllCompare1[T, R any](t *testing.T, testCases []T, name string, testFn func(T) (R, R), assert assertFn[R])

AllCompare1 tests 1 pair of [actual, want] from the given generic test cases

func AllP1W1

func AllP1W1[I, R any](t *testing.T, testCases []P1W1[I, R], name string, testFn func(I) R, assert assertFn[R])

AllP1W1 tests all P1W1 test cases

func AllP1W2

func AllP1W2[I, R1, R2 any](t *testing.T, testCases []P1W2[I, R1, R2], name string, testFn func(I) (R1, R2), assert1 assertFn[R1], assert2 assertFn[R2])

AllP1W2 tests all P1W2 test cases

func AllP2W1

func AllP2W1[I1, I2, R any](t *testing.T, testCases []P2W1[I1, I2, R], name string, testFn func(I1, I2) R, assert assertFn[R])

AllP2W1 tests all P2W1 test cases

func AllP2W2

func AllP2W2[I1, I2, R1, R2 any](t *testing.T, testCases []P2W2[I1, I2, R1, R2], name string, testFn func(I1, I2) (R1, R2), assert1 assertFn[R1], assert2 assertFn[R2])

AllP2W2 tests all P2W2 test cases

func AllP2W2Pre

func AllP2W2Pre[I1, I2, R1, R2 any](t *testing.T, testCases []P2W2Pre[I1, I2, R1, R2], name string, testFn func(I1, I2) (R1, R2), assert1 assertFn[R1], assert2 assertFn[R2])

AllP2W2Pre tests all P2W2Pre test cases

func AllP2W3Pre

func AllP2W3Pre[I1, I2, R1, R2, R3 any](t *testing.T, testCases []P2W3Pre[I1, I2, R1, R2, R3], name string, testFn func(I1, I2) (R1, R2, R3), assert1 assertFn[R1], assert2 assertFn[R2], assert3 assertFn[R3])

AllP2W3Pre tests all P2W3Pre test cases

func AllP2W4Pre

func AllP2W4Pre[I1, I2, R1, R2, R3, R4 any](t *testing.T, testCases []P2W4Pre[I1, I2, R1, R2, R3, R4], name string, testFn func(I1, I2) (R1, R2, R3, R4), assert1 assertFn[R1], assert2 assertFn[R2], assert3 assertFn[R3], assert4 assertFn[R4])

AllP2W4Pre tests all P2W4Pre test cases

func AllP3W1

func AllP3W1[I1, I2, I3, R any](t *testing.T, testCases []P3W1[I1, I2, I3, R], name string, testFn func(I1, I2, I3) R, assert assertFn[R])

AllP3W1 tests all P3W1 test cases

func AllP3W1Post

func AllP3W1Post[I1, I2, I3, R any](t *testing.T, testCases []P3W1Post[I1, I2, I3, R], name string, testFn func(I1, I2, I3) R, assert assertFn[R])

AllP3W1Post tests all P3W1Post test cases and checks the post-test function

func AllP3W2

func AllP3W2[I1, I2, I3, R1, R2 any](t *testing.T, testCases []P3W2[I1, I2, I3, R1, R2], name string, testFn func(I1, I2, I3) (R1, R2), assert1 assertFn[R1], assert2 assertFn[R2])

AllP3W2 tests all P3W2 test cases

func AllP3W2Pre

func AllP3W2Pre[I1, I2, I3, R1, R2 any](t *testing.T, testCases []P3W2Pre[I1, I2, I3, R1, R2], name string, testFn func(I1, I2, I3) (R1, R2), assert1 assertFn[R1], assert2 assertFn[R2])

AllP3W2Pre tests all P3W2Pre test cases

func AssertDeepEqual

func AssertDeepEqual(t *testing.T, name string, a, b any)

AssertDeepEqual asserts that the two `any` items are deeply equal

func AssertDeepEqualAnd

func AssertDeepEqualAnd(t *testing.T, name string, a, b any, flag1, flag2 bool)

AssertDeepEqualAnd asserts that the two `any` items are deeply equal and the boolean flags are equal

func AssertDeepEqualError

func AssertDeepEqualError(t *testing.T, name string, a, b any, err error, notNil bool)

AssertDeepEqualError asserts that the two `any` items are deeply equal and the error follows notNil flag

func AssertEqual

func AssertEqual[T comparable](t *testing.T, name string, a, b T)

AssertEqual asserts that the two given values are equal

func AssertEqual2

func AssertEqual2[T1, T2 comparable](t *testing.T, name string, a1, b1 T1, a2, b2 T2)

AssertEqual2 asserts that the two pairs of values are all equal

func AssertEqual3

func AssertEqual3[T1, T2, T3 comparable](t *testing.T, name string, a1, b1 T1, a2, b2 T2, a3, b3 T3)

AssertEqual3 asserts that the three pairs of values are all equal

func AssertEqual4

func AssertEqual4[T1, T2, T3, T4 comparable](t *testing.T, name string, a1, b1 T1, a2, b2 T2, a3, b3 T3, a4, b4 T4)

AssertEqual4 asserts that the four pairs of values are all equal

func AssertEqualAnd

func AssertEqualAnd[T comparable](t *testing.T, name string, a, b T, flag1, flag2 bool)

AssertEqualAnd asserts that the two given values are equal and the boolean flags are equal

func AssertEqualAny

func AssertEqualAny(t *testing.T, name string, a, b any)

AssertEqualAny checks if two `any` items are equal

func AssertEqualAnyAnd

func AssertEqualAnyAnd(t *testing.T, name string, a, b any, flag1, flag2 bool)

AssertEqualAnyAnd checks if two `any` items are equal and the boolean flags are equal

func AssertEqualAnyError

func AssertEqualAnyError(t *testing.T, name string, a, b any, err error, notNil bool)

AssertEqualAnyError checks if two `any` items are equal and the error follows notNil flag

func AssertEqualError

func AssertEqualError[T comparable](t *testing.T, name string, a, b T, err error, notNil bool)

AssertEqualError asserts that the two given values are equal and the error follows notNil flag

func AssertError

func AssertError(t *testing.T, name string, err error)

AssertError asserts that the given error is not nil

func AssertFalse

func AssertFalse(t *testing.T, name string, condition bool)

AssertFalse asserts that the given condition is false

func AssertListEqual

func AssertListEqual[S ~[]T, T comparable](t *testing.T, name string, a, b S)

AssertListEqual asserts that the two given lists are equal

func AssertListEqualAnd

func AssertListEqualAnd[S ~[]T, T comparable](t *testing.T, name string, a, b S, flag1, flag2 bool)

AssertListEqualAnd asserts that the two given lists are equal and the boolean flags are equal

func AssertListEqualError

func AssertListEqualError[S ~[]T, T comparable](t *testing.T, name string, a, b S, err error, notNil bool)

AssertListEqualError asserts that the two given lists are equal and the error follows notNil flag

func AssertListMixedEqual

func AssertListMixedEqual[S ~[]T, T comparable](t *testing.T, name string, a, b S)

AssertListMixedEqual asserts that the two given lists are equal, with pointers and nil checks handled

func AssertMapEqual

func AssertMapEqual[M1, M2 ~map[K]V, K, V comparable](t *testing.T, name string, a M1, b M2)

AssertMapEqual asserts that the two given maps are equal

func AssertMapEqualAnd

func AssertMapEqualAnd[M1, M2 ~map[K]V, K, V comparable](t *testing.T, name string, a M1, b M2, flag1, flag2 bool)

AssertMapEqualAnd asserts that the two given maps are equal and the boolean flags are equal

func AssertMapEqualError

func AssertMapEqualError[M1, M2 ~map[K]V, K, V comparable](t *testing.T, name string, a M1, b M2, err error, notNil bool)

AssertMapEqualError asserts that the two given maps are equal and the error follows notNil flag

func AssertNoError

func AssertNoError(t *testing.T, name string, err error)

AssertNoError asserts that the given error is nil

func AssertPanic

func AssertPanic(t *testing.T, name string)

AssertPanic asserts that the end of the function will panic Usage: defer AssertPanic(t, name)

func AssertTrue

func AssertTrue(t *testing.T, name string, condition bool)

AssertTrue asserts that the given condition is true

func Convert

func Convert[T, V any](items []T, convert func(T) V) []V

Convert maps the list of items to a new list using the conversion function

Types

type Conn

type Conn[T any] struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn[T any](items ...T) *Conn[T]

func (*Conn[T]) Begin

func (c *Conn[T]) Begin() (*Tx, error)

func (*Conn[T]) Exec

func (c *Conn[T]) Exec(query string, args ...any) (sql.Result, error)

func (*Conn[T]) Items

func (c *Conn[T]) Items() []T

func (*Conn[T]) PrepExec

func (c *Conn[T]) PrepExec(execFn func([]T) ([]T, error), result sql.Result) func()

func (*Conn[T]) PrepExecReset

func (c *Conn[T]) PrepExecReset(execFn func([]T) ([]T, error), result sql.Result, items ...T) func()

func (*Conn[T]) PrepGroup

func (c *Conn[T]) PrepGroup(testFn func(T) bool, groupFn func([]T) [][]any) func()

func (*Conn[T]) PrepGroupErr

func (c *Conn[T]) PrepGroupErr(testFn func(T) bool, groupFn func([]T) [][]any, rowsErr error) func()

func (*Conn[T]) PrepOne

func (c *Conn[T]) PrepOne(testFn func(T) bool, rowFn func(T) []any) func()

func (*Conn[T]) PrepRow

func (c *Conn[T]) PrepRow(testFn func(T) bool, rowFn func([]T) ([]any, error)) func()

func (*Conn[T]) PrepRows

func (c *Conn[T]) PrepRows(testFn func(T) bool, rowsFn func(T) []any) func()

func (*Conn[T]) PrepRowsErr

func (c *Conn[T]) PrepRowsErr(testFn func(T) bool, rowsFn func(T) []any, rowsErr error) func()

func (*Conn[T]) PrepSortOne

func (c *Conn[T]) PrepSortOne(testFn func(T) bool, rowFn func(T) []any, sortFn func(T, T) int) func()

func (*Conn[T]) PrepSortRows

func (c *Conn[T]) PrepSortRows(testFn func(T) bool, rowsFn func(T) []any, sortFn func(T, T) int, limit int) func()

func (*Conn[T]) Query

func (c *Conn[T]) Query(query string, args ...any) (*Rows, error)

func (*Conn[T]) QueryRow

func (c *Conn[T]) QueryRow(query string, args ...any) *Row

func (*Conn[T]) Reset

func (c *Conn[T]) Reset(items ...T)

func (*Conn[T]) SetError

func (c *Conn[T]) SetError(err error)

type HasPostTest

type HasPostTest interface {
	PostTest() bool
}

type P1W1

type P1W1[I, R any] struct {
	P1 I
	W1 R
}

P1W1 Test case with 1 input, 1 output

func FlipP1W1

func FlipP1W1[I any](testCases []P1W1[I, bool]) []P1W1[I, bool]

FlipP1W1 flips the boolean output flag of the P1W1 test case

type P1W2

type P1W2[I, R1, R2 any] struct {
	P1 I
	W1 R1
	W2 R2
}

P1W2 Test case with 1 input, 2 outputs

type P2W1

type P2W1[I1, I2, R any] struct {
	P1 I1
	P2 I2
	W1 R
}

P2W1 Test case with 2 inputs, 1 output

func FlipP2W1

func FlipP2W1[I1, I2 any](testCases []P2W1[I1, I2, bool]) []P2W1[I1, I2, bool]

FlipP2W1 flips the boolean output flag of the P2W1 test case

type P2W2

type P2W2[I1, I2, R1, R2 any] struct {
	P1 I1
	P2 I2
	W1 R1
	W2 R2
}

P2W2 Test case with 2 inputs, 2 outputs

type P2W2Pre

type P2W2Pre[I1, I2, R1, R2 any] struct {
	Prep func()
	P1   I1
	P2   I2
	W1   R1
	W2   R2
}

P2W2Pre Test Case with 2 inputs, 2 outputs, and a `prepare` step

type P2W3Pre

type P2W3Pre[I1, I2, R1, R2, R3 any] struct {
	Prep func()
	P1   I1
	P2   I2
	W1   R1
	W2   R2
	W3   R3
}

P2W3Pre Test Case with 2 inputs, 3 outputs, and a `prepare` step

type P2W4Pre

type P2W4Pre[I1, I2, R1, R2, R3, R4 any] struct {
	Prep func()
	P1   I1
	P2   I2
	W1   R1
	W2   R2
	W3   R3
	W4   R4
}

P2W4Pre Test Case with 2 inputs, 4 outputs, and a `prepare` step

type P3W1

type P3W1[I1, I2, I3, R any] struct {
	P1 I1
	P2 I2
	P3 I3
	W1 R
}

P3W1 Test case with 3 inputs, 1 output

func FlipP3W1

func FlipP3W1[I1, I2, I3 any](testCases []P3W1[I1, I2, I3, bool]) []P3W1[I1, I2, I3, bool]

FlipP3W1 flips the boolean output flag of the P3W1 test case

type P3W1Post

type P3W1Post[I1, I2, I3, R any] struct {
	P1   I1
	P2   I2
	P3   I3
	W1   R
	Test func() bool
}

P3W1Post Test case with 3 inputs, 1 output, and a post-test

type P3W2

type P3W2[I1, I2, I3, R1, R2 any] struct {
	P1 I1
	P2 I2
	P3 I3
	W1 R1
	W2 R2
}

P3W2 Test case with 3 inputs, 2 outputs

type P3W2Pre

type P3W2Pre[I1, I2, I3, R1, R2 any] struct {
	Prep func()
	P1   I1
	P2   I2
	P3   I3
	W1   R1
	W2   R2
}

P3W2Pre Test case with 3 inputs, 2 outputs, and a `prepare` step

type Result

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

func NewResult

func NewResult(rowsAffected, lastInsertID int, err error) *Result

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

type Row

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

func NewRow

func NewRow(items ...any) *Row

func (*Row) Scan

func (r *Row) Scan(fieldRefs ...any) (err error)

type Rows

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

func NewRows

func NewRows(items ...[]any) *Rows

func (*Rows) Close

func (r *Rows) Close() error

func (*Rows) Err

func (r *Rows) Err() error

func (*Rows) Next

func (r *Rows) Next() bool

func (*Rows) Scan

func (r *Rows) Scan(fieldRefs ...any) (err error)

func (*Rows) SetError

func (r *Rows) SetError(err error)

type Tx

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

func NewTx

func NewTx() *Tx

func NewTxFrom

func NewTxFrom(result sql.Result, err error) *Tx

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) Exec

func (t *Tx) Exec(query string, args ...any) (sql.Result, error)

func (*Tx) Rollback

func (t *Tx) Rollback() error

func (*Tx) SetError

func (t *Tx) SetError(err error)

func (*Tx) SetResult

func (t *Tx) SetResult(result sql.Result)

Jump to

Keyboard shortcuts

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