-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe2e_test.go
51 lines (42 loc) · 1.23 KB
/
e2e_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
package main
import (
"fmt"
"medgebot/bot"
"medgebot/bot/bottest"
"medgebot/cache"
"medgebot/irc"
"medgebot/irc/irctest"
"medgebot/ws/wstest"
"testing"
)
const (
USER = "medgelabs"
CHANNEL = "medgelabs"
)
func TestRaids(t *testing.T) {
ws := wstest.NewWebsocket()
ircClient := irc.NewClient(ws)
ircConf := irc.Config{
Nick: USER,
Password: "oauth:superSpookyGhostMachineTestSecret",
Channel: "#" + CHANNEL,
}
if err := ircClient.Start(ircConf); err != nil {
t.Fatalf("Failed to start IRC client: %v", err)
}
cache, _ := cache.InMemory(0)
chatBot := bot.New(&cache)
chatBot.RegisterClient(ircClient)
chatBot.SetChatClient(ircClient)
raidTmpl := bot.NewHandlerTemplate(bottest.MakeTemplate("raids", "{{.Sender}} raid of {{.Amount}}"))
chatBot.RegisterRaidHandler(raidTmpl, 1)
// We must Start the bot AFTER the handler is registered
chatBot.Start()
// We should see "USER raid of RAID_SIZE" eventually come through the IRC client
raidSize := 5
expectedMessage := fmt.Sprintf("PRIVMSG #medgelabs :%s raid of %d", USER, raidSize)
ws.SendAndWait(irctest.MakeRaidMessage(USER, raidSize, CHANNEL))
if !ws.Received(expectedMessage) {
t.Fatalf("Did not see expected Raid Message.\nWS Dump:\n%s", ws.String())
}
}