Documentation ¶
Index ¶
- Constants
- func NewUser(name string, id model.Snowflake, bot bool) *discordgo.User
- type FakeUTCClock
- type FakeUTCTimer
- type InMemoryDiscordSession
- func (s *InMemoryDiscordSession) Channel(channelID string, options ...discordgo.RequestOption) (*discordgo.Channel, error)
- func (s *InMemoryDiscordSession) ChannelMessageSend(channel string, message string, options ...discordgo.RequestOption) (*discordgo.Message, error)
- func (s *InMemoryDiscordSession) SetChannel(channel *discordgo.Channel)
- func (s *InMemoryDiscordSession) User(userID string, options ...discordgo.RequestOption) (*discordgo.User, error)
- type InMemoryGist
- type LearnData
- type Message
- type Runner
- func (r *Runner) AddUser(user *discordgo.User)
- func (r *Runner) AssertState()
- func (r *Runner) CastBallotAs(author *discordgo.User, channel model.Snowflake, inFavor bool)
- func (r *Runner) CastDuplicateBallotAs(author *discordgo.User, channel model.Snowflake, inFavor bool)
- func (r *Runner) ExpireVote(channel model.Snowflake)
- func (r *Runner) SendKarmaListMessage(channel model.Snowflake)
- func (r *Runner) SendLearnMessage(channel model.Snowflake, message string, learnData *LearnData)
- func (r *Runner) SendLearnMessageAs(author *discordgo.User, channel model.Snowflake, message string, ...)
- func (r *Runner) SendListMessage(channel model.Snowflake)
- func (r *Runner) SendMessage(channel model.Snowflake, message, expectedResponse string)
- func (r *Runner) SendMessageAs(author *discordgo.User, channel model.Snowflake, ...)
- func (r *Runner) SendMessageIgnoringResponse(channel model.Snowflake, message string)
- func (r *Runner) SendMessageWithoutResponse(channel model.Snowflake, message string)
- func (r *Runner) SendUnlearnMessage(channel model.Snowflake, message string, call string)
- func (r *Runner) SendVoteMessageAs(author *discordgo.User, channel model.Snowflake)
- func (r *Runner) SendVoteStatusMessage(channel model.Snowflake)
- type VoteData
Constants ¶
const ( MainChannelID = model.Snowflake(8675309) SecondChannelID = model.Snowflake(9000000) DirectMessageID = model.Snowflake(1) )
IDs used for testing
const (
// GistSuccessURL is the fake URL for success
GistSuccessURL = "https://www.example.com/success"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FakeUTCClock ¶
type FakeUTCClock struct {
// contains filtered or unexported fields
}
FakeUTCClock is a mockable UTC clock for testing.
func (*FakeUTCClock) Advance ¶
func (c *FakeUTCClock) Advance(d time.Duration)
Advance advances the internal clock by the given duration.
type FakeUTCTimer ¶
type FakeUTCTimer struct {
// contains filtered or unexported fields
}
FakeUTCTimer is a faked UTC timer for testing.
func (*FakeUTCTimer) ElapseTime ¶
func (c *FakeUTCTimer) ElapseTime(duration time.Duration)
ElapseTime subtracts duration from each stored callback. For each duration that becomes negative, it is removed from the list and the associated callback is called.
func (*FakeUTCTimer) ExecuteAfter ¶
func (c *FakeUTCTimer) ExecuteAfter(d time.Duration, cb func())
ExecuteAfter stores the callback and the duration. If the duration is 0 or negative, it will fire immediately.
type InMemoryDiscordSession ¶
type InMemoryDiscordSession struct { Messages []*Message Users map[string]*discordgo.User Channels map[string]*discordgo.Channel // contains filtered or unexported fields }
InMemoryDiscordSession is a fake for the discord session.
func NewInMemoryDiscordSession ¶
func NewInMemoryDiscordSession() *InMemoryDiscordSession
NewInMemoryDiscordSession works as advertised.
func (*InMemoryDiscordSession) Channel ¶
func (s *InMemoryDiscordSession) Channel(channelID string, options ...discordgo.RequestOption) (*discordgo.Channel, error)
Channel returns the Channel struct of the given channel ID. Can be used to determine attributes such as the channel name, topic, etc.
func (*InMemoryDiscordSession) ChannelMessageSend ¶
func (s *InMemoryDiscordSession) ChannelMessageSend(channel string, message string, options ...discordgo.RequestOption) (*discordgo.Message, error)
ChannelMessageSend records a new message delivery.
func (*InMemoryDiscordSession) SetChannel ¶
func (s *InMemoryDiscordSession) SetChannel(channel *discordgo.Channel)
SetChannel adds a channel to the map of channels that InMemoryDiscordSession holds. Can be used to test features that only work under certain channel conditions.
func (*InMemoryDiscordSession) User ¶
func (s *InMemoryDiscordSession) User(userID string, options ...discordgo.RequestOption) (*discordgo.User, error)
User returns the user struct of the given user ID.
type InMemoryGist ¶
InMemoryGist is a fake for the Gist interface.
type LearnData ¶
LearnData represents the information needed to reconstruct a Learn for testing.
func NewLearnData ¶
NewLearnData stores a duplicate representation of the expected learn data for testing
type Runner ¶
type Runner struct { // Test object T *testing.T // State GistsCount int DiscordMessagesCount int LearnDataMap map[string]*LearnData ActiveVoteDataMap map[model.Snowflake]*VoteData // channel->vote. May be nil // Fakes CustomMap *stringmap.InMemoryStringMap KarmaMap *stringmap.InMemoryStringMap VoteMap *stringmap.InMemoryStringMap Gist *InMemoryGist DiscordSession *InMemoryDiscordSession UTCClock *FakeUTCClock UTCTimer *FakeUTCTimer // Real objects FeatureRegistry *feature.Registry // Controllers under test Handler func(api.DiscordSession, *discordgo.MessageCreate) }
Runner is a helper that executes messages incrementally, and asserts that the global state is always what is expected.
func (*Runner) AssertState ¶
func (r *Runner) AssertState()
AssertState asserts all of the features against the test runner's state
func (*Runner) CastBallotAs ¶
CastBallotAs casts a ballot as the given user
func (*Runner) CastDuplicateBallotAs ¶
func (r *Runner) CastDuplicateBallotAs(author *discordgo.User, channel model.Snowflake, inFavor bool)
CastDuplicateBallotAs casts a ballot as the user and expects no state change as a result
func (*Runner) ExpireVote ¶
ExpireVote advances the clock enough that the vote expires, and fires the trigger.
func (*Runner) SendKarmaListMessage ¶
SendKarmaListMessage senda a ?karmalist message to the bot
func (*Runner) SendLearnMessage ¶
SendLearnMessage sends a learn message to the bot
func (*Runner) SendLearnMessageAs ¶
func (r *Runner) SendLearnMessageAs(author *discordgo.User, channel model.Snowflake, message string, learnData *LearnData)
SendLearnMessageAs sends a ?learn message as the given user
func (*Runner) SendListMessage ¶
SendListMessage sends a ?list message to the bot
func (*Runner) SendMessage ¶
SendMessage sends the message to the bot as the standard test user
func (*Runner) SendMessageAs ¶
func (r *Runner) SendMessageAs(author *discordgo.User, channel model.Snowflake, message, expectedResponse string)
SendMessageAs sends a message to the bot as the given user
func (*Runner) SendMessageIgnoringResponse ¶
SendMessageIgnoringResponse sends a message to the bot without checking the output
func (*Runner) SendMessageWithoutResponse ¶
SendMessageWithoutResponse sends a message without a response
func (*Runner) SendUnlearnMessage ¶
SendUnlearnMessage sends an ?unlearn message
func (*Runner) SendVoteMessageAs ¶
SendVoteMessageAs sends a ?vote message to the bot as the given user
func (*Runner) SendVoteStatusMessage ¶
SendVoteStatusMessage sends a vote status message to the bot
type VoteData ¶
type VoteData struct { Channel model.Snowflake Author *discordgo.User Message string VotesFor []model.Snowflake VotesAgainst []model.Snowflake TimestampEnd time.Time }
VoteData contains enough information to reconstruct the status message.
func (*VoteData) Reconstruct ¶
Reconstruct creates a vote.Vote out of the local storage vote. This isn't meant to be a complete reconstruction, but rather all the info necessary for testing (mostly reproducing status lines).