Documentation ¶
Overview ¶
The plugintest package provides mocks that can be used to test plugins. For example, to test the ServeHTTP method of the plugin package's HelloUser example:
package plugin_test import ( "io/ioutil" "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/plugintest" ) func TestHelloUserPlugin(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.OnActivate(api) w := httptest.NewRecorder() r := httptest.NewRequest("GET", "/", nil) r.Header.Add("Mattermost-User-Id", user.Id) p.ServeHTTP(w, r) body, err := ioutil.ReadAll(w.Result().Body) require.NoError(t, err) assert.Equal(t, "Welcome back, billybob!", string(body)) }
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".
Index ¶
- type API
- type APIMOCKINTERNAL
- func (_m *APIMOCKINTERNAL) AddChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
- func (_m *APIMOCKINTERNAL) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) CreatePost(post *model.Post) (*model.Post, *model.AppError)
- func (_m *APIMOCKINTERNAL) CreateTeam(team *model.Team) (*model.Team, *model.AppError)
- func (_m *APIMOCKINTERNAL) CreateUser(user *model.User) (*model.User, *model.AppError)
- func (_m *APIMOCKINTERNAL) DeleteChannel(channelId string) *model.AppError
- func (_m *APIMOCKINTERNAL) DeleteChannelMember(channelId string, userId string) *model.AppError
- func (_m *APIMOCKINTERNAL) DeletePost(postId string) *model.AppError
- func (_m *APIMOCKINTERNAL) DeleteTeam(teamId string) *model.AppError
- func (_m *APIMOCKINTERNAL) DeleteUser(userId string) *model.AppError
- func (_m *APIMOCKINTERNAL) GetChannel(channelId string) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetChannelByName(name string, teamId string) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetDirectChannel(userId1 string, userId2 string) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetPost(postId string) (*model.Post, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetTeam(teamId string) (*model.Team, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetTeamByName(name string) (*model.Team, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetUser(userId string) (*model.User, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetUserByEmail(email string) (*model.User, *model.AppError)
- func (_m *APIMOCKINTERNAL) GetUserByUsername(name string) (*model.User, *model.AppError)
- func (_m *APIMOCKINTERNAL) KeyValueStore() plugin.KeyValueStore
- func (_m *APIMOCKINTERNAL) LoadPluginConfiguration(dest interface{}) error
- func (_m *APIMOCKINTERNAL) RegisterCommand(command *model.Command) error
- func (_m *APIMOCKINTERNAL) UnregisterCommand(teamId string, trigger string) error
- func (_m *APIMOCKINTERNAL) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
- func (_m *APIMOCKINTERNAL) UpdateChannelMemberNotifications(channelId string, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError)
- func (_m *APIMOCKINTERNAL) UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError)
- func (_m *APIMOCKINTERNAL) UpdatePost(post *model.Post) (*model.Post, *model.AppError)
- func (_m *APIMOCKINTERNAL) UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
- func (_m *APIMOCKINTERNAL) UpdateUser(user *model.User) (*model.User, *model.AppError)
- type Hooks
- func (_m *Hooks) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
- func (_m *Hooks) MessageHasBeenPosted(post *model.Post)
- func (_m *Hooks) MessageHasBeenUpdated(newPost *model.Post, oldPost *model.Post)
- func (_m *Hooks) MessageWillBePosted(post *model.Post) (*model.Post, string)
- func (_m *Hooks) MessageWillBeUpdated(newPost *model.Post, oldPost *model.Post) (*model.Post, string)
- func (_m *Hooks) OnActivate(_a0 plugin.API) error
- func (_m *Hooks) OnConfigurationChange() error
- func (_m *Hooks) OnDeactivate() error
- func (_m *Hooks) ServeHTTP(_a0 http.ResponseWriter, _a1 *http.Request)
- type KeyValueStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { APIMOCKINTERNAL Store *KeyValueStore }
func (*API) KeyValueStore ¶
func (m *API) KeyValueStore() plugin.KeyValueStore
type APIMOCKINTERNAL ¶
APIMOCKINTERNAL is an autogenerated mock type for the APIMOCKINTERNAL type
func (*APIMOCKINTERNAL) AddChannelMember ¶
func (_m *APIMOCKINTERNAL) AddChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
AddChannelMember provides a mock function with given fields: channelId, userId
func (*APIMOCKINTERNAL) CreateChannel ¶
CreateChannel provides a mock function with given fields: channel
func (*APIMOCKINTERNAL) CreatePost ¶
CreatePost provides a mock function with given fields: post
func (*APIMOCKINTERNAL) CreateTeam ¶
CreateTeam provides a mock function with given fields: team
func (*APIMOCKINTERNAL) CreateUser ¶
CreateUser provides a mock function with given fields: user
func (*APIMOCKINTERNAL) DeleteChannel ¶
func (_m *APIMOCKINTERNAL) DeleteChannel(channelId string) *model.AppError
DeleteChannel provides a mock function with given fields: channelId
func (*APIMOCKINTERNAL) DeleteChannelMember ¶
func (_m *APIMOCKINTERNAL) DeleteChannelMember(channelId string, userId string) *model.AppError
DeleteChannelMember provides a mock function with given fields: channelId, userId
func (*APIMOCKINTERNAL) DeletePost ¶
func (_m *APIMOCKINTERNAL) DeletePost(postId string) *model.AppError
DeletePost provides a mock function with given fields: postId
func (*APIMOCKINTERNAL) DeleteTeam ¶
func (_m *APIMOCKINTERNAL) DeleteTeam(teamId string) *model.AppError
DeleteTeam provides a mock function with given fields: teamId
func (*APIMOCKINTERNAL) DeleteUser ¶
func (_m *APIMOCKINTERNAL) DeleteUser(userId string) *model.AppError
DeleteUser provides a mock function with given fields: userId
func (*APIMOCKINTERNAL) GetChannel ¶
GetChannel provides a mock function with given fields: channelId
func (*APIMOCKINTERNAL) GetChannelByName ¶
func (_m *APIMOCKINTERNAL) GetChannelByName(name string, teamId string) (*model.Channel, *model.AppError)
GetChannelByName provides a mock function with given fields: name, teamId
func (*APIMOCKINTERNAL) GetChannelMember ¶
func (_m *APIMOCKINTERNAL) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
GetChannelMember provides a mock function with given fields: channelId, userId
func (*APIMOCKINTERNAL) GetDirectChannel ¶
func (_m *APIMOCKINTERNAL) GetDirectChannel(userId1 string, userId2 string) (*model.Channel, *model.AppError)
GetDirectChannel provides a mock function with given fields: userId1, userId2
func (*APIMOCKINTERNAL) GetGroupChannel ¶
GetGroupChannel provides a mock function with given fields: userIds
func (*APIMOCKINTERNAL) GetTeamByName ¶
GetTeamByName provides a mock function with given fields: name
func (*APIMOCKINTERNAL) GetUserByEmail ¶
GetUserByEmail provides a mock function with given fields: email
func (*APIMOCKINTERNAL) GetUserByUsername ¶
GetUserByUsername provides a mock function with given fields: name
func (*APIMOCKINTERNAL) KeyValueStore ¶
func (_m *APIMOCKINTERNAL) KeyValueStore() plugin.KeyValueStore
KeyValueStore provides a mock function with given fields:
func (*APIMOCKINTERNAL) LoadPluginConfiguration ¶
func (_m *APIMOCKINTERNAL) LoadPluginConfiguration(dest interface{}) error
LoadPluginConfiguration provides a mock function with given fields: dest
func (*APIMOCKINTERNAL) RegisterCommand ¶
func (_m *APIMOCKINTERNAL) RegisterCommand(command *model.Command) error
RegisterCommand provides a mock function with given fields: command
func (*APIMOCKINTERNAL) UnregisterCommand ¶
func (_m *APIMOCKINTERNAL) UnregisterCommand(teamId string, trigger string) error
UnregisterCommand provides a mock function with given fields: teamId, trigger
func (*APIMOCKINTERNAL) UpdateChannel ¶
UpdateChannel provides a mock function with given fields: channel
func (*APIMOCKINTERNAL) UpdateChannelMemberNotifications ¶
func (_m *APIMOCKINTERNAL) 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 (*APIMOCKINTERNAL) UpdateChannelMemberRoles ¶
func (_m *APIMOCKINTERNAL) UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError)
UpdateChannelMemberRoles provides a mock function with given fields: channelId, userId, newRoles
func (*APIMOCKINTERNAL) UpdatePost ¶
UpdatePost provides a mock function with given fields: post
func (*APIMOCKINTERNAL) UpdateTeam ¶
UpdateTeam provides a mock function with given fields: team
func (*APIMOCKINTERNAL) UpdateUser ¶
UpdateUser provides a mock function with given fields: user
type Hooks ¶
Hooks is an autogenerated mock type for the Hooks type
func (*Hooks) ExecuteCommand ¶
func (_m *Hooks) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
ExecuteCommand provides a mock function with given fields: args
func (*Hooks) MessageHasBeenPosted ¶
MessageHasBeenPosted provides a mock function with given fields: post
func (*Hooks) MessageHasBeenUpdated ¶
MessageHasBeenUpdated provides a mock function with given fields: newPost, oldPost
func (*Hooks) MessageWillBePosted ¶
MessageWillBePosted provides a mock function with given fields: post
func (*Hooks) MessageWillBeUpdated ¶
func (_m *Hooks) MessageWillBeUpdated(newPost *model.Post, oldPost *model.Post) (*model.Post, string)
MessageWillBeUpdated provides a mock function with given fields: newPost, oldPost
func (*Hooks) OnActivate ¶
OnActivate provides a mock function with given fields: _a0
func (*Hooks) OnConfigurationChange ¶
OnConfigurationChange provides a mock function with given fields:
func (*Hooks) OnDeactivate ¶
OnDeactivate provides a mock function with given fields:
type KeyValueStore ¶
KeyValueStore is an autogenerated mock type for the KeyValueStore type
func (*KeyValueStore) Delete ¶
func (_m *KeyValueStore) Delete(key string) *model.AppError
Delete provides a mock function with given fields: key