notificationtest

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

Index

Constants

This section is empty.

Variables

View Source
var (
	Ada      = uuid.New()
	Bob      = uuid.New()
	AdaEmail = "ada@acme.example.com"
)

Ada is the recipient the suite writes to, and Bob is somebody else. They are exported because a harness has to tell the RecipientLookup which of them has an address: Ada does, Bob does not, which is what makes "a recipient with no address gets the row and no mail" a case.

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 slice: the same rules, no database, no transaction. A consumer that wants to test what it does when somebody is notified takes one of these instead of a Postgres.

It ignores the transaction it is handed, which is the honest limit of it: nothing here commits, so it cannot tell a caller that a write did not.

func NewFake

func NewFake() *Fake

NewFake returns an empty store in which Ada has an address and Bob does not, which is what the conformance suite's two cases are about.

func (*Fake) ListFor

func (f *Fake) ListFor(_ context.Context, _ db.Tx[db.Tenant], recipient uuid.UUID, q crud.Query) ([]*contracts.Notification, int64, error)

ListFor mirrors internal.Service.ListFor: this recipient's rows, newest first, then paged.

func (*Fake) MarkRead

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

MarkRead mirrors internal.Service.MarkRead.

func (*Fake) Notify

Notify mirrors internal.Service.Notify, validation and all.

func (*Fake) Published

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

Published is the names of the events the fake would have emitted, in order.

type Fixture

type Fixture struct {
	Ctx     context.Context
	Tx      db.Tx[db.Tenant]
	Service contracts.Service
	// Published is the names of the events published so far, in order. It is
	// what holds MarkRead to saying nothing the second time, which is the half
	// of the promise a return value cannot show.
	Published func() []string
}

Fixture is one case's world: a Service, the transaction its commands take, and a way to see what was published.

type Harness

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

Harness builds one Fixture and calls run with it. It is written this way round 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