github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/tests/plugin_tests/test_search_posts_in_team_plugin/main.go (about) 1 // Copyright (c) 2015-present Xenia, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "fmt" 8 9 "github.com/xzl8028/xenia-server/model" 10 "github.com/xzl8028/xenia-server/plugin" 11 ) 12 13 type MyPlugin struct { 14 plugin.XeniaPlugin 15 } 16 17 func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) { 18 19 testCases := []struct { 20 description string 21 teamId string 22 params []*model.SearchParams 23 expectedPostsLen int 24 }{ 25 { 26 "nil params", 27 "{{.BasicTeam.Id}}", 28 nil, 29 0, 30 }, 31 { 32 "empty params", 33 "{{.BasicTeam.Id}}", 34 []*model.SearchParams{}, 35 0, 36 }, 37 { 38 "doesn't match any posts", 39 "{{.BasicTeam.Id}}", 40 model.ParseSearchParams("bad message", 0), 41 0, 42 }, 43 { 44 "matched posts", 45 "{{.BasicTeam.Id}}", 46 model.ParseSearchParams("{{.BasicPost.Message}}", 0), 47 1, 48 }, 49 } 50 51 for _, testCase := range testCases { 52 posts, err := p.API.SearchPostsInTeam(testCase.teamId, testCase.params) 53 if err != nil { 54 return nil, fmt.Sprintf("%v: %v", testCase.description, err.Error()) 55 } 56 if testCase.expectedPostsLen != len(posts) { 57 return nil, fmt.Sprintf("%v: invalid number of posts: %v != %v", testCase.description, testCase.expectedPostsLen, len(posts)) 58 } 59 } 60 return nil, "" 61 } 62 63 func main() { 64 plugin.ClientMain(&MyPlugin{}) 65 }