Documentation ¶
Overview ¶
Package postgres contains testing helpers for PostgreSQL databases.
Most of the functions provide independent implementations of functionality that the datastore/postgres package does internally in its exposed API.
Test Databases ¶
The TestIndexerDB and TestMatcherDB start database engines and create suitable databases as needed. See the test/integration package for more information on the specifics of the former.
As part of the database setup, these functions can load SQL files. This package searches both its embedded copy of the local "sql" directory and the main test package's "testdata" director for these patterns:
- all_*.psql
- matcher_*.psql (for TestMatcherDB)
- indexer_*.psql (for TestIndexerDB)
Index ¶
- func InsertDistScanArtifacts(ctx context.Context, pool *pgxpool.Pool, layerHash claircore.Digest, ...) error
- func InsertDistributions(ctx context.Context, pool *pgxpool.Pool, dists []*claircore.Distribution) error
- func InsertPackageScanArtifacts(ctx context.Context, pool *pgxpool.Pool, layerHash claircore.Digest, ...) error
- func InsertPackages(ctx context.Context, pool *pgxpool.Pool, pkgs []*claircore.Package) error
- func InsertRepoScanArtifact(ctx context.Context, pool *pgxpool.Pool, layerHash claircore.Digest, ...) error
- func InsertRepositories(ctx context.Context, pool *pgxpool.Pool, repos []*claircore.Repository) error
- func InsertScannerList(ctx context.Context, pool *pgxpool.Pool, hash claircore.Digest, n int) error
- func InsertUniqueScanners(ctx context.Context, pool *pgxpool.Pool, scnrs indexer.VersionedScanners) error
- func TestIndexerDB(ctx context.Context, t testing.TB) *pgxpool.Pool
- func TestMatcherDB(ctx context.Context, t testing.TB) *pgxpool.Pool
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InsertDistScanArtifacts ¶
func InsertDistScanArtifacts(ctx context.Context, pool *pgxpool.Pool, layerHash claircore.Digest, dists []*claircore.Distribution, scnrs indexer.VersionedScanners) error
InsertDistScanArtifacts will create DistributionScanArtifacts linking the layer hash, dist, and scanner artifacts.
If multiple scanners are provided they will be linked in i % n fashion where "i" is the current index of the dists slice and "n" is the length of the scnrs slice.
func InsertDistributions ¶
func InsertPackageScanArtifacts ¶
func InsertPackageScanArtifacts(ctx context.Context, pool *pgxpool.Pool, layerHash claircore.Digest, pkgs []*claircore.Package, scnrs indexer.VersionedScanners) error
InsertPackageScanArtifacts will create ScanArtifacts linking the layer hash, packages, and scanner artifacts.
If multiple scanners are provided they will be linked in i % n fashion where "i" is the current index of the Packages array and "n" is the length of the scanners array.
func InsertPackages ¶
InsertUniquePackages inserts each unique package into the database. Nested distribution and source packages are un nested and inserted. The pkgs array should be created by a call to GenUniquePackages
func InsertRepoScanArtifact ¶
func InsertRepositories ¶
func InsertScannerList ¶
InsertScannerList is to be used with `test.GenUniqueScanners()`. Inserts a ScannerList record for scanner IDs 0...n associated with provided manifest hash
func InsertUniqueScanners ¶
func InsertUniqueScanners(ctx context.Context, pool *pgxpool.Pool, scnrs indexer.VersionedScanners) error
InsertUniqueScanners inserts each unique scanner into the database. the scanner's primary key (int) is set to the index of the scanner in the array.
func TestIndexerDB ¶ added in v1.4.5
TestIndexerDB returns a pgxpool.Pool connected to a started and configured for a Indexer database.
If any errors are encountered, the test is failed and exited.
func TestMatcherDB ¶ added in v1.4.5
TestMatcherDB returns a pgxpool.Pool connected to a started and configured for a Matcher database.
If any errors are encountered, the test is failed and exited.
Types ¶
This section is empty.
Notes ¶
Bugs ¶
The Test*DB functions close over the passed-in Context and use it for the Cleanup method. Because Cleanup functions are earlier in the stack than any defers inside the test, make sure the Context isn't one that's deferred to be canceled.