Documentation ¶
Overview ¶
Package utils contains a collection of utility functions that can be used throughout the Go application.
Index ¶
- func AddInfoIfErr(err error, info ...string) error
- func Panics(doesItPanic func()) (panics bool)
- func RunSingleArgumentTestCases[T, R any](t *testing.T, testName string, runFn func(T) R, ...)
- func RunThreeArgumentTestCases[T, U, V, R any](t *testing.T, testName string, runFn func(T, U, V) R, ...)
- func RunTwoArgumentTestCases[T, U, R any](t *testing.T, testName string, runFn func(T, U) R, ...)
- func TestingSlicesEqualWithoutOrder[R any](a, b []R) bool
- type GenericTestCase
- type GenericTestCaseWithNoWant
- type Option
- type Result
- func (w *Result[V]) AddInfoIfErr(info ...string) bool
- func (w *Result[V]) Destruct() (V, error)
- func (w *Result[V]) FailTestIfErr(t *testing.T)
- func (w *Result[V]) FailTestIfErrf(t *testing.T, format string, args ...interface{})
- func (w *Result[V]) FailTestIfOk(t *testing.T)
- func (w *Result[V]) FailTestIfOkf(t *testing.T, format string, args ...interface{})
- func (w *Result[V]) IsErr() bool
- func (w *Result[V]) IsOk() bool
- func (w *Result[V]) Msg() string
- func (w *Result[V]) Unwrap() V
- func (w *Result[V]) UnwrapOr(defaultValue V) V
- type SingleArgumentTestCasesArgsType
- type ThreeArgumentTestCasesArgsType
- type TwoArgumentTestCasesArgsType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddInfoIfErr ¶
AddInfoIfErr adds info to the error that is passed in.
func Panics ¶
func Panics(doesItPanic func()) (panics bool)
Panics returns true if the provided function panics. Source: https://www.reddit.com/r/golang/comments/2tj8b3/comment/cnzy3kc
func RunSingleArgumentTestCases ¶
func RunSingleArgumentTestCases[T, R any]( t *testing.T, testName string, runFn func(T) R, testCases []GenericTestCase[SingleArgumentTestCasesArgsType[T], R], )
RunSingleArgumentTestCases runs a sets of test cases for a function that takes a single argument.
func RunThreeArgumentTestCases ¶
func RunThreeArgumentTestCases[T, U, V, R any]( t *testing.T, testName string, runFn func(T, U, V) R, testCases []GenericTestCase[ThreeArgumentTestCasesArgsType[T, U, V], R], )
RunThreeArgumentTestCases runs a sets of test cases for a function that takes three arguments.
func RunTwoArgumentTestCases ¶
func RunTwoArgumentTestCases[T, U, R any]( t *testing.T, testName string, runFn func(T, U) R, testCases []GenericTestCase[TwoArgumentTestCasesArgsType[T, U], R], )
RunTwoArgumentTestCases runs a sets of test cases for a function that takes two arguments.
func TestingSlicesEqualWithoutOrder ¶ added in v0.12.1
TestingSlicesEqualWithoutOrder checks whether two slices are equal without order. Used for slices where order is not important or not defined, e.g. maps, sets, random samples.
Types ¶
type GenericTestCase ¶
GenericTestCase is a generic test case.
type GenericTestCaseWithNoWant ¶
GenericTestCaseWithNoWant is a generic test case with an option want.
type Option ¶ added in v0.9.0
type Option[V any] struct { Value *V }
Option is a wrapper around a value that can be nil.
func (Option[V]) Unwrap ¶ added in v0.9.0
func (o Option[V]) Unwrap() V
Unwrap returns the value of the Option or panics.
func (Option[V]) UnwrapOr ¶ added in v0.9.0
func (o Option[V]) UnwrapOr(defaultValue V) V
UnwrapOr returns the value of the Option or the provided default value.
func (Option[V]) UnwrapOrElse ¶ added in v0.9.0
func (o Option[V]) UnwrapOrElse(f func() V) V
UnwrapOrElse returns the value of the Option or the result of the provided function.
type Result ¶ added in v0.9.0
func NewResultWithIgnoredErrs ¶ added in v0.9.0
NewResultWithIgnoredErrs returns a new Result with the given value and error.
func (*Result[V]) AddInfoIfErr ¶ added in v0.9.0
AddInfoIfErr adds info to the error if Error is not nil. Returns true if the result contained an error.
func (*Result[V]) FailTestIfErr ¶ added in v0.9.0
FailTestIfErr fails the test if the Result is an error.
func (*Result[V]) FailTestIfErrf ¶ added in v0.9.0
func (*Result[V]) FailTestIfOk ¶ added in v0.9.0
FailTestIfOk fails the test if the Result is ok.
func (*Result[V]) FailTestIfOkf ¶ added in v0.9.0
type SingleArgumentTestCasesArgsType ¶
type SingleArgumentTestCasesArgsType[T any] struct { A T }
SingleArgumentTestCasesArgsType is the type of the arguments for a single argument test case.
type ThreeArgumentTestCasesArgsType ¶
type ThreeArgumentTestCasesArgsType[T, U, V any] struct { A T B U C V }
ThreeArgumentTestCasesArgsType is the type of the arguments for a three argument test case.
type TwoArgumentTestCasesArgsType ¶
type TwoArgumentTestCasesArgsType[T, U any] struct { A T B U }
TwoArgumentTestCasesArgsType is the type of the arguments for a two argument test case.