-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_test.go
92 lines (75 loc) · 1.93 KB
/
commands_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"testing"
)
var slack FakeSlackChat
var msg = Message{1, "", "", ""}
// FakeSlackChat is a fake slack requests struct
// it implements the chatAgent interface defined in slack.go
// so that it can replace the real slack requests when testing
type FakeSlackChat struct{}
// fakeSlackChat implement get message
func (t *FakeSlackChat) getMessage() (Message, error) {
msg := new(Message)
return *msg, nil
}
// fakeSlackChat implement post message
func (t *FakeSlackChat) postMessage(msg Message) error {
return nil
}
// TestHelloCommand tests responses from the <hello> command
func TestHelloHearCommand(t *testing.T) {
hello := new(Hello)
type helloTestingStruct struct {
input string
expected bool
}
helloHearTest := []helloTestingStruct{
{"hello", true},
{"hello ", true},
{"Hello", true},
{"", false},
{"helloh", false},
{"hello hello", false},
}
for _, tst := range helloHearTest {
res := hello.Hear(&slack, msg, tst.input)
if res != tst.expected {
t.Errorf("Expected %q to return %q, got %q instead", tst.input, tst.expected, res)
}
}
}
// test <hear hello> command
func TestHelloHearHelp(t *testing.T) {
hello := new(Hello)
type helloTestingStruct struct {
input string
expected bool
}
helloHearHelp := []helloTestingStruct{
{"hello help", true},
{"hello help help", false},
{"hello help Help", false},
{"hello help hello", false},
{"hello helpme", false},
{"hello Help", false},
}
for _, tst := range helloHearHelp {
res := hello.Hear(&slack, msg, tst.input)
if res != tst.expected {
t.Errorf("Expected %q to return %q, got %q instead", tst.input, tst.expected, res)
}
}
}
// test <hello> command
func TestHelloSay(t *testing.T) {
hello := new(Hello)
err := hello.say(&slack, msg)
if err != nil {
t.Errorf("Expected Hello.say to return no error")
}
}
// test parse wercker list app
func TestWerckerListApps(t *testing.T) {
// wercker := new(Wercker)
}