cvtesting

package
v0.0.0-...-7bf56e6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

Package cvtesting reduces boilerplate in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTestingContext

func IsTestingContext(ctx context.Context) bool

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

func (t *Test) AddMember(email, group string)

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

func (t *Test) DisableProjectInGerritListener(ctx context.Context, projectRE string)

DisableProjectInGerritListener updates the cached config to disable LUCI projects matching a given regexp in Listener.

func (*Test) GFactory

func (t *Test) GFactory() gerrit.Factory

func (*Test) ResetMockedAuthDB

func (t *Test) ResetMockedAuthDB(ctx context.Context)

func (*Test) RoundTestClock

func (t *Test) RoundTestClock(multiple time.Duration)

func (*Test) SetUp

func (t *Test) SetUp(testingT testing.TB) context.Context

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.

func (*Test) TSMonSentValue

func (t *Test) TSMonSentValue(ctx context.Context, m types.Metric, fieldVals ...any) any

TSMonSentValue returns the latest value of the given metric.

If not set, returns nil.

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.

Jump to

Keyboard shortcuts

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