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.
Field Sanitation ¶
As you might have noticed, some of the MockX methods have footers like:
This method will sanitize Emoji.ID and Emoji.User.ID.
This means that all fields mentioned in the comment will be set to 1, or, if available, a value passed in as a parameter, if their value is v <= 0. This is necessary, as arikawa serializes all Snowflakes that are s <= 0 to JSON null, as they are seen as invalid.
However, this shouldn't impose much of a problem as a Snowflake with the value 0 or smaller isn't valid anyway, and all valid values 0 will not be sanitized.
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 ¶
Not always do we expect an API call to succeed. To send a discord error, use the Mocker.Error method.
Important Notes ¶
BUG(mavolin): Due to an inconvenient behavior of json.Unmarshal, where on JSON null the the MarshalJSON method doesn't get called, there is no way to differentiate between option.NullX and omitted.
Index ¶
- type Handler
- type MockFunc
- type Mocker
- func (m *Mocker) Ack(channelID, messageID discord.Snowflake, send, ret api.Ack)
- func (m *Mocker) AddMember(guildID discord.Snowflake, d api.AddMemberData, member discord.Member)
- func (m *Mocker) AddRecipient(channelID, userID discord.Snowflake, accessToken, nickname string)
- func (m *Mocker) AddRole(guildID, userID, roleID discord.Snowflake)
- func (m *Mocker) AttachIntegration(guildID, integrationID discord.Snowflake, integrationType discord.Service)
- func (m *Mocker) AuditLog(guildID discord.Snowflake, d api.AuditLogData, al discord.AuditLog)
- func (m *Mocker) Ban(guildID, userID discord.Snowflake, d api.BanData)
- func (m *Mocker) BannerURL(guildID discord.Snowflake, banner discord.Hash, img io.Reader)
- func (m *Mocker) BannerURLWithType(guildID discord.Snowflake, banner discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) Bans(guildID discord.Snowflake, b []discord.Ban)
- func (m *Mocker) ChangeOwnNickname(guildID discord.Snowflake, nick string)
- func (m *Mocker) Channel(c discord.Channel)
- func (m *Mocker) ChannelIconURL(channelID discord.Snowflake, icon discord.Hash, img io.Reader)
- func (m *Mocker) ChannelIconURLWithType(channelID discord.Snowflake, icon discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) ChannelInvites(channelID discord.Snowflake, invites []discord.Invite)
- func (m *Mocker) ChannelWebhooks(channelID discord.Snowflake, webhooks []discord.Webhook)
- func (m *Mocker) Channels(guildID discord.Snowflake, c []discord.Channel)
- func (m *Mocker) Clone(t *testing.T) (clone *Mocker)
- func (m *Mocker) CloneSession(t *testing.T) (clone *Mocker, s *session.Session)
- func (m *Mocker) CloneState(t *testing.T) (clone *Mocker, s *state.State)
- func (m *Mocker) Close()
- func (m *Mocker) CreateChannel(d api.CreateChannelData, c discord.Channel)
- func (m *Mocker) CreateEmoji(guildID discord.Snowflake, d api.CreateEmojiData, e discord.Emoji)
- func (m *Mocker) CreateGuild(d api.CreateGuildData, g discord.Guild)
- func (m *Mocker) CreateInvite(d api.CreateInviteData, i discord.Invite)
- func (m *Mocker) CreatePrivateChannel(c discord.Channel)
- func (m *Mocker) CreateRole(guildID discord.Snowflake, d api.CreateRoleData, role discord.Role)
- func (m *Mocker) CreateWebhook(d api.CreateWebhookData, webhook discord.Webhook)
- func (m *Mocker) DeleteAllReactions(channelID, messageID discord.Snowflake)
- func (m *Mocker) DeleteChannel(id discord.Snowflake)
- func (m *Mocker) DeleteChannelPermission(channelID, overwriteID discord.Snowflake)
- func (m *Mocker) DeleteEmoji(guildID, emojiID discord.Snowflake)
- func (m *Mocker) DeleteGuild(id discord.Snowflake)
- func (m *Mocker) DeleteInvite(i discord.Invite)
- func (m *Mocker) DeleteMessage(channelID, messageID discord.Snowflake)
- func (m *Mocker) DeleteMessages(channelID discord.Snowflake, messageIDs []discord.Snowflake)
- func (m *Mocker) DeleteReactions(channelID, messageID discord.Snowflake, e api.Emoji)
- func (m *Mocker) DeleteRole(guildID, roleID discord.Snowflake)
- func (m *Mocker) DeleteUserReaction(channelID, messageID, userID discord.Snowflake, e api.Emoji)
- func (m *Mocker) DeleteWebhook(id discord.Snowflake)
- func (m *Mocker) DeleteWebhookWithToken(id discord.Snowflake, token string)
- func (m *Mocker) DiscoverySplashURL(guildID discord.Snowflake, splash discord.Hash, img io.Reader)
- func (m *Mocker) DiscoverySplashURLWithType(guildID discord.Snowflake, splash discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) EditChannelPermission(channelID, overwriteID discord.Snowflake, d api.EditChannelPermissionData)
- func (m *Mocker) EditEmbed(msg discord.Message)
- func (m *Mocker) EditMessage(embed *discord.Embed, msg discord.Message, suppressEmbeds bool)
- func (m *Mocker) EditMessageComplex(d api.EditMessageData, msg discord.Message)
- func (m *Mocker) EditText(msg discord.Message)
- func (m *Mocker) Emoji(guildID discord.Snowflake, e discord.Emoji)
- func (m *Mocker) EmojiURL(emojiID discord.Snowflake, animated bool, img io.Reader)
- func (m *Mocker) EmojiURLWithType(emojiID discord.Snowflake, animated bool, t discord.ImageType, img io.Reader)
- func (m *Mocker) Emojis(guildID discord.Snowflake, e []discord.Emoji)
- func (m *Mocker) Error(method, path string, e httputil.HTTPError)
- func (m *Mocker) Eval()
- func (m *Mocker) ExecuteWebhook(webhookID discord.Snowflake, token string, d api.ExecuteWebhookData)
- func (m *Mocker) ExecuteWebhookAndWait(webhookID discord.Snowflake, token string, d api.ExecuteWebhookData, ...)
- func (m *Mocker) GetBan(guildID discord.Snowflake, b discord.Ban)
- func (m *Mocker) Guild(g discord.Guild)
- func (m *Mocker) GuildIconURL(guildID discord.Snowflake, icon discord.Hash, img io.Reader)
- func (m *Mocker) GuildIconURLWithType(guildID discord.Snowflake, icon discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) GuildImage(guildID discord.Snowflake, style api.GuildImageStyle, img io.Reader)
- func (m *Mocker) GuildInvites(guildID discord.Snowflake, invites []discord.Invite)
- func (m *Mocker) GuildPreview(p discord.GuildPreview)
- func (m *Mocker) GuildVanityURL(guildID discord.Snowflake, i discord.Invite)
- func (m *Mocker) GuildWebhooks(guildID discord.Snowflake, webhooks []discord.Webhook)
- func (m *Mocker) GuildWidget(guildID discord.Snowflake, e discord.GuildWidget)
- func (m *Mocker) GuildWithCount(g discord.Guild)
- func (m *Mocker) Guilds(limit uint, g []discord.Guild)
- func (m *Mocker) GuildsAfter(after discord.Snowflake, limit uint, g []discord.Guild)
- func (m *Mocker) GuildsBefore(before discord.Snowflake, limit uint, g []discord.Guild)
- func (m *Mocker) Integrations(guildID discord.Snowflake, integrations []discord.Integration)
- func (m *Mocker) Invite(i discord.Invite)
- func (m *Mocker) InviteWithCounts(i discord.Invite)
- func (m *Mocker) Kick(guildID, userID discord.Snowflake)
- func (m *Mocker) LeaveGuild(id discord.Snowflake)
- func (m *Mocker) Login(email, password string, response api.LoginResponse)
- func (m *Mocker) Me(u discord.User)
- func (m *Mocker) Member(guildID discord.Snowflake, member discord.Member)
- func (m *Mocker) Members(guildID discord.Snowflake, limit uint, members []discord.Member)
- func (m *Mocker) MembersAfter(guildID, after discord.Snowflake, limit uint, members []discord.Member)
- func (m *Mocker) Message(msg discord.Message)
- func (m *Mocker) Messages(channelID discord.Snowflake, limit uint, messages []discord.Message)
- func (m *Mocker) MessagesAfter(channelID, after discord.Snowflake, limit uint, messages []discord.Message)
- func (m *Mocker) MessagesAround(channelID, around discord.Snowflake, limit uint, messages []discord.Message)
- func (m *Mocker) MessagesBefore(channelID, before discord.Snowflake, limit uint, messages []discord.Message)
- func (m *Mocker) Mock(name, method, path string, f MockFunc)
- func (m *Mocker) MockAPI(name, method, path string, f MockFunc)
- func (m *Mocker) ModifyChannel(id discord.Snowflake, d api.ModifyChannelData)
- func (m *Mocker) ModifyEmoji(guildID, emojiID discord.Snowflake, d api.ModifyEmojiData)
- func (m *Mocker) ModifyGuild(d api.ModifyGuildData, g discord.Guild)
- func (m *Mocker) ModifyGuildWidget(guildID discord.Snowflake, d api.ModifyGuildWidgetData, e discord.GuildWidget)
- func (m *Mocker) ModifyIntegration(guildID, integrationID discord.Snowflake, d api.ModifyIntegrationData)
- func (m *Mocker) ModifyMe(d api.ModifySelfData, u discord.User)
- func (m *Mocker) ModifyMember(guildID, userID discord.Snowflake, d api.ModifyMemberData)
- func (m *Mocker) ModifyRole(guildID discord.Snowflake, d api.ModifyRoleData, role discord.Role)
- func (m *Mocker) ModifyWebhook(d api.ModifyWebhookData, webhook discord.Webhook)
- func (m *Mocker) ModifyWebhookWithToken(d api.ModifyWebhookData, webhook discord.Webhook)
- func (m *Mocker) MoveChannel(guildID discord.Snowflake, d []api.MoveChannelData)
- func (m *Mocker) MoveRole(guildID discord.Snowflake, d []api.MoveRoleData, roles []discord.Role)
- func (m *Mocker) PinMessage(channelID, messageID discord.Snowflake)
- func (m *Mocker) PinnedMessages(channelID discord.Snowflake, messages []discord.Message)
- func (m *Mocker) PrivateChannels(c []discord.Channel)
- func (m *Mocker) Prune(guildID discord.Snowflake, d api.PruneData, pruned uint)
- func (m *Mocker) PruneCount(guildID discord.Snowflake, d api.PruneCountData, pruned uint)
- func (m *Mocker) React(channelID, messageID discord.Snowflake, e api.Emoji)
- func (m *Mocker) Reactions(channelID, messageID discord.Snowflake, limit uint, e api.Emoji, ...)
- func (m *Mocker) ReactionsAfter(channelID, messageID, after discord.Snowflake, limit uint, e api.Emoji, ...)
- func (m *Mocker) ReactionsBefore(channelID, messageID discord.Snowflake, before discord.Snowflake, limit uint, ...)
- func (m *Mocker) RemoveRecipient(channelID, userID discord.Snowflake)
- func (m *Mocker) RemoveRole(guildID, userID, roleID discord.Snowflake)
- func (m *Mocker) Roles(guildID discord.Snowflake, roles []discord.Role)
- func (m *Mocker) SendEmbed(msg discord.Message)
- func (m *Mocker) SendMessage(embed *discord.Embed, msg discord.Message)
- func (m *Mocker) SendMessageComplex(d api.SendMessageData, msg discord.Message)
- func (m *Mocker) SendText(msg discord.Message)
- func (m *Mocker) SplashURL(guildID discord.Snowflake, splash discord.Hash, img io.Reader)
- func (m *Mocker) SplashURLWithType(guildID discord.Snowflake, splash discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) SyncIntegration(guildID, integrationID discord.Snowflake)
- func (m *Mocker) TOTP(code, ticket string, response api.LoginResponse)
- func (m *Mocker) Typing(channelID discord.Snowflake)
- func (m *Mocker) Unban(guildID, userID discord.Snowflake)
- func (m *Mocker) UnpinMessage(channelID, messageID discord.Snowflake)
- func (m *Mocker) Unreact(channelID, messageID discord.Snowflake, e api.Emoji)
- func (m *Mocker) User(u discord.User)
- func (m *Mocker) UserConnections(c []discord.Connection)
- func (m *Mocker) VoiceRegionsGuild(guildID discord.Snowflake, vr []discord.VoiceRegion)
- func (m *Mocker) Webhook(webhook discord.Webhook)
- func (m *Mocker) WebhookWithToken(webhook discord.Webhook)
- Bugs
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 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 // mock-server. Client *http.Client // contains filtered or unexported fields }
Mocker handles the mocking of arikawa's API calls.
func New ¶
New creates a new Mocker with a started server listening on Mocker.Server.Listener.Addr().
func NewSession ¶
NewSession creates a new Mocker, starts its test server and returns a manipulated session.Session using the test server.
func NewState ¶
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) AddMember ¶
AddMember mocks a AddMember request.
The User.ID field of the passed discord.Member must be set.
func (*Mocker) AddRecipient ¶
AddRecipient mocks a AddRecipient request.
func (*Mocker) AttachIntegration ¶
func (m *Mocker) AttachIntegration(guildID, integrationID discord.Snowflake, integrationType discord.Service)
AttachIntegration mocks a AttachIntegration request.
func (*Mocker) AuditLog ¶
AuditLog mocks a AuditLog request.
This method will sanitize AuditLog.Webhook.ID, AuditLog.Webhook.User.ID, AuditLog.Users.ID, AuditLog.Entries.ID, AuditLog.Entries.UserID, AuditLog.Integrations.ID, AuditLog.Integrations.RoleID and AuditLog.Integrations.User.ID.
func (*Mocker) BannerURL ¶
BannerURL mocks a BannerURL request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) BannerURLWithType ¶
func (m *Mocker) BannerURLWithType( guildID discord.Snowflake, banner discord.Hash, t discord.ImageType, img io.Reader, )
BannerURLWithType mocks a BannerURLWithType request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) ChangeOwnNickname ¶
ChangeOwnNickname mocks a ChangeOwnNickname request.
func (*Mocker) Channel ¶
Channel mocks a Channel request.
The ID field of the passed discord.Channel must be set.
This method will sanitize Channel.ID.
func (*Mocker) ChannelIconURL ¶
ChannelIconURL mocks a ChannelIconURL request.
func (*Mocker) ChannelIconURLWithType ¶
func (m *Mocker) ChannelIconURLWithType( channelID discord.Snowflake, icon discord.Hash, t discord.ImageType, img io.Reader, )
ChannelIconURLWithType mocks a ChannelIconURLWithType request.
func (*Mocker) ChannelInvites ¶
ChannelInvites mocks a ChannelInvites request.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID and Invite.Inviter.ID.
func (*Mocker) ChannelWebhooks ¶
ChannelWebhooks mocks a ChannelWebhooks request.
This method will sanitize Webhook.ID, Webhook.User.ID and Webhook.ChannelID.
func (*Mocker) Clone ¶ added in v1.2.0
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 ¶
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 ¶
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.
This method will sanitize Channel.ID.
func (*Mocker) CreateEmoji ¶
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.
This method will sanitize Guild.ID, Guild.OwnerID, Guild.Emojis.ID and Guild.Roles.ID.
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.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, and Invite.Inviter.ID.
func (*Mocker) CreatePrivateChannel ¶
CreatePrivateChannel mocks a CreatePrivateChannel request.
The c.DMRecipients[0] field of the passed discord.Channel must be set.
func (*Mocker) CreateRole ¶
CreateRole mocks a CreateRole request.
This method will sanitize Role.ID.
func (*Mocker) CreateWebhook ¶
func (m *Mocker) CreateWebhook(d api.CreateWebhookData, webhook discord.Webhook)
CreateWebhook mocks a CreateWebhook request.
This method will sanitize Webhook.ID, Webhook.User.ID and Webhook.ChannelID.
func (*Mocker) DeleteAllReactions ¶
DeleteAllReactions mocks a DeleteAllReactions request.
func (*Mocker) DeleteChannel ¶
DeleteChannel mocks a DeleteChannel request.
func (*Mocker) DeleteChannelPermission ¶
DeleteChannelPermission mocks a DeleteChannelPermission request.
func (*Mocker) DeleteEmoji ¶
DeleteEmoji mocks a DeleteEmoji request.
func (*Mocker) DeleteGuild ¶
DeleteGuild mocks a DeleteGuild request.
func (*Mocker) DeleteInvite ¶
DeleteInvite mocks a DeleteInvite request.
The Code field of the passed discord.Invite must be set.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID and Invite.Inviter.ID.
func (*Mocker) DeleteMessage ¶
DeleteMessage mocks a DeleteMessage request.
func (*Mocker) DeleteMessages ¶
DeleteMessages mocks a DeleteMessages request.
func (*Mocker) DeleteReactions ¶
DeleteReactions mocks a DeleteReactions request.
func (*Mocker) DeleteRole ¶
DeleteRole mocks a DeleteRole request.
func (*Mocker) DeleteUserReaction ¶
DeleteUserReaction mocks a DeleteUserReaction request.
func (*Mocker) DeleteWebhook ¶
DeleteWebhook mocks a DeleteWebhook request.
func (*Mocker) DeleteWebhookWithToken ¶
DeleteWebhookWithToken mocks a DeleteWebhookWithToken request.
func (*Mocker) DiscoverySplashURL ¶
DiscoverySplashURL mocks a DiscoverySplashURL request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) DiscoverySplashURLWithType ¶
func (m *Mocker) DiscoverySplashURLWithType( guildID discord.Snowflake, splash discord.Hash, t discord.ImageType, img io.Reader, )
DiscoverySplashURLWithType mocks a DiscoverySplashURLWithType request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) EditChannelPermission ¶
func (m *Mocker) EditChannelPermission(channelID, overwriteID discord.Snowflake, d api.EditChannelPermissionData)
EditChannelPermission mocks a EditChannelPermission request.
func (*Mocker) EditEmbed ¶
EditEmbed mocks a EditEmbed request.
The ID field, the ChannelID field and the Embed[0] field of the passed discord.Message must be set.
This method will sanitize Message.Author.ID, Message.Embed.Type and Message.Embed.Color.
func (*Mocker) EditMessage ¶
EditMessage mocks a EditMessage request.
The ID field, the ChannelID field, the Content field of the passed discord.Message must be set.
This method will sanitize Message.Author.ID, Message.Embed.Type and Message.Embed.Color.
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.
This method will sanitize Message.Author.ID, Message.Embed.Type and Message.Embed.Color.
func (*Mocker) EditText ¶
EditText mocks a EditText request.
The ID field, the ChannelID field and the Content field of the passed Message must be set.
This method will sanitize Message.Author.ID.
func (*Mocker) Emoji ¶
Emoji mocks a Emoji request.
The ID field of the passed discord.Emoji is required.
This method will sanitize Emoji.ID and Emoji.User.ID.
func (*Mocker) EmojiURLWithType ¶
func (m *Mocker) EmojiURLWithType(emojiID discord.Snowflake, animated bool, t discord.ImageType, img io.Reader)
EmojiURLWithType mocks a EmojiURLWithType request.
func (*Mocker) Emojis ¶
Emojis mocks a Emojis request.
This method will sanitize Emoji.ID and Emoji.User.ID.
func (*Mocker) Eval ¶
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. This must be called at the end of every test.
func (*Mocker) ExecuteWebhook ¶
func (m *Mocker) ExecuteWebhook(webhookID discord.Snowflake, token string, d api.ExecuteWebhookData)
ExecuteWebhook mocks a ExecuteWebhook request and doesn't "wait" for the message to be delivered.
This method will sanitize Message.ID and Message.Author.ID.
func (*Mocker) ExecuteWebhookAndWait ¶
func (m *Mocker) ExecuteWebhookAndWait( webhookID discord.Snowflake, token string, d api.ExecuteWebhookData, msg discord.Message, )
ExecuteWebhookAndWait mocks a ExecuteWebhook request and "waits" for the message to be delivered.
This method will sanitize Message.ID and Message.Author.ID.
func (*Mocker) GetBan ¶
GetBan mocks a GetBan request.
The User.ID field of the passed discord.Ban must be set.
func (*Mocker) Guild ¶
Guild mocks a Guild request.
The ID field of the passed discord.Guild must be set.
This method will sanitize Guild.ID, Guild.OwnerID, Guild.Emojis.ID and Guild.Roles.ID.
func (*Mocker) GuildIconURL ¶
GuildIconURL mocks a GuildIconURL request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) GuildIconURLWithType ¶
func (m *Mocker) GuildIconURLWithType( guildID discord.Snowflake, icon discord.Hash, t discord.ImageType, img io.Reader, )
GuildIconURLWithType mocks a GuildIconURLWithType request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) GuildImage ¶
GuildImage mocks a GuildImage request.
func (*Mocker) GuildInvites ¶
GuildInvites mocks a GuildInvites request.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID and Invite.Inviter.ID.
func (*Mocker) GuildPreview ¶
func (m *Mocker) GuildPreview(p discord.GuildPreview)
GuildPreview mocks a GuildPreview request.
This method will sanitize GuildPreview.ID, GuildPreview.Emojis.ID and GuildPreview.Emojis.User.ID.
func (*Mocker) GuildVanityURL ¶
GuildVanityURL mocks a GuildVanityURL request.
Although those fields are normally not sent, this method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID, Invite.Inviter.ID.
func (*Mocker) GuildWebhooks ¶
GuildWebhooks mocks a GuildWebhooks request.
This method will sanitize Webhook.ID, Webhook.User.ID and Webhook.ChannelID.
func (*Mocker) GuildWidget ¶
func (m *Mocker) GuildWidget(guildID discord.Snowflake, e discord.GuildWidget)
GuildWidget mocks a GuildWidget request.
func (*Mocker) GuildWithCount ¶
GuildWithCount mocks a GuildWithCount request.
The ID field of the passed discord.Guild must be set.
This method will sanitize Guild.ID, Guild.OwnerID, Guild.Emojis.ID and Guild.Roles.ID.
func (*Mocker) Guilds ¶
Guilds mocks a Guilds request.
This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.
func (*Mocker) GuildsAfter ¶
GuildsAfter mocks a GuildsAfter request.
This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.WithToken
func (*Mocker) GuildsBefore ¶
GuildsBefore mocks a GuildsBefore request.
This method will sanitize Guilds.ID, Guilds.OwnerID, Guilds.Emojis.ID and Guilds.Roles.ID.
func (*Mocker) Integrations ¶
func (m *Mocker) Integrations(guildID discord.Snowflake, integrations []discord.Integration)
Integrations mocks a Integrations request.
This method will sanitize Integration.ID, Integration.RoleID and Integration.User.ID.
func (*Mocker) Invite ¶
Invite mocks a Invite request.
The Code field of the passed discord.Invite must be set.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID and Invite.Inviter.ID.
func (*Mocker) InviteWithCounts ¶
InviteWithCounts mocks a InviteWithCounts request.
The Code field of the passed discord.Invite must be set.
This method will sanitize Invite.Guild.ID, Invite.Guild.OwnerID, Invite.Guild.Emojis.ID, Invite.Guild.Roles.ID, Invite.Channel.ID and Invite.Inviter.ID.
func (*Mocker) LeaveGuild ¶
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) Member ¶
Member mocks a Member request.
The User.ID field of the passed member must be set.
func (*Mocker) MembersAfter ¶
func (m *Mocker) MembersAfter(guildID, after discord.Snowflake, limit uint, members []discord.Member)
MembersAfter mocks a MembersAfter request.
This method will sanitize Member.User.ID.
func (*Mocker) Message ¶
Message mocks a Message request.
The ID field and the ChannelID field of the passed discord.Message must be set.
This method will sanitize Message.Author.ID.
func (*Mocker) Messages ¶
Messages mocks a Messages request.
This method will sanitize Message.ID, Message.ChannelID and Message.Author.ID.
func (*Mocker) MessagesAfter ¶
func (m *Mocker) MessagesAfter(channelID, after discord.Snowflake, limit uint, messages []discord.Message)
MessagesAfter mocks a MessagesAfter request.
This method will sanitize Message.ID, Message.ChannelID and Message.Author.ID.
func (*Mocker) MessagesAround ¶
func (m *Mocker) MessagesAround(channelID, around discord.Snowflake, limit uint, messages []discord.Message)
MessagesAround mocks a MessagesAround request.
This method will sanitize Message.ID, Message.ChannelID and Message.Author.ID.
func (*Mocker) MessagesBefore ¶
func (m *Mocker) MessagesBefore(channelID, before discord.Snowflake, 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 ¶
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 ¶
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.Snowflake, d api.ModifyChannelData)
ModifyChannel mocks a ModifyChannel request.
func (*Mocker) ModifyEmoji ¶
func (m *Mocker) ModifyEmoji(guildID, emojiID discord.Snowflake, 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.
This method will sanitize Guild.ID, Guild.OwnerID, Guild.Emojis.ID and Guild.Roles.ID.
func (*Mocker) ModifyGuildWidget ¶
func (m *Mocker) ModifyGuildWidget(guildID discord.Snowflake, d api.ModifyGuildWidgetData, e discord.GuildWidget)
ModifyGuildWidget mocks a ModifyGuildWidget request.
func (*Mocker) ModifyIntegration ¶
func (m *Mocker) ModifyIntegration(guildID, integrationID discord.Snowflake, 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.
This method will sanitize User.ID.
func (*Mocker) ModifyMember ¶
func (m *Mocker) ModifyMember(guildID, userID discord.Snowflake, d api.ModifyMemberData)
ModifyMember mocks a ModifyMember request.
func (*Mocker) ModifyRole ¶
ModifyRole mocks a ModifyRole request.
This method will sanitize Role.ID.
func (*Mocker) ModifyWebhook ¶
func (m *Mocker) ModifyWebhook(d api.ModifyWebhookData, webhook 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, webhook 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.Snowflake, d []api.MoveChannelData)
MoveChannel mocks a MoveChannel request.
func (*Mocker) PinMessage ¶
PinMessage mocks a PinMessage request.
func (*Mocker) PinnedMessages ¶
PinnedMessages mocks a PinnedMessages request.
This method will sanitize Message.ID, Message.ChannelID and Message.Author.ID.
func (*Mocker) PrivateChannels ¶
PrivateChannels mocks a PrivateChannels request.
This method will sanitize Channels.ID.
func (*Mocker) PruneCount ¶
PruneCount mocks a PruneCount request.
func (*Mocker) Reactions ¶
func (m *Mocker) Reactions(channelID, messageID discord.Snowflake, limit uint, e api.Emoji, u []discord.User)
Reactions mocks a Reactions request.
This method will sanitize Users.ID.
func (*Mocker) ReactionsAfter ¶
func (m *Mocker) ReactionsAfter( channelID, messageID, after discord.Snowflake, limit uint, e api.Emoji, u []discord.User, )
ReactionsAfter mocks a ReactionsAfter request.
This method will sanitize Users.ID.
func (*Mocker) ReactionsBefore ¶
func (m *Mocker) ReactionsBefore( channelID, messageID discord.Snowflake, before discord.Snowflake, limit uint, e api.Emoji, u []discord.User, )
ReactionsBefore mocks a ReactionsBefore request.
This method will sanitize Users.ID.
func (*Mocker) RemoveRecipient ¶
RemoveRecipient mocks a RemoveRecipient request.
func (*Mocker) RemoveRole ¶
RemoveRole mocks a RemoveRole request.
func (*Mocker) SendEmbed ¶
SendEmbed mocks a SendEmbed request.
The ChannelID field and the Embed 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) SendMessage ¶
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.
This method will sanitize Message.ID, Message.Author.ID, Message.Embeds.Type and Message.Embeds.Color.
func (*Mocker) SendText ¶
SendText mocks a SendText 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) SplashURL ¶
SplashURL mocks a SplashURL request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) SplashURLWithType ¶
func (m *Mocker) SplashURLWithType( guildID discord.Snowflake, splash discord.Hash, t discord.ImageType, img io.Reader, )
SplashURLWithType mocks a SplashURLWithType request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) SyncIntegration ¶
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) UnpinMessage ¶ added in v1.1.0
UnpinMessage mocks a UnpinMessage request.
func (*Mocker) UserConnections ¶
func (m *Mocker) UserConnections(c []discord.Connection)
UserConnections mocks a UserConnections request.
func (*Mocker) VoiceRegionsGuild ¶
func (m *Mocker) VoiceRegionsGuild(guildID discord.Snowflake, vr []discord.VoiceRegion)
VoiceRegionsGuild mocks a VoiceRegionsGuild request.
func (*Mocker) Webhook ¶
Webhook mocks a Webhook request.
The ID field of the passed discord.Webhook must be set.
This method will sanitize Webhook.User.ID and Webhook.ChannelID.
func (*Mocker) WebhookWithToken ¶
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 MarshalJSON method doesn't get called, there is no way to differentiate between option.NullX and omitted.