testhelper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package offers some helper functions to make easier to write unit tests with iterators and maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrIs

func AssertErrIs(t TestingT, err error, target error, msg string)

func AssertErrNil

func AssertErrNil(t TestingT, err error, msg string)

func AssertErrNotNil

func AssertErrNotNil(t TestingT, err error, msg string)

func ValidateIterator

func ValidateIterator[K comparable, V comparable](t TestingT, it omap.OMapIterator[K, V], isOrdered bool, expResults []KeyValue[K, V]) bool

func ValidateIteratorBackward

func ValidateIteratorBackward[K comparable, V comparable](t TestingT, it omap.OMapIterator[K, V], shouldBeInvalidAtEnd bool, expResults []KeyValue[K, V]) bool

func ValidateIteratorForward

func ValidateIteratorForward[K comparable, V comparable](t TestingT, it omap.OMapIterator[K, V], isOrdered bool, expResults []KeyValue[K, V]) bool

Types

type KeyValue

type KeyValue[K comparable, V comparable] struct {
	Key   K
	Value V
}

func JsonToKV

func JsonToKV[K comparable, V comparable](in string) []KeyValue[K, V]

Convert a JSON array in form of `[[key1, val1], [key2, val2], ...]` to []KeyValue[K, V]. Returns nil in case of error, since validator functions will treat this specifically. One can use JsonToKVErr to debug the actual error. Notice: this function is intentionally designed to be short to build a []KeyValue from a hard-coded constant, so it is not well designed to be safe nor fast.

func JsonToKVErr

func JsonToKVErr[K comparable, V comparable](in string) ([]KeyValue[K, V], error)

func SlicesToKeyValue

func SlicesToKeyValue[K comparable, V comparable](keys []K, values []V) []KeyValue[K, V]

type TestingErrorsMock

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

func (*TestingErrorsMock) Errorf

func (tm *TestingErrorsMock) Errorf(format string, args ...any)

func (*TestingErrorsMock) Helper

func (tm *TestingErrorsMock) Helper()

func (*TestingErrorsMock) Reset

func (tm *TestingErrorsMock) Reset()

func (*TestingErrorsMock) Validate

func (tm *TestingErrorsMock) Validate(t *testing.T, expectedErrors ...string)

type TestingT

type TestingT interface {
	Helper()
	Errorf(format string, args ...any)
}

Jump to

Keyboard shortcuts

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