From be45f6f2d9e4883333aae2c0290b651c861cf15a Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Wed, 27 Oct 2021 21:34:05 -0400 Subject: [PATCH] multiclient test --- irc_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/irc_test.go b/irc_test.go index bf323b2..f2b9744 100644 --- a/irc_test.go +++ b/irc_test.go @@ -79,6 +79,35 @@ func TestLusersChannels(t *testing.T) { con.Run() } +func TestMultiClient(t *testing.T) { + con := NewConnection("irc.ouch.chat:6667", "irc-go", "irc-go", nil, []string{channel}) + + chancnt := make(chan int) + + con.NumericCallback = func(from string, i int, args string) { + if i == RPL_ENDOFMOTD { + con2 := NewConnection("irc.libera.chat:6667", "irc-go66543", "irc-go66543", nil, nil) + con2.NumericCallback = func(from string, i int, args string) { + if i == RPL_LUSERCHANNELS { + s := strings.TrimSpace(strings.Split(args, " ")[1]) + val, _ := strconv.Atoi(s) + chancnt <- val + } + } + go con2.Run() + + go func() { + resp := <-chancnt + con.SendPrivmsg(channel, fmt.Sprintf("There are %d channels formed on libera", resp)) + con2.SendQuit("") + con.SendQuit("") + }() + } + } + + con.Run() +} + func TestParser(t *testing.T) { log.Printf("testing %s\n", t.Name()) }