Documentation
¶
Index ¶
- type Account
- type AuthClientMock
- type FrozenTime
- func (f *FrozenTime) Add(dur time.Duration) MockTime
- func (f *FrozenTime) AddDate(years int, months int, days int) MockTime
- func (f *FrozenTime) Now() time.Time
- func (f *FrozenTime) SetNow(tm time.Time)
- func (f *FrozenTime) SetTime(hour int, min int, sec int)
- func (f *FrozenTime) Sleep(dur time.Duration)
- func (f *FrozenTime) WithSleep(slp func(time.Duration)) *FrozenTime
- type GracefulProvider
- type MockTime
- type NewTestContextBoundaryOpt
- type ReferenceTime
- func (m *ReferenceTime) Add(dur time.Duration) MockTime
- func (m *ReferenceTime) AddDate(years int, months int, days int) MockTime
- func (m *ReferenceTime) Now() time.Time
- func (m *ReferenceTime) SetNow(tm time.Time)
- func (m *ReferenceTime) SetReference(tm time.Time)
- func (m *ReferenceTime) Sleep(dur time.Duration)
- func (m *ReferenceTime) WithSleep(slp func(time.Duration)) *ReferenceTime
- type RpcMethod
- type TestContextBoundary
- func (t *TestContextBoundary) MustRun(fn func(ctx *jonson.Context) error, recovr ...func(stack string))
- func (t *TestContextBoundary) Run(fn func(ctx *jonson.Context) error, recovr ...func(stack string)) error
- func (t *TestContextBoundary) WithHttpSource(r *http.Request, w http.ResponseWriter) *TestContextBoundary
- func (t *TestContextBoundary) WithRpcMeta(meta *jonson.RpcMeta) *TestContextBoundary
- func (t *TestContextBoundary) WithStackInspector(recovr ...func(stack string)) *TestContextBoundary
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. // contains filtered or unexported fields }
func (*Account) Authenticated ¶
Authenticated makes the account authenticated (logged in)
func (*Account) Authorized ¶
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 ¶
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
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 { // 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) Now ¶
func (f *FrozenTime) Now() time.Time
func (*FrozenTime) SetNow ¶
func (f *FrozenTime) SetNow(tm time.Time)
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 ¶
func WithHttpSource ¶
func WithHttpSource(r *http.Request, w http.ResponseWriter) NewTestContextBoundaryOpt
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 { // 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) 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 ¶
func (t *TestContextBoundary) WithHttpSource(r *http.Request, w http.ResponseWriter) *TestContextBoundary
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()