assertplugin

package
Version: v1.49.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package assertplugin provides testing functions to validate a plugin's overall functionality. This package is designed to play well but not require the assertanswer package for validation of answers

Note that all commands and hearActions are evaluated by assertplugin's driver but this is a simplified version of how slackscot actually drives plugins and aims to provide the minimal processing required to allow a plugin to test functionality given an incoming message. Users should take special care to use include <@botUserID> with the same botUserID with which the plugin driver has been instantiated in the message text inputs to test commands (or include a channel name that starts with D for direct channel testing)

Example:

   func TestPlugin(t *testing.T) {
       assertplugin := assertplugin.New(t, "bot")
       yourPlugin := newPlugin()

       assertplugin.AnswersAndReacts(yourPlugin, &slack.Msg{Text: "are you up?"}, func(t *testing.T, answers []*slackscot.Answer, emojis []string) bool {
	          return assert.Len(t, answers, 1) && assertanswer.HasText(t, answers[0], "I'm 😴, you?")
       }))
   }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asserter

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

Asserter represents a plugin driver/asserter and holds the bot identifier that tests are using when sending test messages for processing

func New

func New(t *testing.T, botUserID string, options ...Option) (a *Asserter)

New creates a new asserter with the given botUserId (only include the id without the '@' prefix). The botUserId is used in order to detect commands formed with <@botUserId>

func (*Asserter) AnswersAndReacts

func (a *Asserter) AnswersAndReacts(p *slackscot.Plugin, m *slack.Msg, validate ResultValidator) (valid bool)

AnswersAndReacts drives a plugin and collects Answers as well as emoji reactions. Once all of those have been collected, it passes handling to a validator to assert the expected answers and emoji reactions. It follows the style of github.com/stretchr/testify/assert as far as returning true/false to indicate success for further nested testing.

func (*Asserter) AnswersAndReactsWithUploads

func (a *Asserter) AnswersAndReactsWithUploads(p *slackscot.Plugin, m *slack.Msg, validate ResultWithUploadsValidator) (valid bool)

AnswersAndReactsWithUploads drives a plugin and collects Answers as well as emoji reactions and file uploads. Once all of those have been collected, it passes handling to a validator to assert the expected answers, emoji reactions and file uploads. It follows the style of github.com/stretchr/testify/assert as far as returning true/false to indicate success for further nested testing.

func (*Asserter) DoesNotRunOnSchedule

func (a *Asserter) DoesNotRunOnSchedule(p *slackscot.Plugin, schedule schedule.Definition) (valid bool)

DoesNotRunOnSchedule drives a plugin's scheduled actions and validate that none of the ScheduledActions run on the specified schedule

func (*Asserter) RunsOnSchedule

func (a *Asserter) RunsOnSchedule(p *slackscot.Plugin, expected schedule.Definition, validate ScheduleResultValidator) (valid bool)

RunsOnSchedule drives a plugin's scheduled actions that match the schedule definition being passed in (i.e. "Every 1 hour" will run all actions scheduled to run every hour) and collects all the sent messages. Once all have been collected, the results are passed to the ScheduleResultValidator as a map[string][]string where the key is the channel id and the value holds the messages sent to that channel

type Option

type Option func(*Asserter)

Option defines an option for the Asserter

func OptionLog

func OptionLog(logger *log.Logger) Option

OptionLog sets a logger for the asserter such that this logger is attached to the plugin when driven by the asserter

type ResultValidator

type ResultValidator func(t *testing.T, answers []*slackscot.Answer, emojis []string) bool

ResultValidator is a function to do further validation of the answers and emoji reactions resulting from a plugin processing of all of its commands and hear actions. The return value is meant to be true if validation is successful and false otherwise (following the testify convention)

type ResultWithUploadsValidator

type ResultWithUploadsValidator func(t *testing.T, answers []*slackscot.Answer, emojis []string, fileUploads []slack.FileUploadParameters) bool

ResultWithUploadsValidator is a function to do further validation of the answers, emoji reactions and file uploads resulting from a plugin processing of all of its commands and hear actions. The return value is meant to be true if validation is successful and false otherwise (following the testify convention)

type ScheduleResultValidator

type ScheduleResultValidator func(t *testing.T, sentMessagesByChannelID map[string][]string, fileUploads []slack.FileUploadParameters) bool

ScheduleResultValidator is a function to do further validation of the messages potentially sent by a slackscot.ScheduledAction as well as files uploaded. The messages sent during the execution of scheduled actions is given as a map of channel IDs to messages sent on that channel.

The return value is meant to be true if validation is successful and false otherwise (following the testify convention)

Jump to

Keyboard shortcuts

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