Modified test 1
This commit is contained in:
parent
da2e16496d
commit
9909b5a3d3
62
irc_test.go
62
irc_test.go
@ -2,32 +2,67 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
// "github.com/thoj/go-ircevent"
|
// "github.com/thoj/go-ircevent"
|
||||||
|
"crypto/tls"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConnection(t *testing.T) {
|
func TestConnection(t *testing.T) {
|
||||||
irccon := IRC("go-eventirc", "go-eventirc")
|
irccon1 := IRC("go-eventirc1", "go-eventirc1")
|
||||||
irccon.VerboseCallbackHandler = true
|
irccon1.VerboseCallbackHandler = true
|
||||||
irccon.Debug = true
|
irccon1.Debug = true
|
||||||
err := irccon.Connect("irc.freenode.net:6667")
|
irccon2 := IRC("go-eventirc2", "go-eventirc2")
|
||||||
|
irccon2.VerboseCallbackHandler = true
|
||||||
|
irccon2.Debug = true
|
||||||
|
err := irccon1.Connect("irc.freenode.net:6667")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(err.Error())
|
t.Log(err.Error())
|
||||||
t.Fatal("Can't connect to freenode.")
|
t.Fatal("Can't connect to freenode.")
|
||||||
}
|
}
|
||||||
irccon.AddCallback("001", func(e *Event) { irccon.Join("#go-eventirc") })
|
err = irccon2.Connect("irc.freenode.net:6667")
|
||||||
|
if err != nil {
|
||||||
irccon.AddCallback("366", func(e *Event) {
|
t.Log(err.Error())
|
||||||
irccon.Privmsg("#go-eventirc", "Test Message\n")
|
t.Fatal("Can't connect to freenode.")
|
||||||
irccon.Nick("go-eventnewnick")
|
}
|
||||||
|
irccon1.AddCallback("001", func(e *Event) { irccon1.Join("#go-eventirc") })
|
||||||
|
irccon2.AddCallback("001", func(e *Event) { irccon2.Join("#go-eventirc") })
|
||||||
|
con2ok := false
|
||||||
|
irccon1.AddCallback("366", func(e *Event) {
|
||||||
|
t := time.NewTicker(1 * time.Second)
|
||||||
|
i := 10
|
||||||
|
for {
|
||||||
|
<-t.C
|
||||||
|
irccon1.Privmsgf("#go-eventirc", "Test Message%d\n", i)
|
||||||
|
if con2ok {
|
||||||
|
i -= 1
|
||||||
|
}
|
||||||
|
if i == 0 {
|
||||||
|
t.Stop()
|
||||||
|
irccon1.Quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
irccon.AddCallback("NICK", func(e *Event) {
|
|
||||||
irccon.Quit()
|
irccon2.AddCallback("366", func(e *Event) {
|
||||||
if irccon.nickcurrent == "go-eventnewnick" {
|
irccon2.Privmsg("#go-eventirc", "Test Message\n")
|
||||||
|
con2ok = true
|
||||||
|
irccon2.Nick("go-eventnewnick")
|
||||||
|
})
|
||||||
|
|
||||||
|
irccon2.AddCallback("PRIVMSG", func(e *Event) {
|
||||||
|
t.Log(e.Message())
|
||||||
|
if e.Message() == "Test Message5" {
|
||||||
|
irccon2.Quit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
irccon2.AddCallback("NICK", func(e *Event) {
|
||||||
|
if irccon2.nickcurrent == "go-eventnewnick" {
|
||||||
t.Fatal("Nick change did not work!")
|
t.Fatal("Nick change did not work!")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
irccon.Loop()
|
go irccon2.Loop()
|
||||||
|
irccon1.Loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnectionSSL(t *testing.T) {
|
func TestConnectionSSL(t *testing.T) {
|
||||||
@ -35,6 +70,7 @@ func TestConnectionSSL(t *testing.T) {
|
|||||||
irccon.VerboseCallbackHandler = true
|
irccon.VerboseCallbackHandler = true
|
||||||
irccon.Debug = true
|
irccon.Debug = true
|
||||||
irccon.UseTLS = true
|
irccon.UseTLS = true
|
||||||
|
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
err := irccon.Connect("irc.freenode.net:7000")
|
err := irccon.Connect("irc.freenode.net:7000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(err.Error())
|
t.Log(err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user