testingx

package
v3.16.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testingx contains code useful for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeFiller

type FakeFiller struct {

	// Now is OPTIONAL and allows to mock the current time
	Now func() time.Time
	// contains filtered or unexported fields
}

FakeFiller fills specific data structures with random data. The only exception to this behaviour is time.Time, which is instead filled with the current time plus a small random number of seconds.

We use this implementation to initialize data in our model. The code has been written with that in mind. It will require some hammering in case we extend the model with new field types.

Caveat: this kind of fillter does not support filling interfaces and channels and other complex types. The current behavior when this kind of data types is encountered is to just ignore them.

This struct is quite limited in scope and we can fill only the structures you typically send over as JSONs.

As part of future work, we aim to investigate whether we can replace this implementation with https://go.dev/blog/fuzz-beta.

func (*FakeFiller) Fill

func (ff *FakeFiller) Fill(in interface{})

Fill fills the input structure or pointer with random data.

type TimeDeterministic

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

TimeDeterministic implements time.Now in a deterministic fashion such that every time.Time call returns a moment in time that occurs one second after the configured zeroTime.

It's safe to use this struct from multiple goroutine contexts.

func NewTimeDeterministic

func NewTimeDeterministic(zeroTime time.Time) *TimeDeterministic

NewTimeDeterministic creates a new instance using the given zeroTime value.

func (*TimeDeterministic) Now

func (td *TimeDeterministic) Now() time.Time

Now is like time.Now but more deterministic. The first call returns the configured zeroTime and subsequent calls return moments in time that occur exactly one second after the time returned by the previous call.

Jump to

Keyboard shortcuts

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