Documentation
¶
Overview ¶
Package storetest runs one conformance test body against every Nexus store backend: memory and SQLite always, PostgreSQL when NEXUS_TEST_POSTGRES_DSN is set and MongoDB when NEXUS_TEST_MONGO_URI is set. Each subtest gets a database nothing else touches.
Index ¶
- func Each(t *testing.T, fn func(t *testing.T, s store.Store))
- func FindRecord(t *testing.T, s store.Store, rid id.UsageID) *usage.Record
- func InsertRecord(t *testing.T, s store.Store, r *usage.Record)
- func InsertTenant(t *testing.T, s store.Store) *tenant.Tenant
- func Key(tenantID id.TenantID, name string) *key.APIKey
- func MongoClient(t *testing.T) *mongodrv.Client
- func Now() time.Time
- func OpenMongoDB(t *testing.T) (db *grove.DB, name string)
- func OpenPostgresDB(t *testing.T) *grove.DB
- func OpenSQLiteDB(t *testing.T) *grove.DB
- func Record(tenantID id.TenantID, cost string) *usage.Record
- func SameKey(t *testing.T, got, want *key.APIKey)
- func SameRecord(t *testing.T, got, want *usage.Record)
- func SameTenant(t *testing.T, got, want *tenant.Tenant)
- func Tenant(slug string) *tenant.Tenant
- func UsageMetadataFilterRejectsBadKeys(t *testing.T, s store.Store)
- func UsageMetadataRoundTrips(t *testing.T, s store.Store)
- func UsageQueryFiltersByMetadata(t *testing.T, s store.Store)
- func UsageSeriesFiltersByMetadata(t *testing.T, s store.Store)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Each ¶
Each runs fn once per backend, as a subtest named after it, against a migrated store of that backend.
func FindRecord ¶
FindRecord returns the record with the given id from an unfiltered query.
func InsertRecord ¶
InsertRecord stores r.
func InsertTenant ¶
InsertTenant stores a fresh tenant with a unique slug and returns it.
func Key ¶
Key builds a key with every field filled. Two keys with one name still get different prefixes and hashes.
func MongoClient ¶
MongoClient connects to the server NEXUS_TEST_MONGO_URI names, for tests that write raw documents. It is closed when the test ends.
func Now ¶
Now is a timestamp every backend stores exactly: UTC, whole seconds. SQLite keeps tenant and key times as RFC3339 text with no fraction, and Mongo keeps milliseconds.
func OpenMongoDB ¶
OpenMongoDB opens a database of this test's own on the server NEXUS_TEST_MONGO_URI names and drops it when the test ends. It returns the database name so a test can write raw documents. It skips when the variable is unset and refuses the default port.
func OpenPostgresDB ¶
OpenPostgresDB opens the database NEXUS_TEST_POSTGRES_DSN names, confined to a schema of this test's own that is dropped when the test ends. It skips when the variable is unset and refuses the default port.
func OpenSQLiteDB ¶
OpenSQLiteDB opens an empty SQLite database in the test's temp dir. It is not migrated, so a test can lay down a legacy schema first.
func Record ¶
Record builds a usage record with every field filled. An empty cost builds an unpriced record (nil cost, unpriced_model).
func SameRecord ¶
SameRecord fails the test unless got and want match field by field. Cost is compared as an amount, so 0.150 and 0.15 are the same.
func SameTenant ¶
SameTenant fails the test unless got and want match field by field.
func Tenant ¶
Tenant builds a tenant with every field filled, so a backend that drops a field fails the round trip instead of passing it by omission.
func UsageMetadataFilterRejectsBadKeys ¶
UsageMetadataFilterRejectsBadKeys checks a filter is validated like record metadata, on both reads.
func UsageMetadataRoundTrips ¶
UsageMetadataRoundTrips checks that metadata comes back equal, and that a record stored without any reads back as an empty, non-nil map.
func UsageQueryFiltersByMetadata ¶
UsageQueryFiltersByMetadata checks the filter is exact, needs every pair, and pages without losing or repeating a record.
Types ¶
This section is empty.