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 ¶
- func RunService(t *testing.T, h Harness)
- type Fake
- func (f *Fake) Archive(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)
- func (f *Fake) Contents() map[uuid.UUID]contracts.Content
- func (f *Fake) Public(_ context.Context, _ db.Tx[db.Tenant], slug string) (*contracts.Content, error)
- func (f *Fake) Publish(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)
- func (f *Fake) Published() []string
- func (f *Fake) Put(c *contracts.Content) uuid.UUID
- func (f *Fake) Unpublish(_ context.Context, _ db.Tx[db.Tenant], id uuid.UUID) (*contracts.Content, error)
- type Fixture
- type Harness
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunService ¶
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 (*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) 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.
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.