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 ¶
- 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 discord.APIEmoji)
- 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()deprecated
- func (m *Mocker) ExecuteWebhook(webhookID discord.WebhookID, token string, d webhook.ExecuteData)
- func (m *Mocker) ExecuteWebhookAndWait(webhookID discord.WebhookID, token string, d webhook.ExecuteData, ...)
- 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) GuildInvites(guildID discord.GuildID, invites []discord.Invite)
- func (m *Mocker) GuildPreview(p discord.GuildPreview)
- func (m *Mocker) GuildVanityInvite(guildID discord.GuildID, i discord.Invite)
- func (m *Mocker) GuildWebhooks(guildID discord.GuildID, webhooks []discord.Webhook)
- func (m *Mocker) GuildWidget(guildID discord.GuildID, widget discord.GuildWidget)
- func (m *Mocker) GuildWidgetImage(guildID discord.GuildID, style api.GuildWidgetImageStyle, img io.Reader)
- func (m *Mocker) GuildWidgetSettings(guildID discord.GuildID, s discord.GuildWidgetSettings)
- 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) HTTPClient() *httputil.Client
- 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, ...)
- 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 discord.APIEmoji)
- 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 discord.APIEmoji)
- 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 // 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) Banner ¶
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) 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.
func (*Mocker) ChannelIcon ¶
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 ¶
ChannelInvites mocks a ChannelInvites request.
func (*Mocker) ChannelWebhooks ¶
ChannelWebhooks mocks a ChannelWebhooks request.
func (*Mocker) Clone ¶
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.
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.
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 ¶
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.
func (*Mocker) CreateWebhook ¶
func (m *Mocker) CreateWebhook(d api.CreateWebhookData, wh discord.Webhook)
CreateWebhook mocks a CreateWebhook request.
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.
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 discord.APIEmoji)
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 discord.APIEmoji, )
DeleteUserReaction mocks a DeleteUserReaction request.
func (*Mocker) DeleteWebhook ¶
DeleteWebhook mocks a DeleteWebhook request.
func (*Mocker) DeleteWebhookWithToken ¶
DeleteWebhookWithToken mocks a DeleteWebhookWithToken request.
func (*Mocker) DiscoverySplash ¶
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 ¶
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 ¶
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 ¶
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 ¶
Emoji mocks a Emoji request.
The ID field of the passed discord.Emoji is required.
func (*Mocker) EmojiPicture ¶
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) 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 ¶
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 ¶
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.
func (*Mocker) GuildIcon ¶
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 ¶
GuildInvites mocks a GuildInvites request.
func (*Mocker) GuildPreview ¶
func (m *Mocker) GuildPreview(p discord.GuildPreview)
GuildPreview mocks a GuildPreview request.
func (*Mocker) GuildVanityInvite ¶
GuildVanityURL mocks a GuildVanityURL request.
func (*Mocker) GuildWebhooks ¶
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 ¶
GuildWithCount mocks a GuildWithCount request.
The ID field of the passed discord.Guild must be set.
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) HTTPClient ¶
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 ¶
Invite mocks a Invite request.
The Code field of the passed discord.Invite must be set.
func (*Mocker) InviteWithCounts ¶
InviteWithCounts mocks a InviteWithCounts request.
The Code field of the passed discord.Invite must be set.
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.
func (*Mocker) Message ¶
Message mocks a Message request.
The ID field and the ChannelID field of the passed discord.Message must be set.
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 ¶
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.
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 ¶
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) PinMessage ¶
PinMessage mocks a PinMessage request.
func (*Mocker) PinnedMessages ¶
PinnedMessages mocks a PinnedMessages request.
func (*Mocker) PrivateChannels ¶
PrivateChannels mocks a PrivateChannels request.
func (*Mocker) PruneCount ¶
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 ¶
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.
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.
func (*Mocker) SendText ¶
SendText mocks a SendText request.
The ChannelID field and the Content field of the passed discord.Message must be set.
func (*Mocker) Splash ¶
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) UnpinMessage ¶
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) 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.
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 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.