-
Notifications
You must be signed in to change notification settings - Fork 25
/
conversation_test.go
56 lines (38 loc) · 988 Bytes
/
conversation_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
package hanu
import (
"testing"
"golang.org/x/net/websocket"
"github.com/sbstjn/allot"
)
type ConnectionMock struct{}
func (c ConnectionMock) Send(ws *websocket.Conn, v interface{}) (err error) {
return nil
}
func TestConversation(t *testing.T) {
command := allot.New("cmd test <param>")
msg := Message{
ID: 0,
}
msg.SetText("cmd test value")
match, _ := command.Match(msg.Text())
conv := NewConversation(match, msg, nil)
str, err := conv.String("param")
if err != nil {
t.Errorf("Failed to get correct value for param \"param\"")
}
if str != "value" {
t.Errorf("Failed to get correct value for param \"param\": %s != %s", str, "value")
}
conv.Reply("example")
}
func TestConnect(t *testing.T) {
cmd := allot.New("cmd test <param>")
msg := Message{
ID: 0,
}
msg.SetText("cmd test value")
match, _ := cmd.Match(msg.Text())
conv := NewConversation(match, msg, &websocket.Conn{})
conv.SetConnection(ConnectionMock{})
conv.Reply("example")
}