jonsontest

package
v0.0.0-...-a8c3d02 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {

	// We need to pass the test account down to
	// other context forks:
	// usually, an authentication/authorization information resides
	// in the http request headers (cookiers, bearer, ...);
	// those values will be shared between request contexts as well.
	jonson.Shareable
	jonson.ShareableAcrossImpersonation
	// contains filtered or unexported fields
}

func (*Account) Authenticated

func (a *Account) Authenticated() *Account

Authenticated makes the account authenticated (logged in)

func (*Account) Authorized

func (a *Account) Authorized(methods ...*RpcMethod) *Account

Authorized allows the account to be authorized. In case no methods are provided,the account will be authorized to call all methods, otherwise just those provided

func (*Account) CanImpersonate

func (a *Account) CanImpersonate(accounts ...*Account) *Account

CanImpersonate allows the account to impersonate given accounts. In case CanImpersonate is called multiple times, the accounts will be added to the list of possible impersonation accounts

func (*Account) Provide

func (a *Account) Provide(ctx *jonson.Context)

func (*Account) Uuid

func (a *Account) Uuid() string

Uuid returns the account's uuid

type AuthClientMock

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

func NewAuthClientMock

func NewAuthClientMock() *AuthClientMock

func (*AuthClientMock) IsAuthenticated

func (t *AuthClientMock) IsAuthenticated(ctx *jonson.Context) (*string, error)

func (*AuthClientMock) IsAuthorized

func (t *AuthClientMock) IsAuthorized(ctx *jonson.Context) (*string, error)

func (*AuthClientMock) NewAccount

func (t *AuthClientMock) NewAccount(uuid string) *Account

WithAuthenticated creates a new user which is authenticated (logged in)

type FrozenTime

type FrozenTime struct {
	jonson.Shareable
	jonson.ShareableAcrossImpersonation
	// contains filtered or unexported fields
}

func NewFrozenTime

func NewFrozenTime(now ...time.Time) *FrozenTime

NewFrozenTime returns a new frozen time. You can use the methods add, addDate, setTime to move forwards/backwards in time

func (*FrozenTime) Add

func (f *FrozenTime) Add(dur time.Duration) MockTime

func (*FrozenTime) AddDate

func (f *FrozenTime) AddDate(years int, months int, days int) MockTime

func (*FrozenTime) Now

func (f *FrozenTime) Now() time.Time

func (*FrozenTime) SetNow

func (f *FrozenTime) SetNow(tm time.Time)

func (*FrozenTime) SetTime

func (f *FrozenTime) SetTime(hour int, min int, sec int)

func (*FrozenTime) Sleep

func (f *FrozenTime) Sleep(dur time.Duration)

func (*FrozenTime) WithSleep

func (f *FrozenTime) WithSleep(slp func(time.Duration)) *FrozenTime

type GracefulProvider

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

GracefulProvider can be used for tests which rely on jonson.Graceful to be provided. You can mimick a server shutdown by using jonsontest.GracefulProvider

func NewGracefulProvider

func NewGracefulProvider() *GracefulProvider

func (*GracefulProvider) NewGraceful

func (g *GracefulProvider) NewGraceful(ctx *jonson.Context) jonson.Graceful

func (*GracefulProvider) Restart

func (g *GracefulProvider) Restart()

Start mimicks a server restart

func (*GracefulProvider) Shutdown

func (g *GracefulProvider) Shutdown()

Shutdown mimicks a server shutdown

type MockTime

type MockTime interface {
	jonson.Time
	jonson.Shareable
	jonson.ShareableAcrossImpersonation
	SetNow(tm time.Time)
	AddDate(years int, months int, days int) MockTime
	Add(dur time.Duration) MockTime
}

MockTime is a test time that can be implemented by multiple test mocks

type NewTestContextBoundaryOpt

type NewTestContextBoundaryOpt func(*jonson.Context)

func WithHttpSource

WithHttpSource allows us to create a new http source for the test context boundary

func WithRpcMeta

func WithRpcMeta(meta *jonson.RpcMeta) NewTestContextBoundaryOpt

WithRpcMeta allows us to provide rpc meta to the test context boundary

type ReferenceTime

type ReferenceTime struct {
	jonson.Shareable
	jonson.ShareableAcrossImpersonation
	// contains filtered or unexported fields
}

ReferenceTime allows us to bind our time to a fixed reference.

func NewReferenceTime

func NewReferenceTime(reference time.Time, now ...time.Time) *ReferenceTime

NewReferenceTime returns a new time which is bound to a reference. Each call to Now() will add the time that passed since the reference time.

func (*ReferenceTime) Add

func (m *ReferenceTime) Add(dur time.Duration) MockTime

func (*ReferenceTime) AddDate

func (m *ReferenceTime) AddDate(years int, months int, days int) MockTime

func (*ReferenceTime) Now

func (m *ReferenceTime) Now() time.Time

func (*ReferenceTime) SetNow

func (m *ReferenceTime) SetNow(tm time.Time)

SetNow sets the current timestamp

func (*ReferenceTime) SetReference

func (m *ReferenceTime) SetReference(tm time.Time)

func (*ReferenceTime) Sleep

func (m *ReferenceTime) Sleep(dur time.Duration)

func (*ReferenceTime) WithSleep

func (m *ReferenceTime) WithSleep(slp func(time.Duration)) *ReferenceTime

type RpcMethod

type RpcMethod struct {
	HttpMethod jonson.RpcHttpMethod
	Method     string
}

type TestContextBoundary

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

func NewContextBoundary

func NewContextBoundary(
	t *testing.T,
	factory *jonson.Factory,
	methodHandler *jonson.MethodHandler,
	opts ...NewTestContextBoundaryOpt) *TestContextBoundary

NewTestContext returns a new test context

func (*TestContextBoundary) MustRun

func (t *TestContextBoundary) MustRun(fn func(ctx *jonson.Context) error, recovr ...func(stack string))

MustRun makes the parent test fail in case of an error

func (*TestContextBoundary) Run

func (t *TestContextBoundary) Run(fn func(ctx *jonson.Context) error, recovr ...func(stack string)) error

Run runs test. In case you need to inspect a panic, handle a recover fn (recovr) which will receive the stack as a fn argument

func (*TestContextBoundary) WithHttpSource

WithHttpSource provides an http source to the context

func (*TestContextBoundary) WithRpcMeta

func (t *TestContextBoundary) WithRpcMeta(meta *jonson.RpcMeta) *TestContextBoundary

WithRpcMeta provides rpc meta to the context

func (*TestContextBoundary) WithStackInspector

func (t *TestContextBoundary) WithStackInspector(recovr ...func(stack string)) *TestContextBoundary

WithStackInspector allows you to specify a stack inspector which will be enabled for any of the run calls. You can optionally also pass a second argument to Run() or MustRun()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳