plugintest

package
v5.0.2-rc1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 12, 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 {
	APIMOCKINTERNAL
	Store *KeyValueStore
}

func (*API) KeyValueStore

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

type APIMOCKINTERNAL

type APIMOCKINTERNAL struct {
	mock.Mock
}

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

func (_m *APIMOCKINTERNAL) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

CreateChannel provides a mock function with given fields: channel

func (*APIMOCKINTERNAL) CreatePost

func (_m *APIMOCKINTERNAL) CreatePost(post *model.Post) (*model.Post, *model.AppError)

CreatePost provides a mock function with given fields: post

func (*APIMOCKINTERNAL) CreateTeam

func (_m *APIMOCKINTERNAL) CreateTeam(team *model.Team) (*model.Team, *model.AppError)

CreateTeam provides a mock function with given fields: team

func (*APIMOCKINTERNAL) CreateUser

func (_m *APIMOCKINTERNAL) CreateUser(user *model.User) (*model.User, *model.AppError)

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

func (_m *APIMOCKINTERNAL) GetChannel(channelId string) (*model.Channel, *model.AppError)

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

func (_m *APIMOCKINTERNAL) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)

GetGroupChannel provides a mock function with given fields: userIds

func (*APIMOCKINTERNAL) GetPost

func (_m *APIMOCKINTERNAL) GetPost(postId string) (*model.Post, *model.AppError)

GetPost provides a mock function with given fields: postId

func (*APIMOCKINTERNAL) GetTeam

func (_m *APIMOCKINTERNAL) GetTeam(teamId string) (*model.Team, *model.AppError)

GetTeam provides a mock function with given fields: teamId

func (*APIMOCKINTERNAL) GetTeamByName

func (_m *APIMOCKINTERNAL) GetTeamByName(name string) (*model.Team, *model.AppError)

GetTeamByName provides a mock function with given fields: name

func (*APIMOCKINTERNAL) GetUser

func (_m *APIMOCKINTERNAL) GetUser(userId string) (*model.User, *model.AppError)

GetUser provides a mock function with given fields: userId

func (*APIMOCKINTERNAL) GetUserByEmail

func (_m *APIMOCKINTERNAL) GetUserByEmail(email string) (*model.User, *model.AppError)

GetUserByEmail provides a mock function with given fields: email

func (*APIMOCKINTERNAL) GetUserByUsername

func (_m *APIMOCKINTERNAL) GetUserByUsername(name string) (*model.User, *model.AppError)

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

func (_m *APIMOCKINTERNAL) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)

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

func (_m *APIMOCKINTERNAL) UpdatePost(post *model.Post) (*model.Post, *model.AppError)

UpdatePost provides a mock function with given fields: post

func (*APIMOCKINTERNAL) UpdateTeam

func (_m *APIMOCKINTERNAL) UpdateTeam(team *model.Team) (*model.Team, *model.AppError)

UpdateTeam provides a mock function with given fields: team

func (*APIMOCKINTERNAL) UpdateUser

func (_m *APIMOCKINTERNAL) UpdateUser(user *model.User) (*model.User, *model.AppError)

UpdateUser provides a mock function with given fields: user

type Hooks

type Hooks struct {
	mock.Mock
}

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

func (_m *Hooks) MessageHasBeenPosted(post *model.Post)

MessageHasBeenPosted provides a mock function with given fields: post

func (*Hooks) MessageHasBeenUpdated

func (_m *Hooks) MessageHasBeenUpdated(newPost *model.Post, oldPost *model.Post)

MessageHasBeenUpdated provides a mock function with given fields: newPost, oldPost

func (*Hooks) MessageWillBePosted

func (_m *Hooks) MessageWillBePosted(post *model.Post) (*model.Post, string)

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

func (_m *Hooks) OnActivate(_a0 plugin.API) error

OnActivate provides a mock function with given fields: _a0

func (*Hooks) OnConfigurationChange

func (_m *Hooks) OnConfigurationChange() error

OnConfigurationChange provides a mock function with given fields:

func (*Hooks) OnDeactivate

func (_m *Hooks) OnDeactivate() error

OnDeactivate provides a mock function with given fields:

func (*Hooks) ServeHTTP

func (_m *Hooks) ServeHTTP(_a0 http.ResponseWriter, _a1 *http.Request)

ServeHTTP provides a mock function with given fields: _a0, _a1

type KeyValueStore

type KeyValueStore struct {
	mock.Mock
}

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

func (*KeyValueStore) Get

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

Get provides a mock function with given fields: key

func (*KeyValueStore) Set

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

Set provides a mock function with given fields: key, value

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