Documentation
¶
Overview ¶
Package pkgtest provides test helpers for cataloger and parser testing, including automatic observation tracking for capability documentation.
Package pkgtest provides test helpers for cataloger and parser testing, including resolver decorators that track file access patterns.
Index ¶
- func AssertPackagesEqual(t *testing.T, a, b pkg.Package, userOpts ...cmp.Option)
- func AssertPackagesEqualIgnoreLayers(t *testing.T, a, b pkg.Package, userOpts ...cmp.Option)
- func Context() context.Context
- func TestCataloger(t *testing.T, fixtureDir string, cataloger pkg.Cataloger, ...)
- func TestCatalogerFromFileSource(t *testing.T, fixturePath string, cataloger pkg.Cataloger, ...)
- func TestFileParser(t *testing.T, fixturePath string, parser generic.Parser, ...)
- func TestFileParserWithEnv(t *testing.T, fixturePath string, parser generic.Parser, ...)
- func WriteResultsIfEnabled() error
- type CatalogTester
- func (p *CatalogTester) Expects(pkgs []pkg.Package, relationships []artifact.Relationship) *CatalogTester
- func (p *CatalogTester) ExpectsAssertion(...) *CatalogTester
- func (p *CatalogTester) ExpectsPackageStrings(expected []string) *CatalogTester
- func (p *CatalogTester) ExpectsRelationshipStrings(expected []string) *CatalogTester
- func (p *CatalogTester) ExpectsResolverContentQueries(locations []string) *CatalogTester
- func (p *CatalogTester) ExpectsResolverPathResponses(locations []string) *CatalogTester
- func (p *CatalogTester) FromDirectory(t *testing.T, path string) *CatalogTester
- func (p *CatalogTester) FromFile(t *testing.T, path string) *CatalogTester
- func (p *CatalogTester) FromFileSource(t *testing.T, path string) *CatalogTester
- func (p *CatalogTester) FromString(location, data string) *CatalogTester
- func (p *CatalogTester) IgnoreLocationLayer() *CatalogTester
- func (p *CatalogTester) IgnorePackageFields(fields ...string) *CatalogTester
- func (p *CatalogTester) IgnoreUnfulfilledPathResponses(paths ...string) *CatalogTester
- func (p *CatalogTester) TestCataloger(t *testing.T, cataloger pkg.Cataloger)
- func (p *CatalogTester) TestParser(t *testing.T, parser generic.Parser)
- func (p *CatalogTester) WithCompareOptions(opts ...cmp.Option) *CatalogTester
- func (p *CatalogTester) WithContext(ctx context.Context) *CatalogTester
- func (p *CatalogTester) WithEnv(env *generic.Environment) *CatalogTester
- func (p *CatalogTester) WithError() *CatalogTester
- func (p *CatalogTester) WithErrorAssertion(a require.ErrorAssertionFunc) *CatalogTester
- func (p *CatalogTester) WithImageResolver(t *testing.T, fixtureName string) *CatalogTester
- func (p *CatalogTester) WithLinuxRelease(r linux.Release) *CatalogTester
- func (p *CatalogTester) WithPackageStringer(fn func(pkg.Package) string) *CatalogTester
- func (p *CatalogTester) WithResolver(r file.Resolver) *CatalogTester
- func (p *CatalogTester) WithoutTestObserver() *CatalogTester
- type MetadataTracker
- func (t *MetadataTracker) RecordCataloger(catalogerName, metadataType string)
- func (t *MetadataTracker) RecordCatalogerObservations(packageName, catalogerName string, pkgs []pkg.Package, ...)
- func (t *MetadataTracker) RecordCatalogerPackageMetadata(catalogerName string, p pkg.Package)
- func (t *MetadataTracker) RecordCatalogerPackageType(catalogerName, pkgType string)
- func (t *MetadataTracker) RecordParser(packageName, parserFunction, metadataType string)
- func (t *MetadataTracker) RecordParserObservations(packageName, parserFunction string, pkgs []pkg.Package, ...)
- func (t *MetadataTracker) RecordParserPackageMetadata(packageName, parserFunction string, p pkg.Package)
- func (t *MetadataTracker) RecordParserPackageType(packageName, parserFunction, pkgType string)
- func (t *MetadataTracker) WriteResults() error
- type ObservingResolver
- func (r *ObservingResolver) AllContentQueries() []string
- func (r *ObservingResolver) AllLocations(ctx context.Context) <-chan file.Location
- func (r *ObservingResolver) AllPathQueries() map[string][]string
- func (r *ObservingResolver) FileContentsByLocation(location file.Location) (io.ReadCloser, error)
- func (r *ObservingResolver) FileMetadataByLocation(location file.Location) (file.Metadata, error)
- func (r *ObservingResolver) FilesByGlob(patterns ...string) ([]file.Location, error)
- func (r *ObservingResolver) FilesByMIMEType(types ...string) ([]file.Location, error)
- func (r *ObservingResolver) FilesByPath(paths ...string) ([]file.Location, error)
- func (r *ObservingResolver) HasPath(path string) bool
- func (r *ObservingResolver) HasUnfulfilledPathRequests() bool
- func (r *ObservingResolver) ObservedContentQueries(path string) bool
- func (r *ObservingResolver) ObservedPathQuery(input string) bool
- func (r *ObservingResolver) ObservedPathResponses(path string) bool
- func (r *ObservingResolver) PrettyUnfulfilledPathRequests() string
- func (r *ObservingResolver) PruneUnfulfilledPathResponses(ignore map[string][]string, ignorePaths ...string)
- func (r *ObservingResolver) RelativeFileByPath(location file.Location, path string) *file.Location
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertPackagesEqual ¶ added in v0.61.0
func AssertPackagesEqualIgnoreLayers ¶ added in v1.21.0
func TestCataloger ¶ added in v1.11.0
func TestCatalogerFromFileSource ¶ added in v1.25.0
func TestFileParser ¶
func TestFileParserWithEnv ¶
func WriteResultsIfEnabled ¶ added in v1.37.0
func WriteResultsIfEnabled() error
WriteResultsIfEnabled writes results if tracking is enabled. this is typically called via t.Cleanup() in tests.
Types ¶
type CatalogTester ¶
type CatalogTester struct {
// contains filtered or unexported fields
}
func NewCatalogTester ¶
func NewCatalogTester() *CatalogTester
func (*CatalogTester) Expects ¶
func (p *CatalogTester) Expects(pkgs []pkg.Package, relationships []artifact.Relationship) *CatalogTester
func (*CatalogTester) ExpectsAssertion ¶ added in v1.5.0
func (p *CatalogTester) ExpectsAssertion(a func(t *testing.T, pkgs []pkg.Package, relationships []artifact.Relationship)) *CatalogTester
func (*CatalogTester) ExpectsPackageStrings ¶ added in v1.6.0
func (p *CatalogTester) ExpectsPackageStrings(expected []string) *CatalogTester
func (*CatalogTester) ExpectsRelationshipStrings ¶ added in v1.6.0
func (p *CatalogTester) ExpectsRelationshipStrings(expected []string) *CatalogTester
func (*CatalogTester) ExpectsResolverContentQueries ¶ added in v0.71.0
func (p *CatalogTester) ExpectsResolverContentQueries(locations []string) *CatalogTester
func (*CatalogTester) ExpectsResolverPathResponses ¶ added in v0.71.0
func (p *CatalogTester) ExpectsResolverPathResponses(locations []string) *CatalogTester
func (*CatalogTester) FromDirectory ¶ added in v0.60.3
func (p *CatalogTester) FromDirectory(t *testing.T, path string) *CatalogTester
func (*CatalogTester) FromFile ¶
func (p *CatalogTester) FromFile(t *testing.T, path string) *CatalogTester
func (*CatalogTester) FromFileSource ¶ added in v1.25.0
func (p *CatalogTester) FromFileSource(t *testing.T, path string) *CatalogTester
func (*CatalogTester) FromString ¶
func (p *CatalogTester) FromString(location, data string) *CatalogTester
func (*CatalogTester) IgnoreLocationLayer ¶
func (p *CatalogTester) IgnoreLocationLayer() *CatalogTester
func (*CatalogTester) IgnorePackageFields ¶ added in v0.61.0
func (p *CatalogTester) IgnorePackageFields(fields ...string) *CatalogTester
func (*CatalogTester) IgnoreUnfulfilledPathResponses ¶ added in v0.71.0
func (p *CatalogTester) IgnoreUnfulfilledPathResponses(paths ...string) *CatalogTester
func (*CatalogTester) TestCataloger ¶
func (p *CatalogTester) TestCataloger(t *testing.T, cataloger pkg.Cataloger)
func (*CatalogTester) TestParser ¶
func (p *CatalogTester) TestParser(t *testing.T, parser generic.Parser)
func (*CatalogTester) WithCompareOptions ¶ added in v0.71.0
func (p *CatalogTester) WithCompareOptions(opts ...cmp.Option) *CatalogTester
func (*CatalogTester) WithContext ¶ added in v1.23.0
func (p *CatalogTester) WithContext(ctx context.Context) *CatalogTester
func (*CatalogTester) WithEnv ¶
func (p *CatalogTester) WithEnv(env *generic.Environment) *CatalogTester
func (*CatalogTester) WithError ¶
func (p *CatalogTester) WithError() *CatalogTester
func (*CatalogTester) WithErrorAssertion ¶
func (p *CatalogTester) WithErrorAssertion(a require.ErrorAssertionFunc) *CatalogTester
func (*CatalogTester) WithImageResolver ¶
func (p *CatalogTester) WithImageResolver(t *testing.T, fixtureName string) *CatalogTester
func (*CatalogTester) WithLinuxRelease ¶
func (p *CatalogTester) WithLinuxRelease(r linux.Release) *CatalogTester
func (*CatalogTester) WithPackageStringer ¶ added in v1.6.0
func (p *CatalogTester) WithPackageStringer(fn func(pkg.Package) string) *CatalogTester
func (*CatalogTester) WithResolver ¶
func (p *CatalogTester) WithResolver(r file.Resolver) *CatalogTester
func (*CatalogTester) WithoutTestObserver ¶ added in v1.37.0
func (p *CatalogTester) WithoutTestObserver() *CatalogTester
type MetadataTracker ¶ added in v1.37.0
type MetadataTracker struct {
// contains filtered or unexported fields
}
MetadataTracker collects metadata type and package type usage during test execution
func (*MetadataTracker) RecordCataloger ¶ added in v1.37.0
func (t *MetadataTracker) RecordCataloger(catalogerName, metadataType string)
RecordCataloger records a metadata type usage for a cataloger
func (*MetadataTracker) RecordCatalogerObservations ¶ added in v1.37.0
func (t *MetadataTracker) RecordCatalogerObservations( packageName, catalogerName string, pkgs []pkg.Package, relationships []artifact.Relationship, )
RecordCatalogerObservations records comprehensive observations for a cataloger.
func (*MetadataTracker) RecordCatalogerPackageMetadata ¶ added in v1.37.0
func (t *MetadataTracker) RecordCatalogerPackageMetadata(catalogerName string, p pkg.Package)
RecordCatalogerPackageMetadata extracts and records metadata type and package type from a package for a cataloger
func (*MetadataTracker) RecordCatalogerPackageType ¶ added in v1.37.0
func (t *MetadataTracker) RecordCatalogerPackageType(catalogerName, pkgType string)
RecordCatalogerPackageType records a package type usage for a cataloger
func (*MetadataTracker) RecordParser ¶ added in v1.37.0
func (t *MetadataTracker) RecordParser(packageName, parserFunction, metadataType string)
RecordParser records a metadata type usage for a parser function
func (*MetadataTracker) RecordParserObservations ¶ added in v1.37.0
func (t *MetadataTracker) RecordParserObservations( packageName, parserFunction string, pkgs []pkg.Package, relationships []artifact.Relationship, )
RecordParserObservations records comprehensive observations for a parser.
func (*MetadataTracker) RecordParserPackageMetadata ¶ added in v1.37.0
func (t *MetadataTracker) RecordParserPackageMetadata(packageName, parserFunction string, p pkg.Package)
RecordParserPackageMetadata extracts and records metadata type and package type from a package for a parser
func (*MetadataTracker) RecordParserPackageType ¶ added in v1.37.0
func (t *MetadataTracker) RecordParserPackageType(packageName, parserFunction, pkgType string)
RecordParserPackageType records a package type usage for a parser function
func (*MetadataTracker) WriteResults ¶ added in v1.37.0
func (t *MetadataTracker) WriteResults() error
WriteResults writes the collected observation data to test-fixtures/test-observations.json.
type ObservingResolver ¶ added in v0.71.0
type ObservingResolver struct {
// contains filtered or unexported fields
}
ObservingResolver wraps a file.Resolver to observe and track all file access patterns. it records what paths were queried, what was returned, and what file contents were read. this is useful for validating that catalogers use appropriate glob patterns and don't over-read files.
func NewObservingResolver ¶ added in v0.71.0
func NewObservingResolver(resolver file.Resolver) *ObservingResolver
NewObservingResolver creates a new ObservingResolver that wraps the given resolver.
func (*ObservingResolver) AllContentQueries ¶ added in v0.71.0
func (r *ObservingResolver) AllContentQueries() []string
AllContentQueries returns a deduplicated list of all file paths whose content was read.
func (*ObservingResolver) AllLocations ¶ added in v0.71.0
func (r *ObservingResolver) AllLocations(ctx context.Context) <-chan file.Location
AllLocations returns all file locations known to the resolver.
func (*ObservingResolver) AllPathQueries ¶ added in v0.71.0
func (r *ObservingResolver) AllPathQueries() map[string][]string
AllPathQueries returns all path query patterns grouped by method name.
func (*ObservingResolver) FileContentsByLocation ¶ added in v0.71.0
func (r *ObservingResolver) FileContentsByLocation(location file.Location) (io.ReadCloser, error)
FileContentsByLocation returns a reader for the contents of the file at the given location.
func (*ObservingResolver) FileMetadataByLocation ¶ added in v0.71.0
FileMetadataByLocation returns metadata for the file at the given location.
func (*ObservingResolver) FilesByGlob ¶ added in v0.71.0
func (r *ObservingResolver) FilesByGlob(patterns ...string) ([]file.Location, error)
FilesByGlob returns files matching the given glob patterns.
func (*ObservingResolver) FilesByMIMEType ¶ added in v0.71.0
func (r *ObservingResolver) FilesByMIMEType(types ...string) ([]file.Location, error)
FilesByMIMEType returns files matching the given MIME types.
func (*ObservingResolver) FilesByPath ¶ added in v0.71.0
func (r *ObservingResolver) FilesByPath(paths ...string) ([]file.Location, error)
FilesByPath returns files matching the given paths.
func (*ObservingResolver) HasPath ¶ added in v0.71.0
func (r *ObservingResolver) HasPath(path string) bool
HasPath returns true if the resolver knows about the given path.
func (*ObservingResolver) HasUnfulfilledPathRequests ¶ added in v0.71.0
func (r *ObservingResolver) HasUnfulfilledPathRequests() bool
HasUnfulfilledPathRequests returns true if there are any paths that were queried but returned empty.
func (*ObservingResolver) ObservedContentQueries ¶ added in v0.71.0
func (r *ObservingResolver) ObservedContentQueries(path string) bool
ObservedContentQueries checks if a specific file's content was read.
func (*ObservingResolver) ObservedPathQuery ¶ added in v0.71.0
func (r *ObservingResolver) ObservedPathQuery(input string) bool
ObservedPathQuery checks if a specific path pattern was queried.
func (*ObservingResolver) ObservedPathResponses ¶ added in v0.71.0
func (r *ObservingResolver) ObservedPathResponses(path string) bool
ObservedPathResponses checks if a specific path was returned in any response.
func (*ObservingResolver) PrettyUnfulfilledPathRequests ¶ added in v0.71.0
func (r *ObservingResolver) PrettyUnfulfilledPathRequests() string
PrettyUnfulfilledPathRequests returns a formatted string of all unfulfilled path requests.
func (*ObservingResolver) PruneUnfulfilledPathResponses ¶ added in v0.71.0
func (r *ObservingResolver) PruneUnfulfilledPathResponses(ignore map[string][]string, ignorePaths ...string)
PruneUnfulfilledPathResponses removes specified paths from the unfulfilled requests tracking. ignore maps method names to paths that should be ignored for that method. ignorePaths lists paths that should be ignored for all methods.
func (*ObservingResolver) RelativeFileByPath ¶ added in v0.71.0
RelativeFileByPath returns a file at a path relative to the given location.