package gctest

import "zgo.at/goatcounter/v2/gctest"

Package gctest contains testing helpers.

Index

Functions

func Context

func Context(db zdb.DB) context.Context

Context creates a new test context.

func DB

func DB(t testing.TB) context.Context

DB starts a new database test.

func DBFile

func DBFile(t testing.TB) context.Context

DBFile is like DB(), but guarantees that the database will be written to disk, whereas DB() may store it in memory.

You can get the connection string from the GCTEST_CONNECT environment variable.

func Reset

func Reset()

Reset global state.

func Site

func Site(ctx context.Context, t *testing.T, site *goatcounter.Site, user *goatcounter.User) context.Context

Site creates a new user/site pair.

You can set values for the site by passing the sute or user parameters, but they may be nul to just set them to some sensible defaults.

func StoreHits

func StoreHits(ctx context.Context, t *testing.T, wantFail bool, hits ...goatcounter.Hit) []goatcounter.Hit

StoreHits is a convenient helper to store hits in the DB via Memstore and cron.UpdateStats().

Source Files

gctest.go

Version
v2.5.0 (latest)
Published
Dec 14, 2023
Platform
linux/amd64
Imports
15 packages
Last checked
1 day ago

Tools for package owners.