github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/example_test.go (about) 1 package plugin_test 2 3 import ( 4 "io/ioutil" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/mattermost/mattermost-server/model" 12 "github.com/mattermost/mattermost-server/plugin/plugintest" 13 ) 14 15 func TestHelloUserPlugin(t *testing.T) { 16 user := &model.User{ 17 Id: model.NewId(), 18 Username: "billybob", 19 } 20 21 api := &plugintest.API{} 22 api.On("GetUser", user.Id).Return(user, nil) 23 defer api.AssertExpectations(t) 24 25 p := &HelloUserPlugin{} 26 p.OnActivate(api) 27 28 w := httptest.NewRecorder() 29 r := httptest.NewRequest("GET", "/", nil) 30 r.Header.Add("Mattermost-User-Id", user.Id) 31 p.ServeHTTP(w, r) 32 body, err := ioutil.ReadAll(w.Result().Body) 33 require.NoError(t, err) 34 assert.Equal(t, "Welcome back, billybob!", string(body)) 35 }