Skip to content

Commit

Permalink
Hashtags Inserted by Autolink Searchable (#76)
Browse files Browse the repository at this point in the history
* Hashtags Inserted by Autolink Searchable

* Hashtags Unit Tests

* git.apache.org workaround
  • Loading branch information
mjthomp95 authored and levb committed Sep 18, 2019
1 parent 8d31acb commit a017380
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""
}
48 changes: 48 additions & 0 deletions server/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a017380

Please sign in to comment.