/
slack_test.go
55 lines (47 loc) · 1.61 KB
/
slack_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
package bot_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/infracloudio/botkube/pkg/bot"
)
func TestSlackBot_StripUnmarshallingErrEventDetails(t *testing.T) {
//given
sampleEvent := `{"type":"user_huddle_changed","user":{"id":"id","team_id":"team_id"}, "event_ts":"1652949120.004700"}`
testCases := []struct {
Name string
Input string
Expected string
}{
{
Name: "Unmapped event",
Input: fmt.Sprintf(`RTM Error: Received unmapped event "user_huddle_changed": %s`, sampleEvent),
Expected: `RTM Error: Received unmapped event "user_huddle_changed"`,
},
{
Name: "Unmarshalling error message",
Input: fmt.Sprintf(`RTM Error: Could not unmarshall event "user_huddle_changed": %s`, sampleEvent),
Expected: `RTM Error: Could not unmarshall event "user_huddle_changed"`,
},
{
Name: "JSON unmarshal error",
Input: "cannot unmarshal bool into Go value of type string",
Expected: "cannot unmarshal bool into Go value of type string",
},
{
Name: "JSON unmarshal error with colons",
// this is a real error when doing json.Unmarshal([]byte(`":::"`), &time)
Input: `parsing time "":::"" as ""2006-01-02T15:04:05Z07:00"": cannot parse ":::"" as "2006"`,
Expected: `parsing time "":::"" as ""2006-01-02T15:04:05Z07:00"": cannot parse ":::"" as "2006"`,
},
}
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
slackBot := &bot.SlackBot{}
// when
actual := slackBot.StripUnmarshallingErrEventDetails(testCase.Input)
// then
assert.Equal(t, testCase.Expected, actual)
})
}
}