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 discord.ChannelID, messageID discord.MessageID, send, ret api.Ack)
- func (m *Mocker) AddMember(guildID discord.GuildID, d api.AddMemberData, member discord.Member)
- func (m *Mocker) AddRecipient(channelID discord.ChannelID, userID discord.UserID, ...)
- func (m *Mocker) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID)
- func (m *Mocker) AttachIntegration(guildID discord.GuildID, integrationID discord.IntegrationID, ...)
- func (m *Mocker) AuditLog(guildID discord.GuildID, d api.AuditLogData, al discord.AuditLog)
- func (m *Mocker) Ban(guildID discord.GuildID, userID discord.UserID, d api.BanData)
- func (m *Mocker) Banner(guildID discord.GuildID, banner discord.Hash, img io.Reader)
- func (m *Mocker) BannerWithType(guildID discord.GuildID, banner discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) Bans(guildID discord.GuildID, b []discord.Ban)
- func (m *Mocker) ChangeOwnNickname(guildID discord.GuildID, nick string)
- func (m *Mocker) Channel(c discord.Channel)
- func (m *Mocker) ChannelIcon(channelID discord.ChannelID, icon discord.Hash, img io.Reader)
- func (m *Mocker) ChannelIconWithType(channelID discord.ChannelID, icon discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) ChannelInvites(channelID discord.ChannelID, invites []discord.Invite)
- func (m *Mocker) ChannelWebhooks(channelID discord.ChannelID, webhooks []discord.Webhook)
- func (m *Mocker) Channels(guildID discord.GuildID, 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.GuildID, 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.GuildID, d api.CreateRoleData, role discord.Role)
- func (m *Mocker) CreateWebhook(d api.CreateWebhookData, wh discord.Webhook)
- func (m *Mocker) DeleteAllReactions(channelID discord.ChannelID, messageID discord.MessageID)
- func (m *Mocker) DeleteChannel(id discord.ChannelID)
- func (m *Mocker) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake)
- func (m *Mocker) DeleteEmoji(guildID discord.GuildID, emojiID discord.EmojiID)
- func (m *Mocker) DeleteGuild(id discord.GuildID)
- func (m *Mocker) DeleteInvite(i discord.Invite)
- func (m *Mocker) DeleteMessage(channelID discord.ChannelID, messageID discord.MessageID)
- func (m *Mocker) DeleteMessages(channelID discord.ChannelID, messageIDs []discord.MessageID)
- func (m *Mocker) DeleteReactions(channelID discord.ChannelID, messageID discord.MessageID, e api.Emoji)
- func (m *Mocker) DeleteRole(guildID discord.GuildID, roleID discord.RoleID)
- func (m *Mocker) DeleteUserReaction(channelID discord.ChannelID, messageID discord.MessageID, ...)
- func (m *Mocker) DeleteWebhook(id discord.WebhookID)
- func (m *Mocker) DeleteWebhookWithToken(id discord.WebhookID, token string)
- func (m *Mocker) DiscoverySplash(guildID discord.GuildID, splash discord.Hash, img io.Reader)
- func (m *Mocker) DiscoverySplashWithType(guildID discord.GuildID, splash discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) EditChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake, ...)
- 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.GuildID, e discord.Emoji)
- func (m *Mocker) EmojiPicture(emojiID discord.EmojiID, animated bool, img io.Reader)
- func (m *Mocker) EmojiPictureWithType(emojiID discord.EmojiID, animated bool, t discord.ImageType, img io.Reader)
- func (m *Mocker) Emojis(guildID discord.GuildID, e []discord.Emoji)
- func (m *Mocker) Error(method, path string, e httputil.HTTPError)
- func (m *Mocker) Eval()
- func (m *Mocker) ExecuteWebhook(webhookID discord.WebhookID, token string, d api.ExecuteWebhookData)
- func (m *Mocker) ExecuteWebhookAndWait(webhookID discord.WebhookID, token string, d api.ExecuteWebhookData, ...)
- func (m *Mocker) GetBan(guildID discord.GuildID, b discord.Ban)
- func (m *Mocker) Guild(g discord.Guild)
- func (m *Mocker) GuildIcon(guildID discord.GuildID, icon discord.Hash, img io.Reader)
- func (m *Mocker) GuildIconWithType(guildID discord.GuildID, icon discord.Hash, t discord.ImageType, img io.Reader)
- func (m *Mocker) GuildImage(guildID discord.GuildID, style api.GuildImageStyle, img io.Reader)
- func (m *Mocker) GuildInvites(guildID discord.GuildID, invites []discord.Invite)
- func (m *Mocker) GuildPreview(p discord.GuildPreview)
- func (m *Mocker) GuildVanityURL(guildID discord.GuildID, i discord.Invite)
- func (m *Mocker) GuildWebhooks(guildID discord.GuildID, webhooks []discord.Webhook)
- func (m *Mocker) GuildWidget(guildID discord.GuildID, 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.GuildID, limit uint, g []discord.Guild)
- func (m *Mocker) GuildsBefore(before discord.GuildID, limit uint, g []discord.Guild)
- func (m *Mocker) Integrations(guildID discord.GuildID, integrations []discord.Integration)
- func (m *Mocker) Invite(i discord.Invite)
- func (m *Mocker) InviteWithCounts(i discord.Invite)
- func (m *Mocker) Kick(guildID discord.GuildID, userID discord.UserID)
- func (m *Mocker) LeaveGuild(id discord.GuildID)
- func (m *Mocker) Login(email, password string, response api.LoginResponse)
- func (m *Mocker) Me(u discord.User)
- func (m *Mocker) Member(guildID discord.GuildID, member discord.Member)
- func (m *Mocker) Members(guildID discord.GuildID, limit uint, members []discord.Member)
- func (m *Mocker) MembersAfter(guildID discord.GuildID, after discord.UserID, limit uint, ...)
- func (m *Mocker) Message(msg discord.Message)
- func (m *Mocker) Messages(channelID discord.ChannelID, limit uint, messages []discord.Message)
- func (m *Mocker) MessagesAfter(channelID discord.ChannelID, after discord.MessageID, limit uint, ...)
- func (m *Mocker) MessagesAround(channelID discord.ChannelID, around discord.MessageID, limit uint, ...)
- func (m *Mocker) MessagesBefore(channelID discord.ChannelID, before discord.MessageID, limit uint, ...)
- 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.ChannelID, d api.ModifyChannelData)
- func (m *Mocker) ModifyEmoji(guildID discord.GuildID, emojiID discord.EmojiID, d api.ModifyEmojiData)
- func (m *Mocker) ModifyGuild(d api.ModifyGuildData, g discord.Guild)
- func (m *Mocker) ModifyGuildWidget(guildID discord.GuildID, d api.ModifyGuildWidgetData, e discord.GuildWidget)
- func (m *Mocker) ModifyIntegration(guildID discord.GuildID, integrationID discord.IntegrationID, ...)
- func (m *Mocker) ModifyMe(d api.ModifySelfData, u discord.User)
- func (m *Mocker) ModifyMember(guildID discord.GuildID, userID discord.UserID, d api.ModifyMemberData)
- func (m *Mocker) ModifyRole(guildID discord.GuildID, d api.ModifyRoleData, role discord.Role)
- func (m *Mocker) ModifyWebhook(d api.ModifyWebhookData, wh discord.Webhook)
- func (m *Mocker) ModifyWebhookWithToken(d api.ModifyWebhookData, wh discord.Webhook)
- func (m *Mocker) MoveChannel(guildID discord.GuildID, d []api.MoveChannelData)
- func (m *Mocker) MoveRole(guildID discord.GuildID, d []api.MoveRoleData, roles []discord.Role)
- func (m *Mocker) PinMessage(channelID discord.ChannelID, messageID discord.MessageID)
- func (m *Mocker) PinnedMessages(channelID discord.ChannelID, messages []discord.Message)
- func (m *Mocker) PrivateChannels(c []discord.Channel)
- func (m *Mocker) Prune(guildID discord.GuildID, d api.PruneData, pruned uint)
- func (m *Mocker) PruneCount(guildID discord.GuildID, d api.PruneCountData, pruned uint)
- func (m *Mocker) React(channelID discord.ChannelID, messageID discord.MessageID, e api.Emoji)
- func (m *Mocker) Reactions(channelID discord.ChannelID, messageID discord.MessageID, limit uint, ...)
- func (m *Mocker) ReactionsAfter(channelID discord.ChannelID, messageID discord.MessageID, after discord.UserID, ...)
- func (m *Mocker) ReactionsBefore(channelID discord.ChannelID, messageID discord.MessageID, ...)
- func (m *Mocker) RemoveRecipient(channelID discord.ChannelID, userID discord.UserID)
- func (m *Mocker) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID)
- func (m *Mocker) Roles(guildID discord.GuildID, 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) Splash(guildID discord.GuildID, splash discord.Hash, img io.Reader)
- func (m *Mocker) SplashWithType(guildID discord.GuildID, splash discord.Hash, t discord.ImageType, ...)
- func (m *Mocker) SyncIntegration(guildID discord.GuildID, integrationID discord.IntegrationID)
- func (m *Mocker) TOTP(code, ticket string, response api.LoginResponse)
- func (m *Mocker) Typing(channelID discord.ChannelID)
- func (m *Mocker) Unban(guildID discord.GuildID, userID discord.UserID)
- func (m *Mocker) UnpinMessage(channelID discord.ChannelID, messageID discord.MessageID)
- func (m *Mocker) Unreact(channelID discord.ChannelID, messageID discord.MessageID, e api.Emoji)
- func (m *Mocker) User(u discord.User)
- func (m *Mocker) UserConnections(c []discord.Connection)
- func (m *Mocker) VoiceRegionsGuild(guildID discord.GuildID, vr []discord.VoiceRegion)
- func (m *Mocker) Webhook(webhook discord.Webhook)
- func (m *Mocker) WebhookWithToken(wh 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 ¶
func (m *Mocker) AddRecipient(channelID discord.ChannelID, userID discord.UserID, accessToken, nickname string)
AddRecipient mocks a AddRecipient 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 ¶
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) Banner ¶ added in v1.3.0
Banner mocks a Banner request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) BannerWithType ¶ added in v1.3.0
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) 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) ChannelIcon ¶ added in v1.3.0
ChannelIcon mocks a ChannelIcon request.
func (*Mocker) ChannelIconWithType ¶ added in v1.3.0
func (m *Mocker) ChannelIconWithType( channelID discord.ChannelID, icon discord.Hash, t discord.ImageType, img io.Reader, )
ChannelIconWithType mocks a ChannelIconWithType 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, wh 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 ¶
func (m *Mocker) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake)
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 ¶
func (m *Mocker) DeleteReactions(channelID discord.ChannelID, messageID discord.MessageID, e api.Emoji)
DeleteReactions mocks a DeleteReactions request.
func (*Mocker) DeleteRole ¶
DeleteRole mocks a DeleteRole request.
func (*Mocker) DeleteUserReaction ¶
func (m *Mocker) DeleteUserReaction( channelID discord.ChannelID, messageID discord.MessageID, userID discord.UserID, e api.Emoji, )
DeleteUserReaction mocks a DeleteUserReaction request.
func (*Mocker) DeleteWebhook ¶
DeleteWebhook mocks a DeleteWebhook request.
func (*Mocker) DeleteWebhookWithToken ¶
DeleteWebhookWithToken mocks a DeleteWebhookWithToken request.
func (*Mocker) DiscoverySplash ¶ added in v1.3.0
DiscoverySplash mocks a DiscoverySplash request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) DiscoverySplashWithType ¶ added in v1.3.0
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 ¶
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) EmojiPicture ¶ added in v1.3.0
EmojiPicture mocks a EmojiPicture request.
func (*Mocker) EmojiPictureWithType ¶ added in v1.3.0
func (m *Mocker) EmojiPictureWithType(emojiID discord.EmojiID, animated bool, t discord.ImageType, img io.Reader)
EmojiPictureWithType mocks a EmojiPictureWithType 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.WebhookID, 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.WebhookID, 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) GuildIcon ¶ added in v1.3.0
GuildIcon mocks a GuildIcon request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) GuildIconWithType ¶ added in v1.3.0
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) 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.GuildID, 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.GuildID, 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 discord.GuildID, after discord.UserID, 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 discord.ChannelID, after discord.MessageID, 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 discord.ChannelID, around discord.MessageID, 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 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 ¶
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.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.
This method will sanitize Guild.ID, Guild.OwnerID, Guild.Emojis.ID and Guild.Roles.ID.
func (*Mocker) ModifyGuildWidget ¶
func (m *Mocker) ModifyGuildWidget(guildID discord.GuildID, d api.ModifyGuildWidgetData, e discord.GuildWidget)
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.
This method will sanitize User.ID.
func (*Mocker) ModifyMember ¶
func (m *Mocker) ModifyMember(guildID discord.GuildID, userID discord.UserID, 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, 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) 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 discord.ChannelID, messageID discord.MessageID, 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 discord.ChannelID, messageID discord.MessageID, after discord.UserID, 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 discord.ChannelID, messageID discord.MessageID, before discord.UserID, 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) Splash ¶ added in v1.3.0
Splash mocks a Splash request.
This method can be used for both discord.Guild and discord.GuildPreview.
func (*Mocker) SplashWithType ¶ added in v1.3.0
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) 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.GuildID, 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.