testsupport

package
v0.0.0-...-3c039c4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package testsupport provides a text fixture that sets up unit tests for the fleet cost server.

Package testsupport provides the `NewFixture` function, which produces a context and a frontend that's suitable for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMatcher

func NewMatcher(message string, predicate func(any) bool) gomock.Matcher

NewMatcher makes a new predicate matcher.

Types

type Fixture

type Fixture struct {
	Ctx      context.Context
	Frontend *costserver.FleetCostFrontend
	MockUFS  *mockufs.MockFleetClient
}

Fixture creates a new test fixture for the fleet cost service and the backend services it talks to.

For each of the backend services, we use the best test implementation available. Datastore uses the LUCI in-memory representation, so it doesn't get an explicit field. UFS uses the go-mock generated stub.

func NewFixture

func NewFixture(ctx context.Context, t *testing.T) *Fixture

NewFixture creates a basic fixture with fake versions of datastore and UFS with properties that are convenient for unit tests.

func NewFixtureWithData

func NewFixtureWithData(ctx context.Context, t *testing.T) *Fixture

NewFixtureWithData returns a fixture with test data.

func (*Fixture) AdvanceClock

func (tf *Fixture) AdvanceClock(d time.Duration)

AdvanceClock advances the clock by a duration.

func (*Fixture) Clock

func (tf *Fixture) Clock() testclock.TestClock

Clock extracts the test clock from the context.

func (*Fixture) RegisterDUTsForLabstation

func (tf *Fixture) RegisterDUTsForLabstation(reqMatcher gomock.Matcher, resp *ufsAPI.GetDUTsForLabstationResponse)

RegisterDUTsForLabstation registers a GetChromeOSDeviceData request and response.

func (*Fixture) RegisterGetChromeOSDeviceDataCall

func (tf *Fixture) RegisterGetChromeOSDeviceDataCall(reqMatcher gomock.Matcher, resp *ufspb.ChromeOSDeviceData)

RegisterGetChromeOSDeviceDataCall registers a GetChromeOSDeviceData request and response.

func (*Fixture) RegisterGetDeviceDataCall

func (tf *Fixture) RegisterGetDeviceDataCall(reqMatcher gomock.Matcher, resp *ufsAPI.GetDeviceDataResponse)

RegisterGetDeviceDataCall registers a GetDeviceData request and response.

func (*Fixture) RegisterGetDeviceDataFailure

func (tf *Fixture) RegisterGetDeviceDataFailure(reqMatcher gomock.Matcher, failure error)

RegisterGetDeviceDataFailure registers a failing GetDeviceData response.

No attempt is made to ensure that the error that we get back is realistic. TODO(gregorynisbet): Check the error for reasonableness and make sure it resembles a UFS error and panic if it does not resemble one.

func (*Fixture) RegisterListMachineLSEs

func (tf *Fixture) RegisterListMachineLSEs(reqMatcher gomock.Matcher, resp *ufsAPI.ListMachineLSEsResponse)

RegisterListMachineLSEs registers a listMachineLSEs request.

type SimpleMatcher

type SimpleMatcher struct {
	Predicate func(any) bool
	Message   string
}

SimpleMatcher takes an artbirary function and makes it a matcher.

func (SimpleMatcher) Matches

func (matcher SimpleMatcher) Matches(item any) bool

Matches determines whether an item fulfills the predicate.

func (SimpleMatcher) String

func (matcher SimpleMatcher) String() string

String returns the matcher message.

Jump to

Keyboard shortcuts

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