storetest

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 29 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each(t *testing.T, fn func(t *testing.T, s store.Store))

Each runs fn once per backend, as a subtest named after it, against a migrated store of that backend.

func FindRecord

func FindRecord(t *testing.T, s store.Store, rid id.UsageID) *usage.Record

FindRecord returns the record with the given id from an unfiltered query.

func InsertRecord

func InsertRecord(t *testing.T, s store.Store, r *usage.Record)

InsertRecord stores r.

func InsertTenant

func InsertTenant(t *testing.T, s store.Store) *tenant.Tenant

InsertTenant stores a fresh tenant with a unique slug and returns it.

func Key

func Key(tenantID id.TenantID, name string) *key.APIKey

Key builds a key with every field filled. Two keys with one name still get different prefixes and hashes.

func MongoClient

func MongoClient(t *testing.T) *mongodrv.Client

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

func Now() time.Time

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

func OpenMongoDB(t *testing.T) (db *grove.DB, name string)

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

func OpenPostgresDB(t *testing.T) *grove.DB

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

func OpenSQLiteDB(t *testing.T) *grove.DB

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

func Record(tenantID id.TenantID, cost string) *usage.Record

Record builds a usage record with every field filled. An empty cost builds an unpriced record (nil cost, unpriced_model).

func SameKey

func SameKey(t *testing.T, got, want *key.APIKey)

SameKey fails the test unless got and want match field by field.

func SameRecord

func SameRecord(t *testing.T, got, want *usage.Record)

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

func SameTenant(t *testing.T, got, want *tenant.Tenant)

SameTenant fails the test unless got and want match field by field.

func Tenant

func Tenant(slug string) *tenant.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

func UsageMetadataFilterRejectsBadKeys(t *testing.T, s store.Store)

UsageMetadataFilterRejectsBadKeys checks a filter is validated like record metadata, on both reads.

func UsageMetadataRoundTrips

func UsageMetadataRoundTrips(t *testing.T, s store.Store)

UsageMetadataRoundTrips checks that metadata comes back equal, and that a record stored without any reads back as an empty, non-nil map.

func UsageQueryFiltersByMetadata

func UsageQueryFiltersByMetadata(t *testing.T, s store.Store)

UsageQueryFiltersByMetadata checks the filter is exact, needs every pair, and pages without losing or repeating a record.

func UsageSeriesFiltersByMetadata

func UsageSeriesFiltersByMetadata(t *testing.T, s store.Store)

UsageSeriesFiltersByMetadata checks a series sums only the matching records.

Types

This section is empty.

Jump to

Keyboard shortcuts

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