unique

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRetryable = errors.New("cannot create unique value but retryable")

ErrRetryable indicates that the generation of a unique value has temporarily failed, but may succeed by retrying.

Functions

func StringFunc

func StringFunc(n int) func() (string, error)

StringFunc is an n-digit random string generator. It uses upper/lower case alphanumeric characters.

Types

type Option

type Option interface {
	option.Interface
	// contains filtered or unexported methods
}

func WithBeacon

func WithBeacon(storeName string) Option

WithBeacon configures Unique to integrate with a starting beacon server. It enables us to generate unique values through all tests that reference the same beacon server and storeName.

See confort.WithBeacon.

func WithRetry

func WithRetry(n uint) Option

WithRetry configures the maximum number of retries for unique value generation.

type Unique

type Unique[T comparable] struct {
	// contains filtered or unexported fields
}

func Must added in v1.1.0

func Must[T comparable](u *Unique[T], err error) *Unique[T]

Must is a helper that wraps a call to a function returning (*Unique[T], error) and panics if the error is non-nil. It is intended for use in variable initializations such as

var u = unique.Must(unique.String(context.Background(), 10))

func New

func New[T comparable](ctx context.Context, fn func() (T, error), opts ...Option) (*Unique[T], error)

New creates unique value generator. Argument fn is an arbitrary generator function. When the generated value by fn is not unique or fn returns ErrRetryable, Unique retries. By default, Unique retries 10 times.

func String

func String(ctx context.Context, n int, opts ...Option) (*Unique[string], error)

String is a shorthand of New(StringFunc(n)).

func (*Unique[T]) Must

func (u *Unique[T]) Must(tb testing.TB) T

Must returns unique value. If a unique value cannot be generated within the maximum number of retries, the test fails.

func (*Unique[T]) New

func (u *Unique[T]) New() (T, error)

New returns unique value.

Jump to

Keyboard shortcuts

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