test

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 25 Imported by: 0

README

Store tests

How to test store with MySQL?

  1. Create a database in your MySQL server.
  2. Run the following command with two environment variables set:
DRIVER=mysql DSN=root@/memos_test go test -v ./test/store/...
  • DRIVER should be set to mysql.
  • DSN should be set to the DSN of your MySQL server.

Documentation

Index

Constants

View Source
const (

	// Memos container settings for migration testing.
	MemosDockerImage   = "neosmemo/memos"
	StableMemosVersion = "stable" // Always points to the latest stable release
)

Variables

View Source
var MemosStartupWaitStrategy = wait.ForAll(
	wait.ForLog("(started successfully|has been started on port)").AsRegexp(),
	wait.ForListeningPort("5230/tcp"),
).WithDeadline(180 * time.Second)

MemosStartupWaitStrategy defines the wait strategy for Memos container startup. Uses regex to match various log message formats across versions.

Functions

func GetMySQLDSN added in v0.26.0

func GetMySQLDSN(t *testing.T) string

GetMySQLDSN starts a MySQL container (if not already running) and creates a fresh database for this test.

func GetPostgresDSN added in v0.26.0

func GetPostgresDSN(t *testing.T) string

GetPostgresDSN starts a PostgreSQL container (if not already running) and creates a fresh database for this test.

func NewTestingStore

func NewTestingStore(ctx context.Context, t *testing.T) *store.Store

NewTestingStore creates a new testing store with a fresh database. Each test gets its own isolated database:

  • SQLite: new temp file per test
  • MySQL/PostgreSQL: new database per test in shared container

func NewTestingStoreWithDSN added in v0.26.0

func NewTestingStoreWithDSN(_ context.Context, t *testing.T, driver, dsn string) *store.Store

NewTestingStoreWithDSN creates a testing store connected to a specific DSN. This is useful for testing migrations on existing data.

func StartMemosContainer added in v0.26.0

func StartMemosContainer(ctx context.Context, cfg MemosContainerConfig) (testcontainers.Container, error)

StartMemosContainer starts a Memos container for migration testing. For SQLite, it mounts the dataDir to /var/opt/memos.

func TerminateContainers added in v0.26.0

func TerminateContainers()

TerminateContainers cleans up all running containers and network. This is typically called from TestMain.

Types

type MemosContainerConfig added in v0.26.0

type MemosContainerConfig struct {
	Version string // Memos version tag (e.g., "0.24.0")
	Driver  string // Database driver: sqlite, mysql, postgres
	DSN     string // Database DSN (for mysql/postgres)
	DataDir string // Host directory to mount for SQLite data
}

MemosContainerConfig holds configuration for starting a Memos container.

Jump to

Keyboard shortcuts

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