testutil

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides helpers for recording Slack API calls during tests.

The central type is Recorder, which captures every Slack API invocation made through a SlackClientMock built via NewSlackClientMock. Calls are stored in chronological order across all methods so that tests (in particular the Phase 0 regression protection golden tests under chat-session-redesign spec) can assert against a stable JSON serialization of the entire interaction.

Usage:

rec := testutil.NewRecorder()
client := testutil.NewSlackClientMock(rec)
// ... use client in production code paths ...
got := rec.CallsJSON()
golden.Assert(t, "fixture_name.json", got)

Determinism: timestamps returned from PostMessageContext are synthesized by the recorder as "1700000000.{seq:06d}" so no wall-clock randomness leaks into the captured stream. MsgOption values are decoded via slack.UnsafeApplyMsgOptions, which yields the same URL-encoded payload Slack itself would see on the wire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSlackClientMock

func NewSlackClientMock(r *Recorder) *mock.SlackClientMock

NewSlackClientMock constructs a SlackClientMock whose every method records invocations into the provided Recorder before returning safe default values.

Tests may override any Func field on the returned mock to customize a specific method's behavior (for example, to simulate a failure or to return a particular conversation history payload). When a Func is overridden the override is fully responsible for recording the call if that is desired.

Types

type Call

type Call struct {
	Seq    int             `json:"seq"`
	Method string          `json:"method"`
	Args   json.RawMessage `json:"args"`
}

Call captures a single Slack API invocation in a form suitable for deterministic JSON comparison.

type Recorder

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

Recorder stores Slack API calls in the order they were observed.

A Recorder is safe for concurrent use.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder constructs an empty Recorder.

func (*Recorder) Calls

func (r *Recorder) Calls() []Call

Calls returns a copy of the recorded calls in chronological order.

func (*Recorder) CallsJSON

func (r *Recorder) CallsJSON() []byte

CallsJSON marshals the recorded calls to a pretty-printed JSON byte slice suitable for direct golden file comparison.

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset clears all captured calls. The timestamp counter is also reset so that post/update calls after Reset start again at 1700000000.000001.

Jump to

Keyboard shortcuts

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