contenttest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package contenttest is the conformance suite for contracts.Service, and a fake that passes it.

It exists because an interface is justified by a passing fake and not by a second production implementation (AGENTS.md rule 8). RunService is the specification of the lifecycle written as executable cases; the real service and the fake both run it, so "the fake behaves like the real thing" is a test result rather than a hope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunService

func RunService(t *testing.T, h Harness)

RunService is the conformance suite. Every implementation of contracts.Service passes it, or it is not one.

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake is contracts.Service over a map: the same rules, no database, no transaction. A consumer that wants to test what it does when a page is published takes one of these instead of a Postgres.

It ignores the transaction it is handed, and that is the honest limit of it: it cannot tell a caller that a write did not commit, because nothing here commits. Everything it can be wrong about is what RunService checks.

func NewFake

func NewFake() *Fake

NewFake returns an empty store.

func (*Fake) Archive

func (f *Fake) Archive(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)

Archive mirrors internal.Service.Archive.

func (*Fake) Contents

func (f *Fake) Contents() map[uuid.UUID]contracts.Content

Contents is everything the fake holds, for a consumer asserting on state.

func (*Fake) Public

func (f *Fake) Public(_ context.Context, _ db.Tx[db.Tenant], slug string) (*contracts.Content, error)

Public mirrors internal.Service.Public: the published row at this slug and nothing else.

func (*Fake) Publish

func (f *Fake) Publish(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)

Publish mirrors internal.Service.Publish.

func (*Fake) Published

func (f *Fake) Published() []string

Published is the names of the events the fake would have emitted.

func (*Fake) Put

func (f *Fake) Put(c *contracts.Content) uuid.UUID

Put stores content, giving it an id if it has none, and returns the id. It is the fake's stand-in for the create route, normalising the slug the way Validate does on the way through.

func (*Fake) Unpublish

func (f *Fake) Unpublish(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)

Unpublish mirrors internal.Service.Unpublish.

type Fixture

type Fixture struct {
	Ctx     context.Context
	Tx      db.Tx[db.Tenant]
	Service contracts.Service
	// Seed stores content and returns the id it was given. It is the one thing
	// the suite cannot do through the interface, because the interface is the
	// lifecycle and creating a page is kit/rest's five routes.
	Seed func(*contracts.Content) uuid.UUID
	// Published is the events the implementation has published so far, in
	// order. Half of what the lifecycle promises is silence: publishing what is
	// already published is a second click on a button, not a second
	// publication, and a subscriber must not hear about it.
	Published func() []string
}

Fixture is one case's world: a Service, the transaction its commands take, and a store to put content in.

type Harness

type Harness func(t *testing.T, run func(Fixture))

Harness builds one Fixture and calls run with it, because the real service's fixture is a transaction and a transaction is a scope somebody has to close.

Jump to

Keyboard shortcuts

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