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
- 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) CreateUser(user *model.User) (*model.User, *model.AppError)
- func (m *API) DeleteChannel(channelId string) *model.AppError
- func (m *API) DeletePost(postId string) *model.AppError
- func (m *API) DeleteTeam(teamId 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(name, teamId string) (*model.Channel, *model.AppError)
- func (m *API) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
- func (m *API) GetDirectChannel(userId1, 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) GetTeam(teamId string) (*model.Team, *model.AppError)
- func (m *API) GetTeamByName(name string) (*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) KeyValueStore() plugin.KeyValueStore
- func (m *API) LoadPluginConfiguration(dest interface{}) error
- func (m *API) RegisterCommand(command *model.Command) error
- func (m *API) UnregisterCommand(teamId, trigger string) error
- func (m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *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) UpdateUser(user *model.User) (*model.User, *model.AppError)
- type Hooks
- type KeyValueStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { mock.Mock Store *KeyValueStore }
func (*API) CreateChannel ¶
func (*API) GetChannel ¶
func (*API) GetChannelByName ¶
func (*API) GetChannelMember ¶
func (*API) GetDirectChannel ¶
func (*API) GetGroupChannel ¶
func (*API) GetUserByEmail ¶
func (*API) GetUserByUsername ¶
func (*API) KeyValueStore ¶
func (m *API) KeyValueStore() plugin.KeyValueStore
func (*API) LoadPluginConfiguration ¶
func (*API) UnregisterCommand ¶
func (*API) UpdateChannel ¶
type Hooks ¶
func (*Hooks) ExecuteCommand ¶
func (m *Hooks) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
func (*Hooks) OnConfigurationChange ¶
func (*Hooks) OnDeactivate ¶
type KeyValueStore ¶
Click to show internal directories.
Click to hide internal directories.