dismock

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 28 Imported by: 1

Documentation

Overview

Package dismock creates mocks for the Discord API. The names of the mocks correspond to arikawa's API wrapper names, but as this are http mocks, any discord library can be mocked.

Mocking Requests for Metadata

Besides the regular API calls, dismock also features mocks for fetching an entities meta data, e.g. an icon or a splash. In order to mock requests for an entity's meta data, you need to make sure that those requests are made with Mocker.Client, so that the requests are correctly redirected to the mock server.

Mocking Errors

To send a discord error, use the Mocker.Error method with the path of the endpoint that should return an error.

Important Notes

BUG(mavolin): Due to an inconvenient behavior of json.Unmarshal where on JSON null the the UnmarshalJSON method doesn't get called, there is no way to differentiate between option.NullX and omitted, and therefore both will be seen as equal.

BUG(mavolin): Due to the way Snowflakes are serialized, all fields that don't have the omitempty flag and are set to 0, will be sent as JSON null.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Name is the name of the handler.
	Name string
	// Handler is the underlying http.Handler.
	http.Handler
}

Handler is a named handler for mocked endpoints.

type MockFunc

type MockFunc func(w http.ResponseWriter, r *http.Request, t *testing.T)

MockFunc is the function used to create a mock.

type Mocker

type Mocker struct {
	// Server is the httptest.Server used to mock the requests.
	Server *httptest.Server
	// Client is a mocked *http.Client that redirects all requests to the
	// Server.
	Client *http.Client
	// contains filtered or unexported fields
}

Mocker handles the mocking of arikawa's API calls.

func New

func New(t *testing.T) *Mocker

New creates a new Mocker with a started server listening on Mocker.Server.Listener.Addr().

func NewSession

func NewSession(t *testing.T) (*Mocker, *session.Session)

NewSession creates a new Mocker, starts its test server and returns a manipulated session.Session using the test server.

func NewState

func NewState(t *testing.T) (*Mocker, *state.State)

NewState creates a new Mocker, starts its test server and returns a manipulated state.State which's Session uses the test server. In order to allow for successful testing, the State's Store, will always return an error, forcing the use of the (mocked) Session.

func (*Mocker) Ack

func (m *Mocker) Ack(channelID discord.ChannelID, messageID discord.MessageID, send, ret api.Ack)

Ack mocks a Ack request.

func (*Mocker) AddMember

func (m *Mocker) AddMember(guildID discord.GuildID, d api.AddMemberData, member discord.Member)

AddMember mocks a AddMember request.

The User.ID field of the passed discord.Member must be set.

func (*Mocker) AddRecipient

func (m *Mocker) AddRecipient(channelID discord.ChannelID, userID discord.UserID, accessToken, nickname string)

AddRecipient mocks a AddRecipient request.

func (*Mocker) AddRole

func (m *Mocker) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID)

AddRole mocks a AddRole request.

func (*Mocker) AttachIntegration

func (m *Mocker) AttachIntegration(
	guildID discord.GuildID, integrationID discord.IntegrationID, integrationType discord.Service,
)

AttachIntegration mocks a AttachIntegration request.

func (*Mocker) AuditLog

func (m *Mocker) AuditLog(guildID discord.GuildID, d api.AuditLogData, al discord.AuditLog)

AuditLog mocks a AuditLog request.

func (*Mocker) Ban

func (m *Mocker) Ban(guildID discord.GuildID, userID discord.UserID, d api.BanData)

Ban mocks a Ban request.

func (*Mocker) Banner

func (m *Mocker) Banner(guildID discord.GuildID, banner discord.Hash, img io.Reader)

Banner mocks a Banner request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) BannerWithType

func (m *Mocker) BannerWithType(guildID discord.GuildID, banner discord.Hash, t discord.ImageType, img io.Reader)

BannerWithType mocks a BannerWithType request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) Bans

func (m *Mocker) Bans(guildID discord.GuildID, b []discord.Ban)

Bans mocks a Bans request.

func (*Mocker) ChangeOwnNickname

func (m *Mocker) ChangeOwnNickname(guildID discord.GuildID, nick string)

ChangeOwnNickname mocks a ChangeOwnNickname request.

func (*Mocker) Channel

func (m *Mocker) Channel(c discord.Channel)

Channel mocks a Channel request.

The ID field of the passed discord.Channel must be set.

func (*Mocker) ChannelIcon

func (m *Mocker) ChannelIcon(channelID discord.ChannelID, icon discord.Hash, img io.Reader)

ChannelIcon mocks a ChannelIcon request.

func (*Mocker) ChannelIconWithType

func (m *Mocker) ChannelIconWithType(
	channelID discord.ChannelID, icon discord.Hash, t discord.ImageType, img io.Reader,
)

ChannelIconWithType mocks a ChannelIconWithType request.

func (*Mocker) ChannelInvites

func (m *Mocker) ChannelInvites(channelID discord.ChannelID, invites []discord.Invite)

ChannelInvites mocks a ChannelInvites request.

func (*Mocker) ChannelWebhooks

func (m *Mocker) ChannelWebhooks(channelID discord.ChannelID, webhooks []discord.Webhook)

ChannelWebhooks mocks a ChannelWebhooks request.

func (*Mocker) Channels

func (m *Mocker) Channels(guildID discord.GuildID, c []discord.Channel)

Channels mocks a channels request.

func (*Mocker) Clone

func (m *Mocker) Clone(t *testing.T) (clone *Mocker)

Clone creates a clone of the Mocker that has the same handlers but a separate server.

Creating a clone will automatically close the Mocker's server.

func (*Mocker) CloneSession

func (m *Mocker) CloneSession(t *testing.T) (clone *Mocker, s *session.Session)

CloneSession clones handlers of the Mocker and returns the cloned Mocker and a new session.Session using the new server.

Creating a clone will automatically close the Mocker's server.

func (*Mocker) CloneState

func (m *Mocker) CloneState(t *testing.T) (clone *Mocker, s *state.State)

CloneState clones handlers of the Mocker and returns the cloned Mocker and a new state.State using the new server. Useful for multiple tests with the same API calls.

Creating a clone will automatically close the current server.

func (*Mocker) Close

func (m *Mocker) Close()

Close shuts down the server and blocks until all current requests are completed.

func (*Mocker) CreateChannel

func (m *Mocker) CreateChannel(d api.CreateChannelData, c discord.Channel)

CreateChannel mocks a CreateChannel request.

The GuildID field of the passed discord.Channel must be set.

func (*Mocker) CreateEmoji

func (m *Mocker) CreateEmoji(guildID discord.GuildID, d api.CreateEmojiData, e discord.Emoji)

CreateEmoji mocks a CreateEmoji request.

The fields Name and RoleIDs of the passed discord.Emoji must be set.

This method will sanitize Emoji.ID and Emoji.User.ID.

func (*Mocker) CreateGuild

func (m *Mocker) CreateGuild(d api.CreateGuildData, g discord.Guild)

CreateGuild mocks a CreateGuild request.

func (*Mocker) CreateInvite

func (m *Mocker) CreateInvite(d api.CreateInviteData, i discord.Invite)

CreateInvite mocks a CreateInvite request.

The Channel.ID field of the passed discord.Invite must be set.

func (*Mocker) CreatePrivateChannel

func (m *Mocker) CreatePrivateChannel(c discord.Channel)

CreatePrivateChannel mocks a CreatePrivateChannel request.

The c.DMRecipients[0] field of the passed discord.Channel must be set.

func (*Mocker) CreateRole

func (m *Mocker) CreateRole(guildID discord.GuildID, d api.CreateRoleData, role discord.Role)

CreateRole mocks a CreateRole request.

func (*Mocker) CreateWebhook

func (m *Mocker) CreateWebhook(d api.CreateWebhookData, wh discord.Webhook)

CreateWebhook mocks a CreateWebhook request.

func (*Mocker) DeleteAllReactions

func (m *Mocker) DeleteAllReactions(channelID discord.ChannelID, messageID discord.MessageID)

DeleteAllReactions mocks a DeleteAllReactions request.

func (*Mocker) DeleteChannel

func (m *Mocker) DeleteChannel(id discord.ChannelID)

DeleteChannel mocks a DeleteChannel request.

func (*Mocker) DeleteChannelPermission

func (m *Mocker) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake)

DeleteChannelPermission mocks a DeleteChannelPermission request.

func (*Mocker) DeleteEmoji

func (m *Mocker) DeleteEmoji(guildID discord.GuildID, emojiID discord.EmojiID)

DeleteEmoji mocks a DeleteEmoji request.

func (*Mocker) DeleteGuild

func (m *Mocker) DeleteGuild(id discord.GuildID)

DeleteGuild mocks a DeleteGuild request.

func (*Mocker) DeleteInvite

func (m *Mocker) DeleteInvite(i discord.Invite)

DeleteInvite mocks a DeleteInvite request.

The Code field of the passed discord.Invite must be set.

func (*Mocker) DeleteMessage

func (m *Mocker) DeleteMessage(channelID discord.ChannelID, messageID discord.MessageID)

DeleteMessage mocks a DeleteMessage request.

func (*Mocker) DeleteMessages

func (m *Mocker) DeleteMessages(channelID discord.ChannelID, messageIDs []discord.MessageID)

DeleteMessages mocks a DeleteMessages request.

func (*Mocker) DeleteReactions

func (m *Mocker) DeleteReactions(channelID discord.ChannelID, messageID discord.MessageID, e discord.APIEmoji)

DeleteReactions mocks a DeleteReactions request.

func (*Mocker) DeleteRole

func (m *Mocker) DeleteRole(guildID discord.GuildID, roleID discord.RoleID)

DeleteRole mocks a DeleteRole request.

func (*Mocker) DeleteUserReaction

func (m *Mocker) DeleteUserReaction(
	channelID discord.ChannelID, messageID discord.MessageID, userID discord.UserID, e discord.APIEmoji,
)

DeleteUserReaction mocks a DeleteUserReaction request.

func (*Mocker) DeleteWebhook

func (m *Mocker) DeleteWebhook(id discord.WebhookID)

DeleteWebhook mocks a DeleteWebhook request.

func (*Mocker) DeleteWebhookWithToken

func (m *Mocker) DeleteWebhookWithToken(id discord.WebhookID, token string)

DeleteWebhookWithToken mocks a DeleteWebhookWithToken request.

func (*Mocker) DiscoverySplash

func (m *Mocker) DiscoverySplash(guildID discord.GuildID, splash discord.Hash, img io.Reader)

DiscoverySplash mocks a DiscoverySplash request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) DiscoverySplashWithType

func (m *Mocker) DiscoverySplashWithType(
	guildID discord.GuildID, splash discord.Hash, t discord.ImageType, img io.Reader,
)

DiscoverySplashWithType mocks a DiscoverySplashWithType request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) EditChannelPermission

func (m *Mocker) EditChannelPermission(
	channelID discord.ChannelID, overwriteID discord.Snowflake, d api.EditChannelPermissionData,
)

EditChannelPermission mocks a EditChannelPermission request.

func (*Mocker) EditEmbed

func (m *Mocker) EditEmbed(msg discord.Message)

EditEmbed mocks a EditEmbed request.

The ID field, the ChannelID field and the Embed[0] field of the passed discord.Message must be set.

func (*Mocker) EditMessage

func (m *Mocker) EditMessage(embed *discord.Embed, msg discord.Message, suppressEmbeds bool)

EditMessage mocks a EditMessage request.

The ID field, the ChannelID field, the Content field of the passed discord.Message must be set.

func (*Mocker) EditMessageComplex

func (m *Mocker) EditMessageComplex(d api.EditMessageData, msg discord.Message)

EditMessageComplex mocks a EditMessageComplex request.

The ID field and the ChannelID field of the passed discord.Message must be set.

func (*Mocker) EditText

func (m *Mocker) EditText(msg discord.Message)

EditText mocks a EditText request.

The ID field, the ChannelID field and the Content field of the passed Message must be set.

func (*Mocker) Emoji

func (m *Mocker) Emoji(guildID discord.GuildID, e discord.Emoji)

Emoji mocks a Emoji request.

The ID field of the passed discord.Emoji is required.

func (*Mocker) EmojiPicture

func (m *Mocker) EmojiPicture(emojiID discord.EmojiID, animated bool, img io.Reader)

EmojiPicture mocks a EmojiPicture request.

func (*Mocker) EmojiPictureWithType

func (m *Mocker) EmojiPictureWithType(emojiID discord.EmojiID, animated bool, t discord.ImageType, img io.Reader)

EmojiPictureWithType mocks a EmojiPictureWithType request.

func (*Mocker) Emojis

func (m *Mocker) Emojis(guildID discord.GuildID, e []discord.Emoji)

Emojis mocks a Emojis request.

func (*Mocker) Error

func (m *Mocker) Error(method, path string, e httputil.HTTPError)

Error simulates an error response for the given path using the given method.

func (*Mocker) Eval deprecated

func (m *Mocker) Eval()

Eval closes the server and evaluates if all registered handlers were invoked. If not it will call testing.T.Fatal, printing an error message with all uninvoked handlers.

If Close was called before Eval, e.g. by calling Clone, Eval will always pass.

Deprecated: When creating a Mocker, Eval will automatically be added as a Cleanup function. Effectively, this means that there is no more need to manually Eval, as it is done at the end of every test.

func (*Mocker) ExecuteWebhook

func (m *Mocker) ExecuteWebhook(webhookID discord.WebhookID, token string, d webhook.ExecuteData)

ExecuteWebhook mocks a ExecuteWebhook request and doesn't "wait" for the message to be delivered.

func (*Mocker) ExecuteWebhookAndWait

func (m *Mocker) ExecuteWebhookAndWait(
	webhookID discord.WebhookID, token string, d webhook.ExecuteData, msg discord.Message,
)

ExecuteWebhookAndWait mocks a ExecuteWebhook request and "waits" for the message to be delivered.

func (*Mocker) GetBan

func (m *Mocker) GetBan(guildID discord.GuildID, b discord.Ban)

GetBan mocks a GetBan request.

The User.ID field of the passed discord.Ban must be set.

func (*Mocker) Guild

func (m *Mocker) Guild(g discord.Guild)

Guild mocks a Guild request.

The ID field of the passed discord.Guild must be set.

func (*Mocker) GuildIcon

func (m *Mocker) GuildIcon(guildID discord.GuildID, icon discord.Hash, img io.Reader)

GuildIcon mocks a GuildIcon request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) GuildIconWithType

func (m *Mocker) GuildIconWithType(guildID discord.GuildID, icon discord.Hash, t discord.ImageType, img io.Reader)

GuildIconWithType mocks a GuildIconWithType request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) GuildInvites

func (m *Mocker) GuildInvites(guildID discord.GuildID, invites []discord.Invite)

GuildInvites mocks a GuildInvites request.

func (*Mocker) GuildPreview

func (m *Mocker) GuildPreview(p discord.GuildPreview)

GuildPreview mocks a GuildPreview request.

func (*Mocker) GuildVanityInvite

func (m *Mocker) GuildVanityInvite(guildID discord.GuildID, i discord.Invite)

GuildVanityURL mocks a GuildVanityURL request.

func (*Mocker) GuildWebhooks

func (m *Mocker) GuildWebhooks(guildID discord.GuildID, webhooks []discord.Webhook)

GuildWebhooks mocks a GuildWebhooks request.

func (*Mocker) GuildWidget

func (m *Mocker) GuildWidget(guildID discord.GuildID, widget discord.GuildWidget)

GuildWidget mocks a GuildWidget request.

func (*Mocker) GuildWidgetImage

func (m *Mocker) GuildWidgetImage(guildID discord.GuildID, style api.GuildWidgetImageStyle, img io.Reader)

GuildWidgetImage mocks a GuildWidgetImage request.

func (*Mocker) GuildWidgetSettings

func (m *Mocker) GuildWidgetSettings(guildID discord.GuildID, s discord.GuildWidgetSettings)

GuildWidgetSettings mocks a GuildWidgetSettings request.

func (*Mocker) GuildWithCount

func (m *Mocker) GuildWithCount(g discord.Guild)

GuildWithCount mocks a GuildWithCount request.

The ID field of the passed discord.Guild must be set.

func (*Mocker) Guilds

func (m *Mocker) Guilds(limit uint, g []discord.Guild)

Guilds mocks a Guilds request.

This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.

func (*Mocker) GuildsAfter

func (m *Mocker) GuildsAfter(after discord.GuildID, limit uint, g []discord.Guild)

GuildsAfter mocks a GuildsAfter request.

This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.WithToken

func (*Mocker) GuildsBefore

func (m *Mocker) GuildsBefore(before discord.GuildID, limit uint, g []discord.Guild)

GuildsBefore mocks a GuildsBefore request.

This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.

func (*Mocker) HTTPClient

func (m *Mocker) HTTPClient() *httputil.Client

HTTPClient wraps the http client of the mocker in a *httputil.Client, as used by arikawa.

func (*Mocker) Integrations

func (m *Mocker) Integrations(guildID discord.GuildID, integrations []discord.Integration)

Integrations mocks a Integrations request.

func (*Mocker) Invite

func (m *Mocker) Invite(i discord.Invite)

Invite mocks a Invite request.

The Code field of the passed discord.Invite must be set.

func (*Mocker) InviteWithCounts

func (m *Mocker) InviteWithCounts(i discord.Invite)

InviteWithCounts mocks a InviteWithCounts request.

The Code field of the passed discord.Invite must be set.

func (*Mocker) Kick

func (m *Mocker) Kick(guildID discord.GuildID, userID discord.UserID)

Kick mocks a Kick request.

func (*Mocker) LeaveGuild

func (m *Mocker) LeaveGuild(id discord.GuildID)

LeaveGuild mocks a LeaveGuild request.

func (*Mocker) Login

func (m *Mocker) Login(email, password string, response api.LoginResponse)

Login mocks a Login request.

func (*Mocker) Me

func (m *Mocker) Me(u discord.User)

Me mocks a Me request.

func (*Mocker) Member

func (m *Mocker) Member(guildID discord.GuildID, member discord.Member)

Member mocks a Member request.

The User.ID field of the passed member must be set.

func (*Mocker) Members

func (m *Mocker) Members(guildID discord.GuildID, limit uint, members []discord.Member)

Members mocks a Members request.

func (*Mocker) MembersAfter

func (m *Mocker) MembersAfter(guildID discord.GuildID, after discord.UserID, limit uint, members []discord.Member)

MembersAfter mocks a MembersAfter request.

func (*Mocker) Message

func (m *Mocker) Message(msg discord.Message)

Message mocks a Message request.

The ID field and the ChannelID field of the passed discord.Message must be set.

func (*Mocker) Messages

func (m *Mocker) Messages(channelID discord.ChannelID, limit uint, messages []discord.Message)

Messages mocks a Messages request.

func (*Mocker) MessagesAfter

func (m *Mocker) MessagesAfter(
	channelID discord.ChannelID, after discord.MessageID, limit uint, messages []discord.Message,
)

MessagesAfter mocks a MessagesAfter request.

func (*Mocker) MessagesAround

func (m *Mocker) MessagesAround(
	channelID discord.ChannelID, around discord.MessageID, limit uint, messages []discord.Message,
)

MessagesAround mocks a MessagesAround request.

func (*Mocker) MessagesBefore

func (m *Mocker) MessagesBefore(
	channelID discord.ChannelID, before discord.MessageID, limit uint, messages []discord.Message,
)

MessagesBefore mocks a MessagesBefore request.

This method will sanitize Message.ID, Message.ChannelID and Message.Author.ID.

func (*Mocker) Mock

func (m *Mocker) Mock(name, method, path string, f MockFunc)

Mock uses the passed MockFunc to create a mock for the passed path using the passed method. If there are already handlers for this path with the same method, the handler will be queued up behind the other handlers with the same path and method. Queued up handlers must be invoked in the same order they were added in.

Trailing slashes ('/') will be removed.

Names don't need to be unique, and have the sole purpose of aiding in debugging.

The MockFunc may be nil if only the NoContent status shall be returned.

func (*Mocker) MockAPI

func (m *Mocker) MockAPI(name, method, path string, f MockFunc)

MockAPI uses the passed MockFunc to as handler for the passed path and method. The path must not include the api version, i.e. '/api/v6' must be stripped. If there are already handlers for this path with the same method, the handler will be queued up behind the other handlers with the same path and method. Queued up handlers are invoked in the same order they were added in.

Trailing slashes ('/') will be removed.

Names don't need to be unique, and have the sole purpose of aiding in debugging.

The MockFunc may be nil if only the NoContent status shall be returned.

func (*Mocker) ModifyChannel

func (m *Mocker) ModifyChannel(id discord.ChannelID, d api.ModifyChannelData)

ModifyChannel mocks a ModifyChannel request.

func (*Mocker) ModifyEmoji

func (m *Mocker) ModifyEmoji(guildID discord.GuildID, emojiID discord.EmojiID, d api.ModifyEmojiData)

ModifyEmoji mocks a ModifyEmoji request.

func (*Mocker) ModifyGuild

func (m *Mocker) ModifyGuild(d api.ModifyGuildData, g discord.Guild)

ModifyGuild mocks a ModifyGuild request.

The ID field of the passed discord.Guild must be set.

func (*Mocker) ModifyGuildWidget

func (m *Mocker) ModifyGuildWidget(
	guildID discord.GuildID, d api.ModifyGuildWidgetData, s discord.GuildWidgetSettings,
)

ModifyGuildWidget mocks a ModifyGuildWidget request.

func (*Mocker) ModifyIntegration

func (m *Mocker) ModifyIntegration(
	guildID discord.GuildID, integrationID discord.IntegrationID, d api.ModifyIntegrationData,
)

ModifyIntegration mocks a ModifyIntegration request.

func (*Mocker) ModifyMe

func (m *Mocker) ModifyMe(d api.ModifySelfData, u discord.User)

ModifyMe mocks a ModifyMe request.

func (*Mocker) ModifyMember

func (m *Mocker) ModifyMember(guildID discord.GuildID, userID discord.UserID, d api.ModifyMemberData)

ModifyMember mocks a ModifyMember request.

func (*Mocker) ModifyRole

func (m *Mocker) ModifyRole(guildID discord.GuildID, d api.ModifyRoleData, role discord.Role)

ModifyRole mocks a ModifyRole request.

func (*Mocker) ModifyWebhook

func (m *Mocker) ModifyWebhook(d api.ModifyWebhookData, wh discord.Webhook)

ModifyWebhook mocks a ModifyWebhook request.

The ID field of the passed discord.Webhook must be set.

This method will sanitize Webhook.User.ID and Webhook.ChannelID.

func (*Mocker) ModifyWebhookWithToken

func (m *Mocker) ModifyWebhookWithToken(d api.ModifyWebhookData, wh discord.Webhook)

ModifyWebhookWithToken mocks a ModifyWebhookWithToken request.

The ID field and the Token field of the passed discord.Webhook must be set.

This method will sanitize Webhook.User.ID and Webhook.ChannelID.

func (*Mocker) MoveChannel

func (m *Mocker) MoveChannel(guildID discord.GuildID, d []api.MoveChannelData)

MoveChannel mocks a MoveChannel request.

func (*Mocker) MoveRole

func (m *Mocker) MoveRole(guildID discord.GuildID, d []api.MoveRoleData, roles []discord.Role)

MoveRole mocks a MoveRole request.

func (*Mocker) PinMessage

func (m *Mocker) PinMessage(channelID discord.ChannelID, messageID discord.MessageID)

PinMessage mocks a PinMessage request.

func (*Mocker) PinnedMessages

func (m *Mocker) PinnedMessages(channelID discord.ChannelID, messages []discord.Message)

PinnedMessages mocks a PinnedMessages request.

func (*Mocker) PrivateChannels

func (m *Mocker) PrivateChannels(c []discord.Channel)

PrivateChannels mocks a PrivateChannels request.

func (*Mocker) Prune

func (m *Mocker) Prune(guildID discord.GuildID, d api.PruneData, pruned uint)

Prune mocks a Prune request.

func (*Mocker) PruneCount

func (m *Mocker) PruneCount(guildID discord.GuildID, d api.PruneCountData, pruned uint)

PruneCount mocks a PruneCount request.

func (*Mocker) React

func (m *Mocker) React(channelID discord.ChannelID, messageID discord.MessageID, e discord.APIEmoji)

React mocks a React request.

func (*Mocker) Reactions

func (m *Mocker) Reactions(
	channelID discord.ChannelID, messageID discord.MessageID, limit uint, e discord.APIEmoji, u []discord.User,
)

Reactions mocks a Reactions request.

func (*Mocker) ReactionsAfter

func (m *Mocker) ReactionsAfter(
	channelID discord.ChannelID, messageID discord.MessageID, after discord.UserID, limit uint, e discord.APIEmoji,
	u []discord.User,
)

ReactionsAfter mocks a ReactionsAfter request.

func (*Mocker) ReactionsBefore

func (m *Mocker) ReactionsBefore(
	channelID discord.ChannelID, messageID discord.MessageID, before discord.UserID, limit uint, e discord.APIEmoji,
	u []discord.User,
)

ReactionsBefore mocks a ReactionsBefore request.

func (*Mocker) RemoveRecipient

func (m *Mocker) RemoveRecipient(channelID discord.ChannelID, userID discord.UserID)

RemoveRecipient mocks a RemoveRecipient request.

func (*Mocker) RemoveRole

func (m *Mocker) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID)

RemoveRole mocks a RemoveRole request.

func (*Mocker) Roles

func (m *Mocker) Roles(guildID discord.GuildID, roles []discord.Role)

Roles mocks a Roles request.

func (*Mocker) SendEmbed

func (m *Mocker) SendEmbed(msg discord.Message)

SendEmbed mocks a SendEmbed request.

The ChannelID field and the Embed field of the passed discord.Message must be set.

func (*Mocker) SendMessage

func (m *Mocker) SendMessage(embed *discord.Embed, msg discord.Message)

SendMessage mocks a SendMessage request.

The ChannelID field and the Content field of the passed discord.Message must be set.

This method will sanitize Message.ID, Message.Author.ID, Message.Embeds.Type and Message.Embeds.Color.

func (*Mocker) SendMessageComplex

func (m *Mocker) SendMessageComplex(d api.SendMessageData, msg discord.Message)

SendMessageComplex mocks a SendMessageComplex request.

The ChannelID field of the passed discord.Message must be set.

func (*Mocker) SendText

func (m *Mocker) SendText(msg discord.Message)

SendText mocks a SendText request.

The ChannelID field and the Content field of the passed discord.Message must be set.

func (*Mocker) Splash

func (m *Mocker) Splash(guildID discord.GuildID, splash discord.Hash, img io.Reader)

Splash mocks a Splash request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) SplashWithType

func (m *Mocker) SplashWithType(guildID discord.GuildID, splash discord.Hash, t discord.ImageType, img io.Reader)

SplashWithType mocks a SplashWithType request.

This method can be used for both discord.Guild and discord.GuildPreview.

func (*Mocker) SyncIntegration

func (m *Mocker) SyncIntegration(guildID discord.GuildID, integrationID discord.IntegrationID)

SyncIntegration mocks a SyncIntegration request.

func (*Mocker) TOTP

func (m *Mocker) TOTP(code, ticket string, response api.LoginResponse)

TOTP mocks a TOTP request.

func (*Mocker) Typing

func (m *Mocker) Typing(channelID discord.ChannelID)

Typing mocks a Typing request.

func (*Mocker) Unban

func (m *Mocker) Unban(guildID discord.GuildID, userID discord.UserID)

Unban mocks a Unban request.

func (*Mocker) UnpinMessage

func (m *Mocker) UnpinMessage(channelID discord.ChannelID, messageID discord.MessageID)

UnpinMessage mocks a UnpinMessage request.

func (*Mocker) Unreact

func (m *Mocker) Unreact(channelID discord.ChannelID, messageID discord.MessageID, e discord.APIEmoji)

Unreact mocks a Unreact request.

func (*Mocker) User

func (m *Mocker) User(u discord.User)

User mocks a User request.

The ID field of the passed User must be set.

func (*Mocker) UserConnections

func (m *Mocker) UserConnections(c []discord.Connection)

UserConnections mocks a UserConnections request.

func (*Mocker) VoiceRegionsGuild

func (m *Mocker) VoiceRegionsGuild(guildID discord.GuildID, vr []discord.VoiceRegion)

VoiceRegionsGuild mocks a VoiceRegionsGuild request.

func (*Mocker) Webhook

func (m *Mocker) Webhook(webhook discord.Webhook)

Webhook mocks a Webhook request.

The ID field of the passed discord.Webhook must be set.

func (*Mocker) WebhookWithToken

func (m *Mocker) WebhookWithToken(wh discord.Webhook)

WebhookWithToken mocks a WebhookWithToken request.

The ID field and the Token field of the passed discord.Webhook must be set.

This method will sanitize Webhook.User.ID and Webhook.ChannelID.

Notes

Bugs

  • Due to an inconvenient behavior of json.Unmarshal where on JSON null the the UnmarshalJSON method doesn't get called, there is no way to differentiate between option.NullX and omitted, and therefore both will be seen as equal.

  • Due to the way Snowflakes are serialized, all fields that don't have the omitempty flag and are set to 0, will be sent as JSON null.

Jump to

Keyboard shortcuts

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