mmbottest

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mmbottest provides fakes and builders for testing mmbot handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an in-memory implementation of mmbot.Client.

func (*Client) CreatePost

func (c *Client) CreatePost(_ context.Context, post mmbot.Post) (*mmbot.Post, error)

CreatePost records a post or returns the configured error.

func (*Client) Mattermost

func (c *Client) Mattermost() *model.Client4

Mattermost returns nil because the harness does not use the real SDK.

func (*Client) Posts

func (c *Client) Posts() []mmbot.Post

Posts returns a copy of all posts created through the fake client.

func (*Client) SetCreatePostError

func (c *Client) SetCreatePostError(err error)

SetCreatePostError configures the error returned by CreatePost.

func (*Client) SetUser

func (c *Client) SetUser(user mmbot.User)

SetUser configures a user returned by User.

func (*Client) SetUserError

func (c *Client) SetUserError(userID string, err error)

SetUserError configures an error returned for a user ID.

func (*Client) User

func (c *Client) User(_ context.Context, userID string) (*mmbot.User, error)

User returns a configured user or error. An unknown ID returns nil, nil.

type ContextBuilder

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

ContextBuilder constructs a synthetic mmbot.Context.

func (*ContextBuilder) Build

func (b *ContextBuilder) Build() *mmbot.Context

Build creates the context.

func (*ContextBuilder) WithArgs

func (b *ContextBuilder) WithArgs(raw string, args ...string) *ContextBuilder

WithArgs sets parsed and raw command arguments.

func (*ContextBuilder) WithCommand

func (b *ContextBuilder) WithCommand(command string) *ContextBuilder

WithCommand sets the canonical command name.

func (*ContextBuilder) WithContext

func (b *ContextBuilder) WithContext(ctx context.Context) *ContextBuilder

WithContext sets the standard context.

func (*ContextBuilder) WithMessage

func (b *ContextBuilder) WithMessage(message mmbot.Message) *ContextBuilder

WithMessage sets the incoming message.

type Harness

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

Harness owns a fake Client and records posts created by handlers.

func New

func New() *Harness

New creates an empty handler test harness.

func (*Harness) Client

func (h *Harness) Client() *Client

Client returns the fake mmbot client.

func (*Harness) Context

func (h *Harness) Context() *ContextBuilder

Context starts a builder attached to this harness.

Jump to

Keyboard shortcuts

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