Documentation ¶
Overview ¶
Package cvtesting reduces boilerplate in tests.
Index ¶
- func IsTestingContext(ctx context.Context) bool
- type DispatchRecorder
- func (d *DispatchRecorder) Clear()
- func (d *DispatchRecorder) Dispatch(target string, eta time.Time)
- func (d *DispatchRecorder) ETAsOf(target string) []time.Time
- func (d *DispatchRecorder) LatestETAof(target string) time.Time
- func (d *DispatchRecorder) PopTargets() []string
- func (d *DispatchRecorder) Targets() []string
- type Test
- func (t *Test) AddMember(email, group string)
- func (t *Test) AddPermission(email string, perm realms.Permission, realm string)
- func (t *Test) DisableProjectInGerritListener(ctx context.Context, projectRE string)
- func (t *Test) GFactory() gerrit.Factory
- func (t *Test) ResetMockedAuthDB(ctx context.Context)
- func (t *Test) RoundTestClock(multiple time.Duration)
- func (t *Test) SetUp(testingT testing.TB) context.Context
- func (t *Test) TSMonSentDistr(ctx context.Context, m types.Metric, fieldVals ...any) *distribution.Distribution
- func (t *Test) TSMonSentValue(ctx context.Context, m types.Metric, fieldVals ...any) any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTestingContext ¶
IsTestingContext checks if the given context was derived from one created by cvtesting.Test.SetUp().
Types ¶
type DispatchRecorder ¶
type DispatchRecorder struct {
// contains filtered or unexported fields
}
DispatchRecorder records dispatches in memory.
func (*DispatchRecorder) Clear ¶
func (d *DispatchRecorder) Clear()
Clear clears all recorded dispatches.
func (*DispatchRecorder) Dispatch ¶
func (d *DispatchRecorder) Dispatch(target string, eta time.Time)
Dispatch records a dispatch.
func (*DispatchRecorder) ETAsOf ¶
func (d *DispatchRecorder) ETAsOf(target string) []time.Time
ETAsOf returns sorted distinct ETAs for dispatches of the given target.
func (*DispatchRecorder) LatestETAof ¶
func (d *DispatchRecorder) LatestETAof(target string) time.Time
LatestETAof returns the last ETA of the given target.
Panics if the target has no ETAs.
func (*DispatchRecorder) PopTargets ¶
func (d *DispatchRecorder) PopTargets() []string
PopTargets returns sorted list of targets and clears the state.
func (*DispatchRecorder) Targets ¶
func (d *DispatchRecorder) Targets() []string
Targets returns sorted list of targets.
type Test ¶
type Test struct { TB testing.TB // Env simulates CV environment. Env *common.Env // GFake is a Gerrit fake. Defaults to an empty one. GFake *gf.Fake // BuildbucketFake is a Buildbucket fake. Defaults to an empty one. BuildbucketFake *bbfake.Fake // TreeFake is a fake Tree. Defaults to an open Tree. TreeFake *treetest.Fake // BQFake is a fake BQ client. BQFake *bq.Fake // TQDispatcher is a dispatcher with which task classes must be registered. // // Must not be set. TQDispatcher *tq.Dispatcher // TQ allows to run TQ tasks. TQ *tqtesting.Scheduler // SucceededTQTasks is a list of the TQ tasks that were executed successfully. SucceededTQTasks tqtesting.TaskList FailedTQTasks tqtesting.TaskList // Clock allows to move time forward. // By default, the time is moved automatically is something waits on it. Clock testclock.TestClock // TSMonStore store keeps all metrics in memory and allows examination. TSMonStore store.Store // MaxDuration limits how long a test can run as a fail safe. // // Defaults to 10s to most likely finish in pre/post submit tests, // with limited CPU resources. // Set to ~10ms when debugging a hung test. MaxDuration time.Duration // GoMockCtl is the controller for gomock. GoMockCtl *gomock.Controller // contains filtered or unexported fields }
Test encapsulates typical setup for CV test.
Typical use:
ct := cvtesting.Test{} ctx := ct.SetUp(t)
func (*Test) AddMember ¶
AddMember adds a given member into a given luci auth group.
The email may omit domain. In that case, this method will add "@example.com" as the domain name.
func (*Test) AddPermission ¶
func (t *Test) AddPermission(email string, perm realms.Permission, realm string)
AddPermission grants permission to the member in the given realm.
The email may omit domain. In that case, this method will add "@example.com" as the domain name.
func (*Test) DisableProjectInGerritListener ¶
DisableProjectInGerritListener updates the cached config to disable LUCI projects matching a given regexp in Listener.
func (*Test) ResetMockedAuthDB ¶
func (*Test) RoundTestClock ¶
func (*Test) TSMonSentDistr ¶
func (t *Test) TSMonSentDistr(ctx context.Context, m types.Metric, fieldVals ...any) *distribution.Distribution
TSMonSentDistr returns the latest distr value of the given metric.
If not set, returns nil. Panics if metric's value is not a distribution.
Directories ¶
Path | Synopsis |
---|---|
Package benchmarks contains benchmarks for heavy CV use cases.
|
Package benchmarks contains benchmarks for heavy CV use cases. |
Package e2e contains all CV end-to-end tests.
|
Package e2e contains all CV end-to-end tests. |