Documentation
¶
Overview ¶
Package kittest is an in-memory test double for the kit authoring surface: a Room (plus Services/KV/config) you can drive from plain Go tests, with the sends, posts, and settle recorded for assertions.
r := kittest.NewRoom(kittest.Player("p1"), kittest.Player("p2"))
h := mygame.Game{}.NewRoom(r.Config(), r.Services())
h.OnStart(r)
h.OnJoin(r, r.Players[0])
h.OnInput(r, r.Players[0], kit.Input{Kind: kit.InputRune, Rune: ' '})
r.Advance(2 * time.Second) // move the room clock
h.OnWake(r)
frame := r.LastFrame(r.Players[0]) // assert on cells
The clock is virtual (starts at a fixed epoch, moves only via Advance) and the RNG is seeded, so tests are deterministic by default — mirroring the wasm room, not the native dev runner's wall clock.
Index ¶
- func Player(id string) kit.Player
- func String(f *kit.Frame, row int) string
- type Room
- func (r *Room) Advance(d time.Duration)
- func (r *Room) Config() kit.RoomConfig
- func (r *Room) Count() int
- func (r *Room) End(res kit.Result)
- func (r *Room) Has(p kit.Player) bool
- func (r *Room) Identical(f *kit.Frame)
- func (r *Room) LastFrame(p kit.Player) *kit.Frame
- func (r *Room) Log(msg string)
- func (r *Room) Members() []kit.Player
- func (r *Room) Now() time.Time
- func (r *Room) Post(res kit.Result)
- func (r *Room) Rand() *rand.Rand
- func (r *Room) Send(p kit.Player, f *kit.Frame)
- func (r *Room) Services() kit.Services
- func (r *Room) SetInputContext(c kit.InputContext)
- func (r *Room) Settled() bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Room ¶
type Room struct {
Players []kit.Player
Cfg kit.RoomConfig
Clock time.Time
RNG *rand.Rand
Frames map[string][]*kit.Frame // accountID -> sent frames (copies)
Ended *kit.Result
Posted []kit.Result
InputCtx kit.InputContext
Logs []string
KV map[string]map[string][]byte // accountID -> key -> value
KVRules map[string]map[string]kit.MergeRule
ConfigVals map[string][]byte
// gives the guest no error channel, so when the host's store fails it does
// NOT surface a Go error; it degrades exactly like this:
//
// - Get reports the key as missing (nil, false, nil)
// - Set and Delete return nil without persisting anything
//
// While true, the same happens here, and the backing maps keep whatever
// they held (the outage is transient, not a wipe). Use it to test the
// read-absent-reinit hazard: a game that does the natural
// `Get → missing → initialize starting balance → Set` resets a player's
// saved wallet during a store blip. Robust games treat "missing" wallet
// reads conservatively (e.g. re-read on a later wake before overwriting,
// or write with kit.MergeMax/kit.MergeSum so a blip-era write cannot
// clobber the durable value at merge time).
KVUnavailable bool
}
Room is the in-memory kit.Room double.
func NewRoom ¶
NewRoom returns a Room with the given members, a seeded RNG (seed 1), and a fixed-epoch virtual clock.
func (*Room) Config ¶
func (r *Room) Config() kit.RoomConfig
func (*Room) SetInputContext ¶
func (r *Room) SetInputContext(c kit.InputContext)
Click to show internal directories.
Click to hide internal directories.