-
Notifications
You must be signed in to change notification settings - Fork 291
/
slack_helpers_test.go
56 lines (47 loc) · 1.68 KB
/
slack_helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//go:build integration
package e2e
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
var slackLinks = regexp.MustCompile(`<(?P<val>https://[^>]*)>`)
func RemoveSlackLinksIndicators(content string) string {
tpl := "$val"
return slackLinks.ReplaceAllStringFunc(content, func(s string) string {
var result []byte
result = slackLinks.ExpandString(result, tpl, s, slackLinks.FindSubmatchIndex([]byte(s)))
return string(result)
})
}
func TestRemoveSlackLinksIndicators(t *testing.T) {
tests := []struct {
name string
content string
expected string
}{
{
name: "no links",
content: `"...and now my watch begins for cluster '%s'! :crossed_swords:"`,
expected: `"...and now my watch begins for cluster '%s'! :crossed_swords:"`,
},
{
name: "one link",
content: `You can extend Botkube functionality by writing additional filters that can check resource specs, validate some checks and add messages to the Event struct. Learn more at <https://docs.botkube.io/filters>`,
expected: `You can extend Botkube functionality by writing additional filters that can check resource specs, validate some checks and add messages to the Event struct. Learn more at https://docs.botkube.io/filters`,
},
{
name: "multiple links",
content: `Learn more at <https://docs.botkube.io/filters> and <https://docs.botkube.io/configuration/source>`,
expected: `Learn more at https://docs.botkube.io/filters and https://docs.botkube.io/configuration/source`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// when
got := RemoveSlackLinksIndicators(tc.content)
// then
assert.Equal(t, tc.expected, got)
})
}
}