Documentation
¶
Overview ¶
Package gadgettest provides testing utilities for Gadget route handlers. It allows dispatching synthetic events synchronously without requiring a database, HTTP server, or Slack signature verification.
Index ¶
- Variables
- type Dispatcher
- type Option
- func WithBotClient(c *slack.Client) Option
- func WithChannelMessageRoutes(routes ...router.ChannelMessageRoute) Option
- func WithDB(db *gorm.DB) Option
- func WithLogger(l zerolog.Logger) Option
- func WithMentionRoutes(routes ...router.MentionRoute) Option
- func WithSlashCommandRoutes(routes ...router.SlashCommandRoute) Option
- func WithUserClient(c *slack.Client) Option
Constants ¶
This section is empty.
Variables ¶
var ErrNoRoute = errors.New("no matching route")
ErrNoRoute is returned when no route matches a dispatched event.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher dispatches synthetic events to registered routes synchronously.
func NewDispatcher ¶
func NewDispatcher(opts ...Option) *Dispatcher
NewDispatcher creates a test Dispatcher with the given options.
func (*Dispatcher) DispatchChannelMessage ¶
func (d *Dispatcher) DispatchChannelMessage(ev slackevents.MessageEvent, message string) error
DispatchChannelMessage finds the matching channel message route for message and executes it synchronously. Returns an error if no route matches.
func (*Dispatcher) DispatchMention ¶
func (d *Dispatcher) DispatchMention(ev slackevents.AppMentionEvent, message string) error
DispatchMention finds the matching mention route for message and executes it synchronously. Route permissions are not enforced; this dispatches directly to the handler. Returns an error if no route matches.
func (*Dispatcher) DispatchSlashCommand ¶
func (d *Dispatcher) DispatchSlashCommand(cmd slack.SlashCommand) error
DispatchSlashCommand finds the matching slash command route and executes it synchronously. Returns an error if no route matches.
type Option ¶
type Option func(*Dispatcher)
Option configures a Dispatcher.
func WithBotClient ¶
WithBotClient sets the bot Slack client available as ctx.BotClient.
func WithChannelMessageRoutes ¶
func WithChannelMessageRoutes(routes ...router.ChannelMessageRoute) Option
WithChannelMessageRoutes registers channel message routes on the dispatcher.
func WithLogger ¶
WithLogger sets the logger available as ctx.Logger.
func WithMentionRoutes ¶
func WithMentionRoutes(routes ...router.MentionRoute) Option
WithMentionRoutes registers mention routes on the dispatcher.
func WithSlashCommandRoutes ¶
func WithSlashCommandRoutes(routes ...router.SlashCommandRoute) Option
WithSlashCommandRoutes registers slash command routes on the dispatcher.
func WithUserClient ¶
WithUserClient sets the user Slack client available as ctx.UserClient.