apptest

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package apptest is the compiled source for docs/guide/testing-your-app.md: a small application, and the specs that hold it to the library's contracts.

templ: version: v0.3.1020

Index

Constants

View Source
const (
	EventInc   = "count.inc"
	EventReset = "count.reset"

	FragmentValue = "count.value"
	FragmentLabel = "count.label"
)

Variables

View Source
var (
	Admin = User{Name: "admin"}
	Guest = User{Name: "guest"}
)

Admin and Guest are the two identities the specs bind a session to.

Functions

func Authorize

func Authorize(_ context.Context, sess live.Session[User], ev live.Event) error

Authorize is a hook a spec can call directly, given a Session.

func Config

func Config(origins []string) live.Config[State, User]

Config is the application, built by a function so a spec can construct one without a running server.

func LabelRegion

func LabelRegion(s State) templ.Component

func ValueRegion

func ValueRegion(s State) templ.Component

Types

type State

type State struct {
	N      int
	Resets int
}

State is one session's view.

func Reduce

func Reduce(s State, ev live.Event) (State, []live.Effect[User])

Reduce is the pure state transition under test.

type User

type User struct {
	// Name is the subject, and what Authorize compares.
	Name string
}

User is the identity this application binds a session to.

One type rather than two since 2026-09-03: a Config carries its identity type as a type parameter, so an application has exactly one, and "an admin" and "a guest" are two VALUES of it rather than two types. That is also the honest model — a real application authenticates one kind of principal and reads a role off it.

func (User) Subject

func (u User) Subject() string

Subject is the stable identifier the library logs and counts sessions by.

Jump to

Keyboard shortcuts

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