Documentation ¶
Overview ¶
The plugintest package provides mocks that can be used to test plugins.
The mocks are created using testify's mock package: https://godoc.org/github.com/stretchr/testify/mock
If you need to import the mock package, you can import it with "github.com/mattermost/mattermost-server/plugin/plugintest/mock".
Example ¶
package main import ( "fmt" "io/ioutil" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin" "github.com/mattermost/mattermost-server/plugin/plugintest" ) type HelloUserPlugin struct { plugin.MattermostPlugin } func (p *HelloUserPlugin) ServeHTTP(context *plugin.Context, w http.ResponseWriter, r *http.Request) { userId := r.Header.Get("Mattermost-User-Id") user, err := p.API.GetUser(userId) if err != nil { w.WriteHeader(http.StatusBadRequest) p.API.LogError(err.Error()) return } fmt.Fprintf(w, "Welcome back, %s!", user.Username) } func main() { t := &testing.T{} user := &model.User{ Id: model.NewId(), Username: "billybob", } api := &plugintest.API{} api.On("GetUser", user.Id).Return(user, nil) defer api.AssertExpectations(t) p := &HelloUserPlugin{} p.SetAPI(api) w := httptest.NewRecorder() r := httptest.NewRequest("GET", "/", nil) r.Header.Add("Mattermost-User-Id", user.Id) p.ServeHTTP(&plugin.Context{}, w, r) body, err := ioutil.ReadAll(w.Result().Body) require.NoError(t, err) assert.Equal(t, "Welcome back, billybob!", string(body)) }
Output:
Index ¶
- type API
- func (_m *API) AddChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
- func (_m *API) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
- func (_m *API) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
- func (_m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError)
- func (_m *API) CreateTeam(team *model.Team) (*model.Team, *model.AppError)
- func (_m *API) CreateTeamMember(teamId string, userId string) (*model.TeamMember, *model.AppError)
- func (_m *API) CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)
- func (_m *API) CreateUser(user *model.User) (*model.User, *model.AppError)
- func (_m *API) DeleteChannel(channelId string) *model.AppError
- func (_m *API) DeleteChannelMember(channelId string, userId string) *model.AppError
- func (_m *API) DeletePost(postId string) *model.AppError
- func (_m *API) DeleteTeam(teamId string) *model.AppError
- func (_m *API) DeleteTeamMember(teamId string, userId string, requestorId string) *model.AppError
- func (_m *API) DeleteUser(userId string) *model.AppError
- func (_m *API) GetChannel(channelId string) (*model.Channel, *model.AppError)
- func (_m *API) GetChannelByName(teamId string, name string, includeDeleted bool) (*model.Channel, *model.AppError)
- func (_m *API) GetChannelByNameForTeamName(teamName string, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)
- func (_m *API) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
- func (_m *API) GetConfig() *model.Config
- func (_m *API) GetDirectChannel(userId1 string, userId2 string) (*model.Channel, *model.AppError)
- func (_m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
- func (_m *API) GetPost(postId string) (*model.Post, *model.AppError)
- func (_m *API) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
- func (_m *API) GetSession(sessionId string) (*model.Session, *model.AppError)
- func (_m *API) GetTeam(teamId string) (*model.Team, *model.AppError)
- func (_m *API) GetTeamByName(name string) (*model.Team, *model.AppError)
- func (_m *API) GetTeamMember(teamId string, userId string) (*model.TeamMember, *model.AppError)
- func (_m *API) GetTeamMembers(teamId string, offset int, limit int) ([]*model.TeamMember, *model.AppError)
- func (_m *API) GetTeams() ([]*model.Team, *model.AppError)
- func (_m *API) GetUser(userId string) (*model.User, *model.AppError)
- func (_m *API) GetUserByEmail(email string) (*model.User, *model.AppError)
- func (_m *API) GetUserByUsername(name string) (*model.User, *model.AppError)
- func (_m *API) GetUserStatus(userId string) (*model.Status, *model.AppError)
- func (_m *API) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
- func (_m *API) KVDelete(key string) *model.AppError
- func (_m *API) KVGet(key string) ([]byte, *model.AppError)
- func (_m *API) KVSet(key string, value []byte) *model.AppError
- func (_m *API) LoadPluginConfiguration(dest interface{}) error
- func (_m *API) LogDebug(msg string, keyValuePairs ...interface{})
- func (_m *API) LogError(msg string, keyValuePairs ...interface{})
- func (_m *API) LogInfo(msg string, keyValuePairs ...interface{})
- func (_m *API) LogWarn(msg string, keyValuePairs ...interface{})
- func (_m *API) PublishWebSocketEvent(event string, payload map[string]interface{}, ...)
- func (_m *API) RegisterCommand(command *model.Command) error
- func (_m *API) SaveConfig(config *model.Config) *model.AppError
- func (_m *API) SendEphemeralPost(userId string, post *model.Post) *model.Post
- func (_m *API) UnregisterCommand(teamId string, trigger string) error
- func (_m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
- func (_m *API) UpdateChannelMemberNotifications(channelId string, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
- func (_m *API) UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError)
- func (_m *API) UpdatePost(post *model.Post) (*model.Post, *model.AppError)
- func (_m *API) UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
- func (_m *API) UpdateTeamMemberRoles(teamId string, userId string, newRoles string) (*model.TeamMember, *model.AppError)
- func (_m *API) UpdateUser(user *model.User) (*model.User, *model.AppError)
- func (_m *API) UpdateUserStatus(userId string, status string) (*model.Status, *model.AppError)
- type Hooks
- func (_m *Hooks) ChannelHasBeenCreated(c *plugin.Context, channel *model.Channel)
- func (_m *Hooks) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
- func (_m *Hooks) FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string)
- func (_m *Hooks) Implemented() ([]string, error)
- func (_m *Hooks) MessageHasBeenPosted(c *plugin.Context, post *model.Post)
- func (_m *Hooks) MessageHasBeenUpdated(c *plugin.Context, newPost *model.Post, oldPost *model.Post)
- func (_m *Hooks) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string)
- func (_m *Hooks) MessageWillBeUpdated(c *plugin.Context, newPost *model.Post, oldPost *model.Post) (*model.Post, string)
- func (_m *Hooks) OnActivate() error
- func (_m *Hooks) OnConfigurationChange() error
- func (_m *Hooks) OnDeactivate() error
- func (_m *Hooks) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request)
- func (_m *Hooks) UserHasJoinedChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User)
- func (_m *Hooks) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User)
- func (_m *Hooks) UserHasLeftChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User)
- func (_m *Hooks) UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User)
- func (_m *Hooks) UserHasLoggedIn(c *plugin.Context, user *model.User)
- func (_m *Hooks) UserWillLogIn(c *plugin.Context, user *model.User) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
API is an autogenerated mock type for the API type
func (*API) AddChannelMember ¶
func (_m *API) AddChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
AddChannelMember provides a mock function with given fields: channelId, userId
func (*API) CopyFileInfos ¶
CopyFileInfos provides a mock function with given fields: userId, fileIds
func (*API) CreateChannel ¶
CreateChannel provides a mock function with given fields: channel
func (*API) CreatePost ¶
CreatePost provides a mock function with given fields: post
func (*API) CreateTeam ¶
CreateTeam provides a mock function with given fields: team
func (*API) CreateTeamMember ¶
CreateTeamMember provides a mock function with given fields: teamId, userId
func (*API) CreateTeamMembers ¶
func (_m *API) CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError)
CreateTeamMembers provides a mock function with given fields: teamId, userIds, requestorId
func (*API) CreateUser ¶
CreateUser provides a mock function with given fields: user
func (*API) DeleteChannel ¶
DeleteChannel provides a mock function with given fields: channelId
func (*API) DeleteChannelMember ¶
DeleteChannelMember provides a mock function with given fields: channelId, userId
func (*API) DeletePost ¶
DeletePost provides a mock function with given fields: postId
func (*API) DeleteTeam ¶
DeleteTeam provides a mock function with given fields: teamId
func (*API) DeleteTeamMember ¶
DeleteTeamMember provides a mock function with given fields: teamId, userId, requestorId
func (*API) DeleteUser ¶
DeleteUser provides a mock function with given fields: userId
func (*API) GetChannel ¶
GetChannel provides a mock function with given fields: channelId
func (*API) GetChannelByName ¶
func (_m *API) GetChannelByName(teamId string, name string, includeDeleted bool) (*model.Channel, *model.AppError)
GetChannelByName provides a mock function with given fields: teamId, name, includeDeleted
func (*API) GetChannelByNameForTeamName ¶
func (_m *API) GetChannelByNameForTeamName(teamName string, channelName string, includeDeleted bool) (*model.Channel, *model.AppError)
GetChannelByNameForTeamName provides a mock function with given fields: teamName, channelName, includeDeleted
func (*API) GetChannelMember ¶
func (_m *API) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
GetChannelMember provides a mock function with given fields: channelId, userId
func (*API) GetDirectChannel ¶
GetDirectChannel provides a mock function with given fields: userId1, userId2
func (*API) GetGroupChannel ¶
GetGroupChannel provides a mock function with given fields: userIds
func (*API) GetPublicChannelsForTeam ¶
func (_m *API) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsForTeam provides a mock function with given fields: teamId, offset, limit
func (*API) GetSession ¶
GetSession provides a mock function with given fields: sessionId
func (*API) GetTeamByName ¶
GetTeamByName provides a mock function with given fields: name
func (*API) GetTeamMember ¶
GetTeamMember provides a mock function with given fields: teamId, userId
func (*API) GetTeamMembers ¶
func (_m *API) GetTeamMembers(teamId string, offset int, limit int) ([]*model.TeamMember, *model.AppError)
GetTeamMembers provides a mock function with given fields: teamId, offset, limit
func (*API) GetUserByEmail ¶
GetUserByEmail provides a mock function with given fields: email
func (*API) GetUserByUsername ¶
GetUserByUsername provides a mock function with given fields: name
func (*API) GetUserStatus ¶
GetUserStatus provides a mock function with given fields: userId
func (*API) GetUserStatusesByIds ¶
GetUserStatusesByIds provides a mock function with given fields: userIds
func (*API) LoadPluginConfiguration ¶
LoadPluginConfiguration provides a mock function with given fields: dest
func (*API) PublishWebSocketEvent ¶
func (_m *API) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast)
PublishWebSocketEvent provides a mock function with given fields: event, payload, broadcast
func (*API) RegisterCommand ¶
RegisterCommand provides a mock function with given fields: command
func (*API) SaveConfig ¶
SaveConfig provides a mock function with given fields: config
func (*API) SendEphemeralPost ¶
SendEphemeralPost provides a mock function with given fields: userId, post
func (*API) UnregisterCommand ¶
UnregisterCommand provides a mock function with given fields: teamId, trigger
func (*API) UpdateChannel ¶
UpdateChannel provides a mock function with given fields: channel
func (*API) UpdateChannelMemberNotifications ¶
func (_m *API) UpdateChannelMemberNotifications(channelId string, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
UpdateChannelMemberNotifications provides a mock function with given fields: channelId, userId, notifications
func (*API) UpdateChannelMemberRoles ¶
func (_m *API) UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError)
UpdateChannelMemberRoles provides a mock function with given fields: channelId, userId, newRoles
func (*API) UpdatePost ¶
UpdatePost provides a mock function with given fields: post
func (*API) UpdateTeam ¶
UpdateTeam provides a mock function with given fields: team
func (*API) UpdateTeamMemberRoles ¶
func (_m *API) UpdateTeamMemberRoles(teamId string, userId string, newRoles string) (*model.TeamMember, *model.AppError)
UpdateTeamMemberRoles provides a mock function with given fields: teamId, userId, newRoles
func (*API) UpdateUser ¶
UpdateUser provides a mock function with given fields: user
type Hooks ¶
Hooks is an autogenerated mock type for the Hooks type
func (*Hooks) ChannelHasBeenCreated ¶
ChannelHasBeenCreated provides a mock function with given fields: c, channel
func (*Hooks) ExecuteCommand ¶
func (_m *Hooks) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
ExecuteCommand provides a mock function with given fields: c, args
func (*Hooks) FileWillBeUploaded ¶
func (_m *Hooks) FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string)
FileWillBeUploaded provides a mock function with given fields: c, info, file, output
func (*Hooks) Implemented ¶
Implemented provides a mock function with given fields:
func (*Hooks) MessageHasBeenPosted ¶
MessageHasBeenPosted provides a mock function with given fields: c, post
func (*Hooks) MessageHasBeenUpdated ¶
MessageHasBeenUpdated provides a mock function with given fields: c, newPost, oldPost
func (*Hooks) MessageWillBePosted ¶
MessageWillBePosted provides a mock function with given fields: c, post
func (*Hooks) MessageWillBeUpdated ¶
func (_m *Hooks) MessageWillBeUpdated(c *plugin.Context, newPost *model.Post, oldPost *model.Post) (*model.Post, string)
MessageWillBeUpdated provides a mock function with given fields: c, newPost, oldPost
func (*Hooks) OnActivate ¶
OnActivate provides a mock function with given fields:
func (*Hooks) OnConfigurationChange ¶
OnConfigurationChange provides a mock function with given fields:
func (*Hooks) OnDeactivate ¶
OnDeactivate provides a mock function with given fields:
func (*Hooks) UserHasJoinedChannel ¶
func (_m *Hooks) UserHasJoinedChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User)
UserHasJoinedChannel provides a mock function with given fields: c, channelMember, actor
func (*Hooks) UserHasJoinedTeam ¶
func (_m *Hooks) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User)
UserHasJoinedTeam provides a mock function with given fields: c, teamMember, actor
func (*Hooks) UserHasLeftChannel ¶
func (_m *Hooks) UserHasLeftChannel(c *plugin.Context, channelMember *model.ChannelMember, actor *model.User)
UserHasLeftChannel provides a mock function with given fields: c, channelMember, actor
func (*Hooks) UserHasLeftTeam ¶
func (_m *Hooks) UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User)
UserHasLeftTeam provides a mock function with given fields: c, teamMember, actor
func (*Hooks) UserHasLoggedIn ¶
UserHasLoggedIn provides a mock function with given fields: c, user