diff options
author | Chris <ccbrown112@gmail.com> | 2017-11-07 13:12:38 -0600 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-11-07 11:12:38 -0800 |
commit | 1d1998c6686e969a6d3fdfcdfa0592ea5945bb9c (patch) | |
tree | db090ad6df64e4cd555fdfe3c0ffebd3e307c8f0 /plugin/example_test.go | |
parent | 61db2ff59bc5146a85a8275a4ce231eb1d5e03f1 (diff) | |
download | chat-1d1998c6686e969a6d3fdfcdfa0592ea5945bb9c.tar.gz chat-1d1998c6686e969a6d3fdfcdfa0592ea5945bb9c.tar.bz2 chat-1d1998c6686e969a6d3fdfcdfa0592ea5945bb9c.zip |
add a few docs for plugin testing (#7798)
* add a few docs for plugin testing
* fix typo
Diffstat (limited to 'plugin/example_test.go')
-rw-r--r-- | plugin/example_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/plugin/example_test.go b/plugin/example_test.go new file mode 100644 index 000000000..e6ae3c2ea --- /dev/null +++ b/plugin/example_test.go @@ -0,0 +1,35 @@ +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)) +} |