slacktest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package slacktest is a fake Slack Web API for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Response

type Response struct {
	Status int
	Header http.Header
	Body   any
}

Response lets a handler set the HTTP status and headers of its answer. A zero Status means 200.

type Server

type Server struct {
	// URL is the base URL to use as slack.Client.BaseURL.
	URL string
	// HTTP is the client to use as slack.Client.HTTP; nil reaches URL over the network.
	HTTP *http.Client
	// contains filtered or unexported fields
}

func New

func New(t testing.TB) *Server

New starts a fake Slack closed when t ends. A method without a handler answers {"ok": false, "error": "unknown_method"}, as Slack does.

func NewInMemory

func NewInMemory() *Server

NewInMemory is a fake Slack that HTTP serves in memory, without a socket, so a synctest bubble can call it.

func (*Server) Authorization

func (s *Server) Authorization(method string) []string

Authorization returns the bearer token of every request received for method ("" when absent).

func (*Server) Calls

func (s *Server) Calls(method string) []url.Values

Calls returns the form of every request received for method, rate-limited ones included.

func (*Server) Close

func (s *Server) Close()

Close stops a networked server early, so calls fail at the transport.

func (*Server) Handle

func (s *Server) Handle(method string, fn func(url.Values) any)

Handle answers method with fn's result encoded as JSON. nil or a map without "ok" gets "ok": true; a string is sent raw; a Response sets status and headers too.

func (*Server) RateLimit

func (s *Server) RateLimit(method string, retryAfter int, times int)

RateLimit answers the next times requests for method with HTTP 429 and Retry-After.

Jump to

Keyboard shortcuts

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