testutil

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Driver = "sqlite"

Variables

This section is empty.

Functions

func AssertIterResult

func AssertIterResult[T any](t *testing.T, want []TestResult[T], got iter.Seq2[T, error])

AssertIterResult checks if the iterator returns the expected values.

func CollectFiles

func CollectFiles(t *testing.T, fsys fs.FS) (ret map[string]FileInfo)

CollectFiles returns a map of file paths to file info.

func GZCompress

func GZCompress(t *testing.T, data []byte) []byte

GZCompress compresses data using gzip and returns the compressed data.

func IterVal2Iter

func IterVal2Iter[T, U any](s []IterVal[T, U]) iter.Seq2[T, U]

func MarshalJSON

func MarshalJSON(t *testing.T, v any) []byte

MarshalJSON marshals data to JSON and returns the byte slice.

func PrepareTestDirectory

func PrepareTestDirectory(t *testing.T, fsys fs.FS) string

PrepareTestDirectory prepares a temporary directory for testing and populates it with files from fsys. It returns the path to the directory.

func Ptr

func Ptr[T any](v T) *T

func Slice2Seq2

func Slice2Seq2[T any](s []T) iter.Seq2[T, error]

func TestDB

func TestDB(t *testing.T) *sqlx.DB

func TestDBDSN

func TestDBDSN(t *testing.T, dsn string) *sqlx.DB

func TestPersistentDB

func TestPersistentDB(t *testing.T) *sqlx.DB

func ToIter

func ToIter[T any](v []TestResult[T]) iter.Seq2[T, error]

ToIter converts a slice of testResult to an iter.Seq2.

Types

type FileInfo

type FileInfo struct {
	Name string
	Size int64
}

type IterVal

type IterVal[T, U any] struct {
	T T
	U U
}

func Seq2Collect

func Seq2Collect[T, U any](it iter.Seq2[T, U]) (ret []IterVal[T, U])

type TestResult

type TestResult[T any] struct {
	V   T
	Err error
}

TestResult is a pair of value and error to use in the test iterators.

func Collect

func Collect[T any](t *testing.T, it iter.Seq2[T, error]) []TestResult[T]

Collect collects the values from the iterator into a slice of TestResult.

func SliceToTestResult

func SliceToTestResult[E any, T []E](t T) []TestResult[E]

SliceToTestResult converts a slice of values to a slice of TestResult.

func ToTestResult

func ToTestResult[T any](v T, err error) TestResult[T]

Jump to

Keyboard shortcuts

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