-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirc_test.go
92 lines (79 loc) · 2.17 KB
/
irc_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"
import "log"
import "time"
import "strconv"
// checks if CheckChannel recognized whether we're in a channel or not
func TestCheckChannels(t *testing.T) {
irc := IRC{Server: "irc.abjects.net:6667"}
if !irc.Connect() {
t.FailNow()
}
log.Print("1")
irc.JoinChannel("#moviegods")
if !irc.CheckChannel("#moviegods") {
t.FailNow()
}
log.Print("2")
irc.CommandCh<-"PART #moviegods\r\n"
time.Sleep(1*time.Second)
if irc.CheckChannel("#moviegods") {
t.FailNow()
}
log.Print("3")
irc.channels = []string{}
irc.JoinChannel("#moviegods")
if !irc.CheckChannel("#moviegods") {
t.FailNow()
}
log.Print("4")
irc.Quit()
}
// test if our ping (StillConnected) works
func TestConnCheck(t *testing.T) {
connPool := ConnectionPool{}
chs := []ChannelConfig{ChannelConfig{Server:"irc.abjects.net:6667", Channel:"#beast-xdcc"}}
c := (Config{})
c.Channels = chs
CreateIndexer(&c, &connPool)
irc := connPool.GetConnection(chs[0].Server)
if !irc.StillConnected() {
t.FailNow()
}
connPool.GetConnection(chs[0].Server).conn.Close()
if irc.StillConnected() {
t.FailNow()
}
}
// checks if the watchdog recognizes loss of connection and reconnects + rejoins
func TestWatchDog(t *testing.T) {
connPool := ConnectionPool{}
chs := []ChannelConfig{ChannelConfig{Server:"irc.abjects.net:6667", Channel:"#aaaaasdf"}}
c := (Config{})
c.Channels = chs
indx := CreateIndexer(&c, &connPool)
connPool.GetConnection(chs[0].Server).conn.Close()
indx.watchDog()
if !connPool.GetConnection(chs[0].Server).CheckChannel("#aaaaasdf") {
t.FailNow()
}
}
// checks if the watchdog recognizes parting a channel and NOT reconnects but rejoins
func TestWatchdogLong(t *testing.T) {
connPool := ConnectionPool{}
chs := []ChannelConfig{ChannelConfig{Server:"irc.abjects.net:6667", Channel:"#a"}}
for i :=0; i<2; i++ {
chs = append(chs,ChannelConfig{Server:"irc.abjects.net:6667", Channel:"#a"+strconv.FormatInt(int64(i), 10)})
}
c := (Config{})
c.Channels = chs
irc := connPool.GetConnection(chs[0].Server)
indx := CreateIndexer(&c, &connPool)
irc.CommandCh<-"PART #a1\r\n"
for i :=0; i<10; i++ {
if indx.watchDog() {
t.FailNow()
}
time.Sleep(1*time.Second);
}
}