plugintest

package
v4.9.1-rc1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: AGPL-3.0, Apache-2.0 Imports: 4 Imported by: 0

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

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 (m *API) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

func (*API) CreatePost

func (m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError)

func (*API) CreateTeam

func (m *API) CreateTeam(team *model.Team) (*model.Team, *model.AppError)

func (*API) CreateUser

func (m *API) CreateUser(user *model.User) (*model.User, *model.AppError)

func (*API) DeleteChannel

func (m *API) DeleteChannel(channelId string) *model.AppError

func (*API) DeletePost

func (m *API) DeletePost(postId string) *model.AppError

func (*API) DeleteTeam

func (m *API) DeleteTeam(teamId string) *model.AppError

func (*API) DeleteUser

func (m *API) DeleteUser(userId string) *model.AppError

func (*API) GetChannel

func (m *API) GetChannel(channelId string) (*model.Channel, *model.AppError)

func (*API) GetChannelByName

func (m *API) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError)

func (*API) GetChannelMember

func (m *API) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

func (*API) GetDirectChannel

func (m *API) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)

func (*API) GetGroupChannel

func (m *API) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)

func (*API) GetPost

func (m *API) GetPost(postId string) (*model.Post, *model.AppError)

func (*API) GetTeam

func (m *API) GetTeam(teamId string) (*model.Team, *model.AppError)

func (*API) GetTeamByName

func (m *API) GetTeamByName(name string) (*model.Team, *model.AppError)

func (*API) GetUser

func (m *API) GetUser(userId string) (*model.User, *model.AppError)

func (*API) GetUserByEmail

func (m *API) GetUserByEmail(email string) (*model.User, *model.AppError)

func (*API) GetUserByUsername

func (m *API) GetUserByUsername(name string) (*model.User, *model.AppError)

func (*API) KeyValueStore

func (m *API) KeyValueStore() plugin.KeyValueStore

func (*API) LoadPluginConfiguration

func (m *API) LoadPluginConfiguration(dest interface{}) error

func (*API) RegisterCommand

func (m *API) RegisterCommand(command *model.Command) error

func (*API) UnregisterCommand

func (m *API) UnregisterCommand(teamId, trigger string) error

func (*API) UpdateChannel

func (m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

func (*API) UpdatePost

func (m *API) UpdatePost(post *model.Post) (*model.Post, *model.AppError)

func (*API) UpdateTeam

func (m *API) UpdateTeam(team *model.Team) (*model.Team, *model.AppError)

func (*API) UpdateUser

func (m *API) UpdateUser(user *model.User) (*model.User, *model.AppError)

type Hooks

type Hooks struct {
	mock.Mock
}

func (*Hooks) ExecuteCommand

func (m *Hooks) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)

func (*Hooks) OnActivate

func (m *Hooks) OnActivate(api plugin.API) error

func (*Hooks) OnConfigurationChange

func (m *Hooks) OnConfigurationChange() error

func (*Hooks) OnDeactivate

func (m *Hooks) OnDeactivate() error

func (*Hooks) ServeHTTP

func (m *Hooks) ServeHTTP(w http.ResponseWriter, r *http.Request)

type KeyValueStore

type KeyValueStore struct {
	mock.Mock
}

func (*KeyValueStore) Delete

func (m *KeyValueStore) Delete(key string) *model.AppError

func (*KeyValueStore) Get

func (m *KeyValueStore) Get(key string) ([]byte, *model.AppError)

func (*KeyValueStore) Set

func (m *KeyValueStore) Set(key string, value []byte) *model.AppError

Directories

Path Synopsis
This package provides aliases for the contents of "github.com/stretchr/testify/mock".
This package provides aliases for the contents of "github.com/stretchr/testify/mock".

Jump to

Keyboard shortcuts

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