Help us shape the future of Go! Take the 2026 Go Developer Survey

fakeslack

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package fakeslack is a deterministic fake of the Slack Web API subset and the Socket Mode websocket used by connectors/slack. It is served from tests via httptest and from cmd/fakes inside kind.

Web API (under /api/): auth.test, users.info, conversations.open, chat.postMessage, apps.connections.open. Socket Mode: /link/?ticket=...

Test control:

POST /_test/dm          {user, text, event_id?, thread_ts?, channel?, bot_id?, subtype?, team_id?}
GET  /_test/posted      posted messages
GET  /_test/acks        recorded socket-mode acks
GET  /_test/envelopes   delivery state of every envelope
GET  /_test/connections number of open socket-mode connections
POST /_test/fail        {method, mode: "ambiguous"|"rate_limited"|"server_error"|<slack error>, count}
POST /_test/disconnect  close all socket-mode connections
POST /_test/reset       clear posted messages, acks, envelopes and failures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DMChannel

func DMChannel(user string) string

DMChannel returns the deterministic DM channel id for a user.

Types

type Ack

type Ack struct {
	EnvelopeID   string    `json:"envelope_id"`
	EventID      string    `json:"event_id"`
	RetryAttempt int       `json:"retry_attempt"`
	At           time.Time `json:"at"`
}

Ack is a socket-mode acknowledgement received from a client.

type DM

type DM struct {
	User     string `json:"user"`
	Text     string `json:"text"`
	EventID  string `json:"event_id,omitempty"`
	ThreadTS string `json:"thread_ts,omitempty"`
	Channel  string `json:"channel,omitempty"`
	BotID    string `json:"bot_id,omitempty"`
	Subtype  string `json:"subtype,omitempty"`
	TeamID   string `json:"team_id,omitempty"`
}

DM is a direct message injected by a test.

type EnvelopeState

type EnvelopeState struct {
	EnvelopeID string `json:"envelope_id"`
	EventID    string `json:"event_id"`
	Attempts   int    `json:"attempts"` // deliveries so far
	Acked      bool   `json:"acked"`
	GaveUp     bool   `json:"gave_up"`
}

EnvelopeState is the delivery state of one envelope.

type Injected

type Injected struct {
	EventID    string `json:"event_id"`
	EnvelopeID string `json:"envelope_id"`
	TS         string `json:"ts"`
	Channel    string `json:"channel"`
}

Injected describes the envelope created for a DM.

type Options

type Options struct {
	TeamID    string // default T0FAKE
	TeamName  string // default fake
	BotUserID string // default U0BOT
	BotID     string // default B0BOT
	AppID     string // default A0FAKE
	// BotToken and AppToken, when set, must match exactly. Otherwise any
	// xoxb- / xapp- token is accepted.
	BotToken string
	AppToken string
	// Users maps user id to name. Default: U0ALICE alice, U0BOB bob.
	Users map[string]string
	// RedeliveryTimeout is how long an envelope may stay unacked before it is
	// redelivered. Default 3s.
	RedeliveryTimeout time.Duration
	// MaxRetries is the number of redeliveries after the first attempt.
	// Default 3; a negative value disables redelivery.
	MaxRetries int
	// PingInterval is how often the server pings each websocket. Default 5s.
	PingInterval time.Duration
}

Options configure the fake. Zero values take the documented defaults.

type PostedMessage

type PostedMessage struct {
	Channel  string          `json:"channel"`
	Text     string          `json:"text"`
	ThreadTS string          `json:"thread_ts,omitempty"`
	TS       string          `json:"ts"`
	Metadata json.RawMessage `json:"metadata,omitempty"`
}

PostedMessage is a chat.postMessage call the fake accepted.

type Server

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

Server is the fake. It implements http.Handler.

func New

func New(opts Options) *Server

New creates the fake and starts its redelivery loop. Call Close to stop it.

func (*Server) Acks

func (s *Server) Acks() []Ack

Acks returns a copy of the recorded acks.

func (*Server) BotUserID

func (s *Server) BotUserID() string

BotUserID returns the bot's user id.

func (*Server) Close

func (s *Server) Close()

Close stops background work and closes websockets.

func (*Server) Connections

func (s *Server) Connections() int

Connections returns the number of open socket-mode connections.

func (*Server) Disconnect

func (s *Server) Disconnect()

Disconnect closes every socket-mode connection.

func (*Server) Envelopes

func (s *Server) Envelopes() []EnvelopeState

Envelopes returns the state of every envelope.

func (*Server) Fail

func (s *Server) Fail(method, mode string, count int)

Fail makes the next count calls to a Web API method fail with mode.

func (*Server) InjectDM

func (s *Server) InjectDM(dm DM) (Injected, error)

InjectDM queues a message.im event. Reusing an EventID simulates a Slack replay: a new envelope with the same event id.

func (*Server) Posted

func (s *Server) Posted() []PostedMessage

Posted returns a copy of the posted messages.

func (*Server) Reset

func (s *Server) Reset()

Reset clears recorded state and failure rules (connections stay open).

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Server) SetTokens added in v0.2.0

func (s *Server) SetTokens(t TokenSet)

SetTokens replaces the accepted tokens, as when a token is rotated or revoked.

func (*Server) TeamID

func (s *Server) TeamID() string

TeamID returns the configured team id.

type TokenSet added in v0.2.0

type TokenSet struct {
	Bot []string `json:"bot"`
	App []string `json:"app"`
}

TokenSet lists the tokens the fake accepts; an empty list restores the default rule for that kind (Options, or any well-formed token).

Jump to

Keyboard shortcuts

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