testhelper

package
v0.10.0-rc7 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMigrateDatabase

func CreateMigrateDatabase(t testing.TB, dbFile string)

CreateMigrateDatabase creates the parent directory tree and a fresh SQLite database, then runs the same migrate.Up flow `ncps migrate up` uses in production. Empty DB → ent.Schema.Create → final schema including the §10b surrogate-id columns on weak entities. Tests can now perform Ent edge traversals (WithReferences/WithSignatures/ WithNarInfoNarFiles) that the legacy dbmate-only schema didn't support.

func MigrateMySQLDatabase added in v0.6.0

func MigrateMySQLDatabase(t *testing.T, dbURL string)

MigrateMySQLDatabase runs the same migrate.Up flow `ncps migrate up` uses in production: empty DB → ent.Schema.Create → final schema including the §10b surrogate-id columns on weak entities. Replaces the legacy dbmate invocation. The database URL should be in the format: mysql://user:password@host:port/database

func MigrateNarInfoToDatabase added in v0.8.0

func MigrateNarInfoToDatabase(
	ctx context.Context,
	dbClient *database.Client,
	hash string,
	ni *narinfo.NarInfo,
) error

MigrateNarInfoToDatabase migrates a single narinfo to the database via the Ent API. This is a test helper that mimics the migration logic in pkg/ncps/migrate_narinfo.go.

func MigratePostgresDatabase added in v0.6.0

func MigratePostgresDatabase(t *testing.T, dbURL string)

MigratePostgresDatabase runs the same migrate.Up flow `ncps migrate up` uses in production: empty DB → ent.Schema.Create → final schema including the §10b surrogate-id columns on weak entities. Replaces the legacy dbmate invocation. The database URL should be in the format: postgresql://user:password@host:port/database

func MustParseURL added in v0.0.14

func MustParseURL(t *testing.T, us string) *url.URL

MustParseURL parses the url (string) and returns or fails the test.

func MustRandBase16NarHash added in v0.9.0

func MustRandBase16NarHash() string

func MustRandBase32NarHash added in v0.9.0

func MustRandBase32NarHash() string

func MustRandNarInfoHash added in v0.8.5

func MustRandNarInfoHash() string

func MustRandString added in v0.8.5

func MustRandString(n int) string

MustRandString returns the string returned by RandString. If RandString returns an error, it will panic.

func RandBase16NarHash added in v0.9.0

func RandBase16NarHash() (string, error)

func RandBase32NarHash added in v0.9.0

func RandBase32NarHash() (string, error)

func RandNarInfoHash added in v0.8.5

func RandNarInfoHash() (string, error)

func RandString added in v0.8.5

func RandString(n int) (string, error)

RandString returns a random string of length n using crypto/rand.Reader as the random reader.

func RegisterNarInfoAsUnmigrated added in v0.9.0

func RegisterNarInfoAsUnmigrated(
	ctx context.Context,
	dbClient *database.Client,
	hash string,
	ni *narinfo.NarInfo,
) error

RegisterNarInfoAsUnmigrated registers a narinfo in the database as unmigrated (no URL).

func S3TestConfig added in v0.9.0

func S3TestConfig(t *testing.T) *s3.Config

S3TestConfig returns the S3 configuration for testing. It skips the test if any required environment variable is missing.

func SetupMySQL added in v0.7.2

func SetupMySQL(t *testing.T) (*database.Client, string, func())

SetupMySQL sets up a new temporary MySQL database for testing. It requires the NCPS_TEST_ADMIN_MYSQL_URL environment variable to be set. Returns the Ent-backed *database.Client, the database URL, and a cleanup function.

func SetupPostgres added in v0.7.2

func SetupPostgres(t *testing.T) (*database.Client, string, func())

SetupPostgres sets up a new temporary PostgreSQL database for testing. It requires the NCPS_TEST_ADMIN_POSTGRES_URL environment variable to be set. Returns the Ent-backed *database.Client, the database URL, and a cleanup function.

func SetupSQLite added in v0.8.0

func SetupSQLite(t *testing.T) (*database.Client, func())

SetupSQLite sets up a new temporary SQLite database for testing. It returns the Ent-backed *database.Client and a cleanup function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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