dismock

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2020 License: MIT Imports: 27 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is a named handler for mocked endpoints.

type MockFunc

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

MockFunc is the function used to create a mock.

type Mocker

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

Mocker handles the mocking of arikawa's API calls.

func New

func New(t *testing.T) *Mocker

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

func NewSession

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

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

func NewState

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

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

func (*Mocker) Ack

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

Ack mocks a Ack request.

func (*Mocker) AddMember

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

AddMember mocks a AddMember request.

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

func (*Mocker) AddRecipient

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

AddRecipient mocks a AddRecipient request.

func (*Mocker) AddRole

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

AddRole mocks a AddRole request.

func (*Mocker) AttachIntegration

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

AttachIntegration mocks a AttachIntegration request.

func (*Mocker) AuditLog

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

AuditLog mocks a AuditLog request.

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) Ban

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

Ban mocks a Ban request.

func (*Mocker) Banner added in v1.3.0

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

Banner mocks a Banner request.

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

func (*Mocker) BannerWithType 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) Bans

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

Bans mocks a Bans request.

This method will sanitize Bans.User.ID.

func (*Mocker) ChangeOwnNickname

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

ChangeOwnNickname mocks a ChangeOwnNickname request.

func (*Mocker) Channel

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

Channel mocks a Channel request.

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

This method will sanitize Channel.ID.

func (*Mocker) ChannelIcon added in v1.3.0

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

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

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

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

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

ChannelWebhooks mocks a ChannelWebhooks request.

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

func (*Mocker) Channels

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

Channels mocks a channels request.

This method will sanitize Channel.ID.

func (*Mocker) Clone added in v1.2.0

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

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

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

func (*Mocker) CloneSession

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

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

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

func (*Mocker) CloneState

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

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

Creating a clone will automatically close the current server.

func (*Mocker) Close

func (m *Mocker) Close()

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

func (*Mocker) CreateChannel

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

CreateChannel mocks a CreateChannel request.

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

This method will sanitize Channel.ID.

func (*Mocker) CreateEmoji

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

CreateEmoji mocks a CreateEmoji request.

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

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

func (*Mocker) CreateGuild

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

CreateGuild mocks a CreateGuild request.

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

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

CreatePrivateChannel mocks a CreatePrivateChannel request.

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

func (*Mocker) CreateRole

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

CreateRole mocks a CreateRole request.

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

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

DeleteAllReactions mocks a DeleteAllReactions request.

func (*Mocker) DeleteChannel

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

DeleteChannel mocks a DeleteChannel request.

func (*Mocker) DeleteChannelPermission

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

DeleteChannelPermission mocks a DeleteChannelPermission request.

func (*Mocker) DeleteEmoji

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

DeleteEmoji mocks a DeleteEmoji request.

func (*Mocker) DeleteGuild

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

DeleteGuild mocks a DeleteGuild request.

func (*Mocker) DeleteInvite

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

DeleteInvite mocks a DeleteInvite request.

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

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

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

DeleteMessage mocks a DeleteMessage request.

func (*Mocker) DeleteMessages

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

DeleteMessages mocks a DeleteMessages request.

func (*Mocker) DeleteReactions

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

DeleteReactions mocks a DeleteReactions request.

func (*Mocker) DeleteRole

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

DeleteRole mocks a DeleteRole request.

func (*Mocker) DeleteUserReaction

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

DeleteUserReaction mocks a DeleteUserReaction request.

func (*Mocker) DeleteWebhook

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

DeleteWebhook mocks a DeleteWebhook request.

func (*Mocker) DeleteWebhookWithToken

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

DeleteWebhookWithToken mocks a DeleteWebhookWithToken request.

func (*Mocker) DiscoverySplash added in v1.3.0

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

DiscoverySplash mocks a DiscoverySplash request.

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

func (*Mocker) DiscoverySplashWithType 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

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

EditEmbed mocks a EditEmbed request.

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

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

func (*Mocker) EditMessage

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

EditMessage mocks a EditMessage request.

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

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

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

EditText mocks a EditText request.

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

This method will sanitize Message.Author.ID.

func (*Mocker) Emoji

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

Emoji mocks a Emoji request.

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

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

func (*Mocker) EmojiPicture added in v1.3.0

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

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

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

Emojis mocks a Emojis request.

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

func (*Mocker) Error

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

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

func (*Mocker) Eval

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

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

GetBan mocks a GetBan request.

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

func (*Mocker) Guild

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

Guild mocks a Guild request.

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

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

func (*Mocker) GuildIcon added in v1.3.0

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

GuildIcon mocks a GuildIcon request.

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

func (*Mocker) GuildIconWithType 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

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

GuildImage mocks a GuildImage request.

func (*Mocker) GuildInvites

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

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

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

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

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

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

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

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

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

Guilds mocks a Guilds request.

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

func (*Mocker) GuildsAfter

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

GuildsAfter mocks a GuildsAfter request.

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

func (*Mocker) GuildsBefore

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

GuildsBefore mocks a GuildsBefore request.

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

func (*Mocker) 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

func (m *Mocker) Invite(i discord.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

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

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) Kick

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

Kick mocks a Kick request.

func (*Mocker) LeaveGuild

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

LeaveGuild mocks a LeaveGuild request.

func (*Mocker) Login

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

Login mocks a Login request.

func (*Mocker) Me

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

Me mocks a Me request.

This method will sanitize User.ID.

func (*Mocker) Member

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

Member mocks a Member request.

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

func (*Mocker) Members

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

Members mocks a Members request.

This method will sanitize Member.User.ID.

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

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

Message mocks a Message request.

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

This method will sanitize Message.Author.ID.

func (*Mocker) Messages

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

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

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

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

Trailing slashes ('/') will be removed.

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

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

func (*Mocker) MockAPI

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

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

Trailing slashes ('/') will be removed.

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

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

func (*Mocker) ModifyChannel

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

ModifyChannel mocks a ModifyChannel request.

func (*Mocker) ModifyEmoji

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

ModifyEmoji mocks a ModifyEmoji request.

func (*Mocker) ModifyGuild

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

ModifyGuild mocks a ModifyGuild request.

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

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

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

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) MoveRole

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

MoveRole mocks a MoveRole request.

This method will sanitize Roles.ID.

func (*Mocker) PinMessage

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

PinMessage mocks a PinMessage request.

func (*Mocker) PinnedMessages

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

PinnedMessages mocks a PinnedMessages request.

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

func (*Mocker) PrivateChannels

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

PrivateChannels mocks a PrivateChannels request.

This method will sanitize Channels.ID.

func (*Mocker) Prune

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

Prune mocks a Prune request.

func (*Mocker) PruneCount

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

PruneCount mocks a PruneCount request.

func (*Mocker) React

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

React mocks a React 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

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

RemoveRecipient mocks a RemoveRecipient request.

func (*Mocker) RemoveRole

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

RemoveRole mocks a RemoveRole request.

func (*Mocker) Roles

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

Roles mocks a Roles request.

This method will sanitize Roles.ID.

func (*Mocker) SendEmbed

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

SendEmbed mocks a SendEmbed request.

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

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

func (*Mocker) SendMessage

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

SendMessage mocks a SendMessage request.

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

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

func (*Mocker) SendMessageComplex

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

SendMessageComplex mocks a SendMessageComplex request.

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

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

func (*Mocker) SendText

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

SendText mocks a SendText request.

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

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

func (*Mocker) Splash added in v1.3.0

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

Splash mocks a Splash request.

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

func (*Mocker) SplashWithType 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) Typing

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

Typing mocks a Typing request.

func (*Mocker) Unban

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

Unban mocks a Unban request.

func (*Mocker) UnpinMessage added in v1.1.0

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

UnpinMessage mocks a UnpinMessage request.

func (*Mocker) Unreact

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

Unreact mocks a Unreact request.

func (*Mocker) User

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

User mocks a User request.

The ID field of the passed User must be set.

func (*Mocker) UserConnections

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

UserConnections mocks a UserConnections request.

func (*Mocker) VoiceRegionsGuild

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

VoiceRegionsGuild mocks a VoiceRegionsGuild request.

func (*Mocker) Webhook

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

Webhook mocks a Webhook request.

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

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

func (*Mocker) WebhookWithToken

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

WebhookWithToken mocks a WebhookWithToken request.

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

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

Notes

Bugs

  • Due to an inconvenient behavior of json.Unmarshal, where on JSON null the the MarshalJSON method doesn't get called, there is no way to differentiate between option.NullX and omitted.

Jump to

Keyboard shortcuts

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