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 ¶
- func DMChannel(user string) string
- type Ack
- type DM
- type EnvelopeState
- type Injected
- type Options
- type PostedMessage
- type Server
- func (s *Server) Acks() []Ack
- func (s *Server) BotUserID() string
- func (s *Server) Close()
- func (s *Server) Connections() int
- func (s *Server) Disconnect()
- func (s *Server) Envelopes() []EnvelopeState
- func (s *Server) Fail(method, mode string, count int)
- func (s *Server) InjectDM(dm DM) (Injected, error)
- func (s *Server) Posted() []PostedMessage
- func (s *Server) Reset()
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetTokens(t TokenSet)
- func (s *Server) TeamID() string
- type TokenSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Server) Connections ¶
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) InjectDM ¶
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.