testfakes

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package testfakes provides in-memory fakes for all CLI use-case interfaces. Import this package from cli tests to exercise run* functions without opening a real SQLite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeCheckCompatibility

type FakeCheckCompatibility struct {
	Report licensedomain.ClosureCompatibilityReport
	// ReportByWalk answers per walk id, so a test can give two walks of one
	// target genuinely different licence positions — which is the whole point of
	// being able to pin one. A walk id absent from the map falls back to Report.
	ReportByWalk map[string]licensedomain.ClosureCompatibilityReport
	Err          error
	// AskedWalkIDs records, in order, the walks the command asked about.
	AskedWalkIDs []string
}

FakeCheckCompatibility implements cli.CheckCompatibilityUseCase.

type FakeDiffDirectives

type FakeDiffDirectives struct {
	Result directivedomain.DirectiveDiff
	Err    error
}

FakeDiffDirectives implements cli.DiffDirectivesUseCase.

func (*FakeDiffDirectives) Diff

type FakeDiffInterface

type FakeDiffInterface struct {
	Result ifacedomain.InterfaceDiff
	Err    error
}

FakeDiffInterface implements cli.DiffInterfaceUseCase.

func (*FakeDiffInterface) Diff

type FakeDiffLicense

type FakeDiffLicense struct {
	Result licensedomain.LicenseDiff
	Err    error
}

FakeDiffLicense implements cli.DiffLicenseUseCase.

func (*FakeDiffLicense) Diff

type FakeDiffScanRuns

type FakeDiffScanRuns struct {
	Err    error
	Result vulndomain.ScanRunDiff
}

FakeDiffScanRuns implements cli.DiffScanRunsUseCase.

func (*FakeDiffScanRuns) Diff

type FakeDiffWalks

type FakeDiffWalks struct {
	Err    error
	Result walkapp.WalkDiff
}

FakeDiffWalks implements cli.DiffWalksUseCase.

func (*FakeDiffWalks) Diff

type FakeExecuteWalk

type FakeExecuteWalk struct {
	Err         error
	Result      walkapp.ExecuteWalkResult
	LastRequest walkapp.WalkRequest
	// Calls counts Execute invocations, so a test can assert that a refused
	// flag combination never reached the walk at all.
	Calls int
}

FakeExecuteWalk implements cli.ExecuteWalkUseCase. LastRequest captures the most recent request so tests can assert how the CLI translated flags into a WalkRequest.

func (*FakeExecuteWalk) Execute

type FakeExtract

type FakeExtract struct {
	Err    error
	Result extractdomain.ExtractionRun
	Calls  []extractapp.ExtractRequest
}

FakeExtract implements cli.ExtractUseCase. It records each request so tests can assert which stages ran and whether force was set.

func (*FakeExtract) Execute

type FakeExtractCallGraph

type FakeExtractCallGraph struct {
	Err    error
	Result cgapp.ExtractResult
}

FakeExtractCallGraph implements cli.ExtractCallGraphUseCase.

func (*FakeExtractCallGraph) Execute

type FakeExtractExample

type FakeExtractExample struct {
	Err    error
	Result exapp.ExtractResult
}

FakeExtractExample implements cli.ExtractExampleUseCase.

func (*FakeExtractExample) Execute

type FakeExtractFIPS

type FakeExtractFIPS struct {
	Err    error
	Result fipsdomain.Record
}

FakeExtractFIPS implements cli.ExtractFIPSUseCase.

func (*FakeExtractFIPS) Extract

type FakeExtractInterface

type FakeExtractInterface struct {
	Err    error
	Result ifaceapp.ExtractResult
}

FakeExtractInterface implements cli.ExtractInterfaceUseCase.

func (*FakeExtractInterface) Execute

type FakeExtractLicense

type FakeExtractLicense struct {
	Err    error
	Result licapp.ExtractResult
}

FakeExtractLicense implements cli.ExtractLicenseUseCase.

func (*FakeExtractLicense) Execute

func (*FakeExtractLicense) GetLicenseStore

func (f *FakeExtractLicense) GetLicenseStore() licenseports.LicenseStore

type FakeFetchModule

type FakeFetchModule struct {
	Err    error
	Result fetchapp.FetchResult
}

FakeFetchModule implements cli.FetchModuleUseCase.

func (*FakeFetchModule) Execute

type FakeGenerateNotice

type FakeGenerateNotice struct {
	Result licapp.NoticeResult
	Err    error
	// LastRequest records what the caller asked for, so a test can assert on
	// inputs the fake result cannot reflect — the operator's recorded copyright
	// declarations among them.
	LastRequest licapp.NoticeRequest
}

FakeGenerateNotice implements cli.GenerateNoticeUseCase.

func (*FakeGenerateNotice) Generate

type FakeGenerateSBOM

type FakeGenerateSBOM struct {
	Err         error
	Result      sbomdomain.SBOMRecord
	LastRequest sbomapp.SBOMRequest
}

FakeGenerateSBOM implements cli.GenerateSBOMUseCase.

func (*FakeGenerateSBOM) Generate

type FakeQueryCallGraph

type FakeQueryCallGraph struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int
	// CoordinateListCalls counts calls to the column-only listing, and RecordReads
	// every composed record read.
	//
	// They are counted separately from ListCalls because the difference between
	// them IS the behaviour: an edge query asks which modules the store has
	// analysed, which is a question about coordinates, and answering it through
	// the composing listing decodes every generation of every multi-generation
	// coordinate in the store to read fields no part of the answer looks at.
	CoordinateListCalls int
	// Unserved is what UnservedCoordinates answers, for the coordinates asked.
	Unserved []cgports.UnservedCoordinate
	// HistoryCalls counts the composing history read — the one that reconstructs
	// and verifies every generation's edge set. It is counted separately from
	// RecordReads because a caller that needs one COLUMN per generation must not
	// reach it: reading the analyser through it was a second complete pass over
	// the coordinate, on top of the one composition had already done.
	HistoryCalls int
	RecordReads  int
	// ForeignModuleReads counts the column read that qualifies an answer. It is
	// separate from RecordReads because in the store it IS separate: a column
	// beside the record, read without decompressing or decoding one, which is the
	// whole reason the column exists.
	ForeignModuleReads int

	Err error
	// contains filtered or unexported fields
}

FakeQueryCallGraph implements cli.QueryCallGraphUseCase.

func NewFakeQueryCallGraph

func NewFakeQueryCallGraph() *FakeQueryCallGraph

func (*FakeQueryCallGraph) AddGeneration

func (f *FakeQueryCallGraph) AddGeneration(coord coordinate.ModuleCoordinate, pipelineVersion string, rec cgdomain.CallGraphRecord)

AddGeneration appends a record to the coordinate's history without changing what GetCallGraphRecord serves, so a test can set up a ledger holding several generations and a composed answer independently.

func (*FakeQueryCallGraph) AddRecord

func (f *FakeQueryCallGraph) AddRecord(coord coordinate.ModuleCoordinate, pipelineVersion string, rec cgdomain.CallGraphRecord)

func (*FakeQueryCallGraph) CallGraphHistory

func (f *FakeQueryCallGraph) CallGraphHistory(ctx context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) ([]cgdomain.CallGraphRecord, error)

func (*FakeQueryCallGraph) FindCallees

func (*FakeQueryCallGraph) FindCallers

func (*FakeQueryCallGraph) ForeignModulesBuilt

func (f *FakeQueryCallGraph) ForeignModulesBuilt(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string, _ gotoolchain.Version) ([]cgdomain.ForeignModule, bool, error)

ForeignModulesBuilt answers from the added record's own field, which is what the store's derived column holds: the write leg copies it out of the record in the same transaction as the blob, so the two can never disagree. It counts no record read, because reading the column is not one.

func (*FakeQueryCallGraph) GetCallGraphRecord

func (f *FakeQueryCallGraph) GetCallGraphRecord(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) (cgdomain.CallGraphRecord, bool, error)

func (*FakeQueryCallGraph) GetCallGraphRecordFrom

func (f *FakeQueryCallGraph) GetCallGraphRecordFrom(ctx context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string, req cgdomain.ComposeRequest) (cgdomain.CallGraphRecord, bool, error)

func (*FakeQueryCallGraph) ListCallGraphCoordinates

func (f *FakeQueryCallGraph) ListCallGraphCoordinates(_ context.Context, filter cgports.CallGraphFilter) ([]cgports.CallGraphCoordinate, error)

ListCallGraphCoordinates projects the same filtered listing onto the ledger's keys.

The flags are read off the RECORDS the fake holds, not off the summaries. A real store reads them from denormalised columns that a write puts there from the record itself, so the two can never disagree; in the fake they are set independently, and deriving the flags from the summary would let a test whose summary says nothing hide a Partial record the resolution helpers must see.

func (*FakeQueryCallGraph) ListCallGraphRecords

func (f *FakeQueryCallGraph) ListCallGraphRecords(_ context.Context, filter cgports.CallGraphFilter) ([]cgports.CallGraphSummary, error)

ListCallGraphRecords applies the filter the SQLite adapter applies: exact equality on the module path, then offset, then limit. A fake that returned everything regardless would let a filter defect pass every test that used it.

func (*FakeQueryCallGraph) NotSearchedByCallees

NotSearchedByCallees names nothing, as NotSearchedByCallers.

func (*FakeQueryCallGraph) NotSearchedByCallers

NotSearchedByCallers names nothing: the fake holds one generation per coordinate, so nothing it holds is superseded.

func (*FakeQueryCallGraph) SetCallees

func (f *FakeQueryCallGraph) SetCallees(refs []cgports.CallEdgeRef)

func (*FakeQueryCallGraph) SetCallers

func (f *FakeQueryCallGraph) SetCallers(refs []cgports.CallEdgeRef)

func (*FakeQueryCallGraph) SetCallersFor

func (f *FakeQueryCallGraph) SetCallersFor(symbolID string, refs []cgports.CallEdgeRef)

SetCallersFor answers one symbol specifically. A command that queries several symbols in one run needs the fake to tell them apart; SetCallers alone would return the same edges for every one of them, and a join that queried the wrong symbol would still pass.

func (*FakeQueryCallGraph) SetGetErr

func (f *FakeQueryCallGraph) SetGetErr(err error)

SetGetErr makes record reads fail while listing still succeeds, so a caller that must surface a store failure rather than report an empty answer can be tested at the point the read happens.

func (*FakeQueryCallGraph) SetList

func (f *FakeQueryCallGraph) SetList(summaries []cgports.CallGraphSummary)

func (*FakeQueryCallGraph) SetTraverseCallees

func (f *FakeQueryCallGraph) SetTraverseCallees(edges []cgports.CallEdgeRef, nodes []string)

func (*FakeQueryCallGraph) SetTraverseCalleesTruncated

func (f *FakeQueryCallGraph) SetTraverseCalleesTruncated(truncated bool)

SetTraverseCalleesTruncated is SetTraverseCallersTruncated for the other direction.

func (*FakeQueryCallGraph) SetTraverseCallers

func (f *FakeQueryCallGraph) SetTraverseCallers(edges []cgports.CallEdgeRef, nodes []string)

func (*FakeQueryCallGraph) SetTraverseCallersTruncated

func (f *FakeQueryCallGraph) SetTraverseCallersTruncated(truncated bool)

SetTraverseCallersTruncated makes the next caller traversal report that it stopped holding an unexpanded frontier. It is a separate setter from the answer itself because the two are independent: the same nodes and edges are returned whether or not the walk had more to follow, which is the whole difference the marker exists to state.

func (*FakeQueryCallGraph) TraversalRequests

func (f *FakeQueryCallGraph) TraversalRequests() []cgapp.TraversalRequest

TraversalRequests returns every request the fake was asked, in order, so a test can assert what the command plumbed through — the depth bound and the progress reporter included.

func (*FakeQueryCallGraph) TraverseCallees

func (*FakeQueryCallGraph) TraverseCallers

func (*FakeQueryCallGraph) UnservedCoordinates

UnservedCoordinates names nothing, as NotSearchedByCallers.

type FakeQueryDirectives

type FakeQueryDirectives struct {
	Scan    directivedomain.Record
	Found   bool
	Scans   []directivedomain.Record
	GetErr  error
	ListErr error
	// StoreScans is how many scans the whole store holds, across every project.
	// Zero means "the same as Scans": the common fixture has one project and no
	// reason to distinguish the two, and a fixture that wants a store holding
	// scans for OTHER projects sets it explicitly.
	StoreScans int
	CountErr   error
	// Projects is what ListScanProjects names; nil reads as a store that
	// cannot enumerate them.
	Projects []string
	// ListCalls counts calls to ListScans, so a test can assert that a listing
	// which returned rows read the store once and did not also pay the
	// zero-result survey.
	ListCalls int
}

FakeQueryDirectives implements cli.QueryDirectivesUseCase.

func (*FakeQueryDirectives) CountScans

func (f *FakeQueryDirectives) CountScans(context.Context) (int, error)

func (*FakeQueryDirectives) GetScan

func (*FakeQueryDirectives) ListScanProjects added in v0.16.1

func (f *FakeQueryDirectives) ListScanProjects(context.Context) ([]string, bool, error)

func (*FakeQueryDirectives) ListScans

func (f *FakeQueryDirectives) ListScans(_ context.Context, _ string, limit, offset int) ([]directivedomain.Record, error)

type FakeQueryExamples

type FakeQueryExamples struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int
	// ListFilters records every filter the listing method was given, so a test
	// can assert what a listing asked the store for.
	ListFilters []exports.ExampleFilter

	Err error
	// contains filtered or unexported fields
}

FakeQueryExamples implements cli.QueryExamplesUseCase.

func NewFakeQueryExamples

func NewFakeQueryExamples() *FakeQueryExamples

func (*FakeQueryExamples) AddRecord

func (f *FakeQueryExamples) AddRecord(coord coordinate.ModuleCoordinate, pipelineVersion string, rec exdomain.ExampleRecord)

func (*FakeQueryExamples) ExampleHistory

func (f *FakeQueryExamples) ExampleHistory(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) ([]exdomain.ExampleRecord, error)

func (*FakeQueryExamples) FindBySymbol

func (*FakeQueryExamples) FindBySymbolInModule

func (f *FakeQueryExamples) FindBySymbolInModule(_ context.Context, coord coordinate.ModuleCoordinate, _, _ string) ([]exports.ExampleRef, error)

func (*FakeQueryExamples) GetExampleRecord

func (f *FakeQueryExamples) GetExampleRecord(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) (exdomain.ExampleRecord, bool, error)

func (*FakeQueryExamples) ListExampleRecords

func (f *FakeQueryExamples) ListExampleRecords(_ context.Context, filter exports.ExampleFilter) ([]exports.ExampleSummary, error)

func (*FakeQueryExamples) PipelinesHeld

func (f *FakeQueryExamples) PipelinesHeld(_ context.Context, coord coordinate.ModuleCoordinate) ([]string, error)

PipelinesHeld derives the pipelines held from the keys AddRecord and SetHistory filed.

func (*FakeQueryExamples) SetHistory

func (f *FakeQueryExamples) SetHistory(coord coordinate.ModuleCoordinate, pipelineVersion string, recs []exdomain.ExampleRecord)

SetHistory sets the generations ExampleHistory returns for a coordinate.

func (*FakeQueryExamples) SetList

func (f *FakeQueryExamples) SetList(sums []exports.ExampleSummary)

func (*FakeQueryExamples) SetRefs

func (f *FakeQueryExamples) SetRefs(refs []exports.ExampleRef)

type FakeQueryExtraction

type FakeQueryExtraction struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int

	Err error
	// contains filtered or unexported fields
}

FakeQueryExtraction implements cli.QueryExtractionUseCase.

func NewFakeQueryExtraction

func NewFakeQueryExtraction() *FakeQueryExtraction

func (*FakeQueryExtraction) AddRun

func (*FakeQueryExtraction) GetExtractionRun

func (*FakeQueryExtraction) ListExtractionRuns

func (*FakeQueryExtraction) SetList

SetList sets the summaries ListExtractionRuns pages over.

type FakeQueryFIPS

type FakeQueryFIPS struct {
	Err error
	// contains filtered or unexported fields
}

FakeQueryFIPS implements cli.QueryFIPSUseCase.

func NewFakeQueryFIPS

func NewFakeQueryFIPS() *FakeQueryFIPS

func (*FakeQueryFIPS) Add

func (f *FakeQueryFIPS) Add(projectModulePath string, rec fipsdomain.Record)

func (*FakeQueryFIPS) Get

func (f *FakeQueryFIPS) Get(_ context.Context, projectModulePath string) (fipsdomain.Record, bool, error)

type FakeQueryFetch

type FakeQueryFetch struct {
	Err error
	// contains filtered or unexported fields
}

FakeQueryFetch implements cli.QueryFetchUseCase.

func NewFakeQueryFetch

func NewFakeQueryFetch() *FakeQueryFetch

func (*FakeQueryFetch) Add

func (f *FakeQueryFetch) Add(coord coordinate.ModuleCoordinate, pipelineVersion string, rec fetchdomain.FactRecord)

func (*FakeQueryFetch) GetFetchRecord

func (f *FakeQueryFetch) GetFetchRecord(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) (fetchdomain.FactRecord, bool, error)

type FakeQueryInterface

type FakeQueryInterface struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int
	// ListFilters records every filter this fake was asked for, in order, so a
	// test can assert WHAT was asked as well as how often. A per-coordinate
	// question served from an unfiltered read is a defect the count alone
	// cannot see.
	ListFilters []ifaceports.InterfaceFilter

	Err error
	// contains filtered or unexported fields
}

FakeQueryInterface implements cli.QueryInterfaceUseCase.

func NewFakeQueryInterface

func NewFakeQueryInterface() *FakeQueryInterface

func (*FakeQueryInterface) AddRecord

func (f *FakeQueryInterface) AddRecord(coord coordinate.ModuleCoordinate, pipelineVersion string, rec ifacedomain.InterfaceRecord)

AddRecord sets the composed record GetInterfaceRecord returns for a coordinate.

func (*FakeQueryInterface) FindSymbol

func (*FakeQueryInterface) GetInterfaceRecord

func (f *FakeQueryInterface) GetInterfaceRecord(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) (ifacedomain.InterfaceRecord, bool, error)

func (*FakeQueryInterface) InterfaceHistory

func (f *FakeQueryInterface) InterfaceHistory(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) ([]ifacedomain.InterfaceRecord, error)

func (*FakeQueryInterface) ListInterfaceGenerations

func (f *FakeQueryInterface) ListInterfaceGenerations(_ context.Context) ([]ifaceports.InterfaceGeneration, error)

ListInterfaceGenerations names each (module, version, pipeline) the list holds once. It counts as a listing read in ListCalls.

func (*FakeQueryInterface) ListInterfaceRecords

func (*FakeQueryInterface) SetInterfaceHistory

func (f *FakeQueryInterface) SetInterfaceHistory(coord coordinate.ModuleCoordinate, pipelineVersion string, recs []ifacedomain.InterfaceRecord)

SetInterfaceHistory sets the generations InterfaceHistory returns for a coordinate.

func (*FakeQueryInterface) SetList

func (f *FakeQueryInterface) SetList(sums []ifaceports.InterfaceSummary)

SetList sets the summaries ListInterfaceRecords pages over.

type FakeQueryLicense

type FakeQueryLicense struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int

	Err error
	// contains filtered or unexported fields
}

FakeQueryLicense implements cli.QueryLicenseUseCase.

func NewFakeQueryLicense

func NewFakeQueryLicense() *FakeQueryLicense

func (*FakeQueryLicense) AddRecord

func (f *FakeQueryLicense) AddRecord(coord coordinate.ModuleCoordinate, pipelineVersion string, rec licensedomain.LicenseRecord)

func (*FakeQueryLicense) GetLicenseRecord

func (f *FakeQueryLicense) GetLicenseRecord(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) (licensedomain.LicenseRecord, bool, error)

func (*FakeQueryLicense) LicenseHistory

func (f *FakeQueryLicense) LicenseHistory(_ context.Context, coord coordinate.ModuleCoordinate, pipelineVersion string) ([]licensedomain.LicenseRecord, error)

func (*FakeQueryLicense) ListLicenseRecords

ListLicenseRecords applies the filter the SQLite adapter applies: exact equality on the primary SPDX identifier, the pipeline version and the copyright status, then the offset, then the limit.

func (*FakeQueryLicense) PipelinesHeld

func (f *FakeQueryLicense) PipelinesHeld(_ context.Context, coord coordinate.ModuleCoordinate) ([]string, error)

PipelinesHeld derives the pipelines held from the keys AddRecord and SetHistory filed, so a record added at a superseded pipeline is visible to the superseded diagnostic exactly as the store's own index makes it.

func (*FakeQueryLicense) SetHistory

func (f *FakeQueryLicense) SetHistory(coord coordinate.ModuleCoordinate, pipelineVersion string, recs []licensedomain.LicenseRecord)

History is the generation list LicenseHistory returns, keyed by "coordinate|pipelineVersion" like records.

func (*FakeQueryLicense) SetList

func (f *FakeQueryLicense) SetList(summaries []licenseports.LicenseSummary)

func (*FakeQueryLicense) SetResolveResult

func (f *FakeQueryLicense) SetResolveResult(results []licapp.DepLicenseResult)

type FakeQuerySBOM

type FakeQuerySBOM struct {
	Err error
	// contains filtered or unexported fields
}

FakeQuerySBOM implements cli.QuerySBOMUseCase.

func NewFakeQuerySBOM

func NewFakeQuerySBOM() *FakeQuerySBOM

func (*FakeQuerySBOM) GetSBOMRecord

func (f *FakeQuerySBOM) GetSBOMRecord(_ context.Context, id string) (sbomdomain.SBOMRecord, error)

func (*FakeQuerySBOM) ListSBOMRecords

func (f *FakeQuerySBOM) ListSBOMRecords(_ context.Context, _ string) ([]sbomdomain.SBOMRecord, error)

type FakeQueryScanRuns

type FakeQueryScanRuns struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int

	GetErr  error
	ListErr error
	// AbsentWalks are the walk ids this store no longer holds — the runs naming
	// them have inputs that cannot be resolved. Empty (the default) means every
	// seeded run's walk resolves, which is the healthy store.
	AbsentWalks map[string]bool
	// PresenceErr, when set, is what the walk-presence probe fails with. A reader
	// that cannot check must not answer, so commands surface it rather than
	// rendering the run as ordinary.
	PresenceErr error
	// contains filtered or unexported fields
}

FakeQueryScanRuns implements cli.QueryScanRunsUseCase.

func NewFakeQueryScanRuns

func NewFakeQueryScanRuns() *FakeQueryScanRuns

func (*FakeQueryScanRuns) AddRun

func (f *FakeQueryScanRuns) AddRun(run vulndomain.WalkScanRun)

func (*FakeQueryScanRuns) AddSnapshot

func (f *FakeQueryScanRuns) AddSnapshot(snap vulndomain.DatabaseSnapshot)

func (*FakeQueryScanRuns) GetLatestSnapshot

func (*FakeQueryScanRuns) GetRun

func (*FakeQueryScanRuns) ListAllRuns

ListAllRuns returns every seeded run, on the same partial-result terms as ListRunsForWalk.

func (*FakeQueryScanRuns) ListRunsForWalk

func (f *FakeQueryScanRuns) ListRunsForWalk(_ context.Context, walkID string) ([]vulndomain.WalkScanRun, error)

ListRunsForWalk returns the seeded runs for walkID. ListErr is returned ALONGSIDE them, not instead of them: the real store reports the rows it could not verify while still handing back the ones it could, and a fake that withheld them would let a survey command pass a test it fails in production.

func (*FakeQueryScanRuns) ListSnapshots

func (*FakeQueryScanRuns) MarkWalkAbsent

func (f *FakeQueryScanRuns) MarkWalkAbsent(walkID string)

MarkWalkAbsent seeds a walk id as purged from the store, so the runs naming it are the dangling ones.

func (*FakeQueryScanRuns) UnresolvedWalks

func (f *FakeQueryScanRuns) UnresolvedWalks(
	_ context.Context, runs []vulndomain.WalkScanRun,
) (map[string]bool, error)

UnresolvedWalks names the walks among runs that this fake reports as absent.

func (*FakeQueryScanRuns) WalkPresent

func (f *FakeQueryScanRuns) WalkPresent(_ context.Context, walkID string) (bool, error)

WalkPresent reports whether walkID is still held.

type FakeQueryVuln

type FakeQueryVuln struct {
	Err error
	// PartialErr is returned ALONGSIDE the records a listing found, the way a
	// store reports rows it could not verify while still handing back the ones it
	// could. Err aborts instead, returning nothing: the two are different
	// failures, and a fake that could only express one could not test the
	// difference between a listing that withholds its answer and one that names
	// what is missing from it.
	PartialErr error
	// ForceLatestRecordForWalkNotFound empties the walk-scoped candidate read
	// regardless of the records map.
	ForceLatestRecordForWalkNotFound bool
	// contains filtered or unexported fields
}

FakeQueryVuln implements cli.QueryVulnUseCase.

func NewFakeQueryVuln

func NewFakeQueryVuln() *FakeQueryVuln

func (*FakeQueryVuln) AddRecord

func (*FakeQueryVuln) AddRecords

AddRecords seeds every generation the ledger holds for one coordinate, which is what a frame-aware read consults. The first is also the coordinate's single-record answer, so a test that seeds a ledger does not have to seed the composed read separately.

func (*FakeQueryVuln) AddSupersededRecords

func (f *FakeQueryVuln) AddSupersededRecords(coord coordinate.ModuleCoordinate, recs ...vulndomain.VulnerabilityRecord)

AddSupersededRecords seeds records the store holds at a generation this build does not serve. Only ListRecordsForModuleAllGenerations returns them, so a test can reproduce a coordinate whose whole history is dark to the keyed reads while the rows are still in the store.

func (*FakeQueryVuln) ByIDWalkSeen

func (f *FakeQueryVuln) ByIDWalkSeen() string

ByIDWalkSeen returns the walk ID the last ListRecordsByFindingID call carried, so a test can prove the flag reached the use case rather than being dropped.

func (*FakeQueryVuln) FindingTimelines

func (f *FakeQueryVuln) FindingTimelines(_ context.Context, _, walkID string) ([]vulndomain.FindingTimeline, error)

FindingTimelines returns the seeded timelines beside PartialErr, or Err.

func (*FakeQueryVuln) ListRecordGenerationsForModule

func (f *FakeQueryVuln) ListRecordGenerationsForModule(_ context.Context, coord coordinate.ModuleCoordinate) ([]vulnports.VulnerabilityRecordGeneration, error)

ListRecordGenerationsForModule answers the census. An unseeded coordinate holds nothing, which is the "never scanned" case.

func (*FakeQueryVuln) ListRecordsByFindingID

func (f *FakeQueryVuln) ListRecordsByFindingID(_ context.Context, _, walkID string) ([]vulndomain.VulnerabilityRecord, error)

func (*FakeQueryVuln) ListRecordsForModule

func (*FakeQueryVuln) ListRecordsForModuleAllGenerations

func (f *FakeQueryVuln) ListRecordsForModuleAllGenerations(ctx context.Context, coord coordinate.ModuleCoordinate) ([]vulndomain.VulnerabilityRecord, error)

ListRecordsForModuleAllGenerations returns what the keyed read returns plus the rows seeded through AddSupersededRecords, which no other read here sees. The superseded rows come last: the fake seeds no timestamps of its own, and a listing that puts them first would pass a test the real newest-first ordering would fail.

func (*FakeQueryVuln) ListRecordsForModuleInWalk

func (f *FakeQueryVuln) ListRecordsForModuleInWalk(_ context.Context, coord coordinate.ModuleCoordinate, _, _ string) ([]vulndomain.VulnerabilityRecord, error)

ListRecordsForModuleInWalk returns the walk's candidate records for a coordinate: the ledger's generations when one has been seeded, otherwise the single record the map holds. ForceLatestRecordForWalkNotFound empties it, the same way it empties the composed read below.

func (*FakeQueryVuln) ListRecordsForRun

func (f *FakeQueryVuln) ListRecordsForRun(_ context.Context, runID string) ([]vulndomain.VulnerabilityRecord, error)

func (*FakeQueryVuln) SetByID

func (f *FakeQueryVuln) SetByID(recs []vulndomain.VulnerabilityRecord)

func (*FakeQueryVuln) SetByIDForWalk

func (f *FakeQueryVuln) SetByIDForWalk(walkID string, recs []vulndomain.VulnerabilityRecord)

SetByIDForWalk seeds the answer a walk-scoped vuln-by-id query gets. Walks with no entry are reported as never scanned.

func (*FakeQueryVuln) SetRecordGenerations

func (f *FakeQueryVuln) SetRecordGenerations(coord coordinate.ModuleCoordinate, gens []vulnports.VulnerabilityRecordGeneration)

SetRecordGenerations seeds the store census for a coordinate.

func (*FakeQueryVuln) SetRunRecords

func (f *FakeQueryVuln) SetRunRecords(runID string, recs []vulndomain.VulnerabilityRecord)

SetRunRecords seeds the records one scan run wrote, which is what a served run's report is rebuilt from.

func (*FakeQueryVuln) SetTimelines

func (f *FakeQueryVuln) SetTimelines(tls []vulndomain.FindingTimeline)

SetTimelines seeds the answer FindingTimelines gives.

type FakeQueryWalks

type FakeQueryWalks struct {
	// ListCalls counts calls to this fake's listing method, so a test can
	// assert that a listing which returned rows read the store exactly once and
	// did not also pay the survey read the zero-result notice needs.
	ListCalls int

	GetErr  error
	ListErr error
	// contains filtered or unexported fields
}

FakeQueryWalks implements cli.QueryWalksUseCase.

func NewFakeQueryWalks

func NewFakeQueryWalks() *FakeQueryWalks

func (*FakeQueryWalks) AddWalk

func (f *FakeQueryWalks) AddWalk(rec walkdomain.WalkRecord)

func (*FakeQueryWalks) GetWalk

func (*FakeQueryWalks) ListWalks

func (*FakeQueryWalks) SetSummaries

func (f *FakeQueryWalks) SetSummaries(s []walkports.WalkSummary)

type FakeRescanWalk

type FakeRescanWalk struct {
	Err    error
	Result vulndomain.WalkScanRun
}

FakeRescanWalk implements cli.RescanWalkUseCase.

func (*FakeRescanWalk) Rescan

type FakeScanModule

type FakeScanModule struct {
	Err    error
	Result vulndomain.VulnerabilityRecord
}

FakeScanModule implements cli.ScanModuleUseCase.

type FakeScanWalk

type FakeScanWalk struct {
	Err    error
	Result vulndomain.WalkScanRun
	// ProgressRecords are delivered to the Progress callback (if set) before
	// the result is returned. Use this to test output routing in callers.
	ProgressRecords []FakeScanWalkProgress

	// ReusableRunResult and ReusableRunFound are what ReusableRun reports. The
	// zero value reports no reusable run, so a fake that says nothing about reuse
	// drives the measuring path, which is what most callers want.
	ReusableRunResult vulndomain.WalkScanRun
	ReusableRunFound  bool
	ReusableRunErr    error
	// ReusableRunWalkID records the walk the last ReusableRun call asked about,
	// so a test can prove the reuse question was asked about the walk the run
	// executed rather than some other walk of the same target.
	ReusableRunWalkID string
	// ReusableRunProjectDir records the project directory the last ReusableRun
	// call was told about. Whether a stored run may be served depends on that
	// directory still building what the walk resolved, so a caller that asks the
	// reuse question without naming the tree it would have scanned bypasses the
	// check; this records what was named.
	ReusableRunProjectDir string
	// ReusableRunProjectDirSet reports that ReusableRun was called at all, so a
	// test can tell "asked with no directory" from "never asked".
	ReusableRunProjectDirSet bool
	// ServedRuns records every (run id, surface) pair ServeReusableRun was told
	// about, so a test can prove a served answer was witnessed exactly once and
	// attributed to the surface that asked. ServeReusableRunErr fails the append.
	ServedRuns          []ServedRun
	ServeReusableRunErr error
	// ScanCalls counts Scan invocations, so a test can prove a served run did not
	// re-measure.
	ScanCalls int

	// RefreshSnapshotResult and RefreshSnapshotErr are what RefreshSnapshot
	// reports; RefreshSnapshotCalls counts the calls, so a test can prove a run
	// checked the advisory database exactly once — or not at all.
	RefreshSnapshotResult vulnapp.SnapshotRefresh
	RefreshSnapshotErr    error
	RefreshSnapshotCalls  int
	// RefreshSnapshotWalkID records the walk the last refresh restricted its
	// advisory comparison to.
	RefreshSnapshotWalkID string

	// ToolchainAdvisories is what the seeded snapshot is taken to say under its
	// toolchain key; ToolchainErr fails the read instead. JudgeToolchain runs the
	// real domain judgment over them, so a test seeds advisories rather than a
	// conclusion and the fake cannot disagree with the shipped ranking.
	ToolchainAdvisories vulndomain.ToolchainAdvisorySet
	ToolchainErr        error
	// ToolchainVersion records the version the last judgment was asked about, so
	// a test can prove which of the walk's two toolchain versions was read.
	ToolchainVersion string
}

FakeScanWalk implements cli.ScanWalkUseCase.

func (*FakeScanWalk) JudgeToolchain

func (f *FakeScanWalk) JudgeToolchain(_ context.Context, snapshot vulndomain.DatabaseSnapshot, toolchainVersion string) (vulndomain.ToolchainJudgment, error)

JudgeToolchain judges the seeded toolchain advisories with the real domain rule.

func (*FakeScanWalk) RefreshSnapshot

func (f *FakeScanWalk) RefreshSnapshot(_ context.Context, walkID string) (vulnapp.SnapshotRefresh, error)

RefreshSnapshot reports the seeded refresh outcome and counts the call.

func (*FakeScanWalk) ReusableRun

func (f *FakeScanWalk) ReusableRun(_ context.Context, walkID, projectDir string) (vulndomain.WalkScanRun, bool, error)

ReusableRun reports the seeded reusable run, if any.

func (*FakeScanWalk) Scan

func (*FakeScanWalk) ServeReusableRun

func (f *FakeScanWalk) ServeReusableRun(run vulndomain.WalkScanRun, surface string) error

ServeReusableRun records the serving the caller witnessed.

type FakeScanWalkProgress

type FakeScanWalkProgress struct {
	Coord  coordinate.ModuleCoordinate
	Record vulndomain.VulnerabilityRecord
	Index  int // 1-based; 0 means use slice position
	Total  int // 0 means use len(ProgressRecords)
}

FakeScanWalkProgress is one entry delivered to the Progress callback.

type ServedRun

type ServedRun struct {
	RunID   string
	WalkID  string
	Surface string
}

ServedRun is one witnessed serving of a stored scan run.

Jump to

Keyboard shortcuts

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