gadgettest

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func WithBotClient(c *slack.Client) Option

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 WithDB

func WithDB(db *gorm.DB) Option

WithDB sets the database connection on the router.

func WithLogger

func WithLogger(l zerolog.Logger) Option

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

func WithUserClient(c *slack.Client) Option

WithUserClient sets the user Slack client available as ctx.UserClient.

Jump to

Keyboard shortcuts

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