From a0173805afb7315bbf9979536555d4d3cdada1fa Mon Sep 17 00:00:00 2001 From: Micah Thompson Date: Wed, 18 Sep 2019 16:03:17 -0400 Subject: [PATCH] Hashtags Inserted by Autolink Searchable (#76) * Hashtags Inserted by Autolink Searchable * Hashtags Unit Tests * git.apache.org workaround --- go.mod | 6 +++++- go.sum | 1 + server/plugin.go | 2 ++ server/plugin_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 57165c94..2869252e 100644 --- a/go.mod +++ b/go.mod @@ -24,4 +24,8 @@ require ( ) // Workaround for https://github.com/golang/go/issues/30831 and fallout. -replace github.com/golang/lint => github.com/golang/lint v0.0.0-20190227174305-8f45f776aaf1 +replace ( + git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999 + // Workaround for https://github.com/golang/go/issues/30831 and fallout. + github.com/golang/lint => github.com/golang/lint v0.0.0-20190227174305-8f45f776aaf1 +) diff --git a/go.sum b/go.sum index f5cf9753..f1639e78 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,7 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= diff --git a/server/plugin.go b/server/plugin.go index 134c48c0..dff6a1ca 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -94,5 +94,7 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode }) post.Message = postText + post.Hashtags, _ = model.ParseHashtags(post.Message) + return post, "" } diff --git a/server/plugin_test.go b/server/plugin_test.go index 3d272873..b03d257f 100644 --- a/server/plugin_test.go +++ b/server/plugin_test.go @@ -224,3 +224,51 @@ func TestSpecialCases(t *testing.T) { }) } } + +func TestHashtags(t *testing.T) { + conf := Config{ + Links: []Link{ + Link{ + Pattern: "foo", + Template: "#bar", + }, + Link{ + Pattern: "hash tags", + Template: "#hash #tags", + }, + }, + } + + testChannel := model.Channel{ + Name: "TestChanel", + } + + testTeam := model.Team{ + Name: "TestTeam", + } + + api := &plugintest.API{} + + api.On("LoadPluginConfiguration", mock.AnythingOfType("*main.Config")).Return(func(dest interface{}) error { + *dest.(*Config) = conf + return nil + }) + api.On("UnregisterCommand", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return((*model.AppError)(nil)) + + api.On("GetChannel", mock.AnythingOfType("string")).Return(&testChannel, nil) + api.On("GetTeam", mock.AnythingOfType("string")).Return(&testTeam, nil) + + p := Plugin{} + p.SetAPI(api) + p.OnConfigurationChange() + + post := &model.Post{Message: "foo"} + rpost, _ := p.MessageWillBePosted(&plugin.Context{}, post) + + assert.Equal(t, "#bar", rpost.Hashtags) + + post.Message = "hash tags" + rpost, _ = p.MessageWillBePosted(&plugin.Context{}, post) + + assert.Equal(t, "#hash #tags", rpost.Hashtags) +}