/
slackbot_test.go
58 lines (48 loc) · 1.28 KB
/
slackbot_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
57
58
// Slackbot - A Slack robot library written in Go
//
// Author: Vincent Composieux <vincent.composieux@gmail.com>
package slackbot
import (
"testing"
)
// Tests pre-defined and variables values
func TestVariablesValues(t *testing.T) {
Token = "test-token"
if Token != "test-token" {
t.Error("Should have the Token defined")
}
}
// Tests the command addition
func TestAddCommand(t *testing.T) {
if len(commands) != 0 {
t.Error("Should have 0 commands by default")
}
AddCommand("test-a", "a", "test a", func(command Command, message Message) {})
AddCommand("test-b", "b", "test b", func(command Command, message Message) {})
if len(commands) != 2 {
t.Error("Should have 2 commands added")
}
}
// Tests that the check prefix flag works
func TestCheckPrefix(t *testing.T) {
testCases := []struct {
RequirePrefix bool
input string
expectation bool
}{
{true, "!foo", true},
{false, "!foo", true},
{true, "foo", false},
{false, "foo", true},
}
for _, testCase := range testCases {
prefix := "!"
var message Message
message.Text = testCase.input
result := checkPrefix(message, prefix, testCase.RequirePrefix)
if result != testCase.expectation {
t.Fatalf("\nGot: %t\nExpected: %t\n--with--\n%v\n",
result, testCase.expectation, testCase)
}
}
}