thunks

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package thunks contains various thunk utilities

Index

Constants

This section is empty.

Variables

View Source
var CompareHashAndPassword = bcrypt.CompareHashAndPassword

CompareHashAndPassword is a thunk for bcrypt.CompareHashAndPassword

View Source
var GenerateFromPassword = bcrypt.GenerateFromPassword

GenerateFromPassword is a thunk for bcrypt.GenerateFromPassword

View Source
var RandReader = rand.Reader

RandReader is rand.Reader by default, but may be replaced in tests

Functions

func AddSetTimeHook

func AddSetTimeHook(hook func(time.Time))

AddSetTimeHook registers a hook function to be called each time the test clock is changed.

func AdvanceNow

func AdvanceNow(d time.Duration)

AdvanceNow moves the test clock forward by the specified amount

func ResetNow

func ResetNow()

ResetNow resets the test clock to the default time

func SetTime

func SetTime(t time.Time)

SetTime sets the test clock to the specified time

func SetUpTest

func SetUpTest()

SetUpTest sets RandReader to be a deterministic PRNG, and TimeNow to return a fixed date

func TimeNow

func TimeNow() time.Time

TimeNow returns the current time, but may be replaced in tests

Types

type Clock

type Clock struct {
}

Clock implements the clockwork.Clock interface

func (Clock) After

func (fc Clock) After(d time.Duration) <-chan time.Time

After is time.After

func (Clock) Now

func (fc Clock) Now() time.Time

Now returns TimeNow(), the fake/internal time

func (Clock) Since

func (fc Clock) Since(t time.Time) time.Duration

Since returns the time between t and the fake/internal time returned by TimeNow()

func (Clock) Sleep

func (fc Clock) Sleep(d time.Duration)

Sleep is time.Sleep

type TestReader

type TestReader struct {
	Next io.Reader
	// contains filtered or unexported fields
}

TestReader returns bytes from Next whenever asked, unless the number of bytes requested is 1, in which case it always returns 0x00.

This is because in go >= 1.11 the crypto libraries non-deterministically read a single byte from the PRNG in order to prevent people doing what we do and relying on the internal details of cryptographic operations.

For our purposes, having deterministic crypto in tests is super handy, and we have mechanisms for updating our expectations. So, while it might be better if we didn't rely on the crypto/* internals, on balance, the convenience of fixed test data outweighs the uglyness of this hack.

You might ask why we don't use a zero-reader as suggested by the commit message. The reason is that rsa key generation seems to spin forever when given a random source that always returns 0.

[1] https://github.com/golang/go/commit/6269dcdc24d74379d8a609ce886149811020b2cc

func (*TestReader) Read

func (z *TestReader) Read(dst []byte) (n int, err error)

Jump to

Keyboard shortcuts

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