github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/plugintest/plugintest.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 // The plugintest package provides mocks that can be used to test plugins. For example, to test the 5 // ServeHTTP method of the plugin package's HelloUser example: 6 // 7 // package plugin_test 8 // 9 // import ( 10 // "io/ioutil" 11 // "net/http/httptest" 12 // "testing" 13 // 14 // "github.com/stretchr/testify/assert" 15 // "github.com/stretchr/testify/require" 16 // 17 // "github.com/mattermost/mattermost-server/model" 18 // "github.com/mattermost/mattermost-server/plugin/plugintest" 19 // ) 20 // 21 // func TestHelloUserPlugin(t *testing.T) { 22 // user := &model.User{ 23 // Id: model.NewId(), 24 // Username: "billybob", 25 // } 26 // 27 // api := &plugintest.API{} 28 // api.On("GetUser", user.Id).Return(user, nil) 29 // defer api.AssertExpectations(t) 30 // 31 // p := &HelloUserPlugin{} 32 // p.OnActivate(api) 33 // 34 // w := httptest.NewRecorder() 35 // r := httptest.NewRequest("GET", "/", nil) 36 // r.Header.Add("Mattermost-User-Id", user.Id) 37 // p.ServeHTTP(w, r) 38 // body, err := ioutil.ReadAll(w.Result().Body) 39 // require.NoError(t, err) 40 // assert.Equal(t, "Welcome back, billybob!", string(body)) 41 // } 42 // 43 // The mocks are created using testify's mock package: 44 // https://godoc.org/github.com/stretchr/testify/mock 45 // 46 // If you need to import the mock package, you can import it with 47 // "github.com/mattermost/mattermost-server/plugin/plugintest/mock". 48 package plugintest