mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2025-01-07 10:42:48 +01:00
stop using multiple channels in basic conn/auth tests
Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
parent
4e0b0497f4
commit
c22e7a0c84
67
irc_test.go
67
irc_test.go
@ -37,8 +37,6 @@ func makeTestIRCConfig(IRCPort int) *Config {
|
|||||||
IRCUseSSL: false,
|
IRCUseSSL: false,
|
||||||
IRCChannels: []IRCChannel{
|
IRCChannels: []IRCChannel{
|
||||||
IRCChannel{Name: "#foo"},
|
IRCChannel{Name: "#foo"},
|
||||||
IRCChannel{Name: "#bar"},
|
|
||||||
IRCChannel{Name: "#baz"},
|
|
||||||
},
|
},
|
||||||
UsePrivmsg: false,
|
UsePrivmsg: false,
|
||||||
}
|
}
|
||||||
@ -68,10 +66,7 @@ func TestServerPassword(t *testing.T) {
|
|||||||
var testStep sync.WaitGroup
|
var testStep sync.WaitGroup
|
||||||
|
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -89,8 +84,6 @@ func TestServerPassword(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +137,6 @@ func TestSendAlertOnPreJoinedChannel(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"NOTICE #foo :test message",
|
"NOTICE #foo :test message",
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
@ -201,8 +192,6 @@ func TestUsePrivmsgToSendAlertOnPreJoinedChannel(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"PRIVMSG #foo :test message",
|
"PRIVMSG #foo :test message",
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
@ -225,10 +214,7 @@ func TestSendAlertAndJoinChannel(t *testing.T) {
|
|||||||
// Send the alert after configured channels have joined, to ensure log
|
// Send the alert after configured channels have joined, to ensure log
|
||||||
// ordering.
|
// ordering.
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -258,8 +244,6 @@ func TestSendAlertAndJoinChannel(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
// #foobar joined before sending message
|
// #foobar joined before sending message
|
||||||
"JOIN #foobar",
|
"JOIN #foobar",
|
||||||
"NOTICE #foobar :test message",
|
"NOTICE #foobar :test message",
|
||||||
@ -307,13 +291,10 @@ func TestSendAlertDisconnected(t *testing.T) {
|
|||||||
holdUserStep.Wait()
|
holdUserStep.Wait()
|
||||||
|
|
||||||
// Make sure session is established by checking that pre-joined
|
// Make sure session is established by checking that pre-joined
|
||||||
// channels are there.
|
// channel is there.
|
||||||
testStep.Add(1)
|
testStep.Add(1)
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -339,8 +320,6 @@ func TestSendAlertDisconnected(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
// Only message sent while being connected is received.
|
// Only message sent while being connected is received.
|
||||||
"NOTICE #foo :connected test message",
|
"NOTICE #foo :connected test message",
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
@ -359,10 +338,7 @@ func TestReconnect(t *testing.T) {
|
|||||||
var testStep sync.WaitGroup
|
var testStep sync.WaitGroup
|
||||||
|
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -370,14 +346,14 @@ func TestReconnect(t *testing.T) {
|
|||||||
testStep.Add(1)
|
testStep.Add(1)
|
||||||
go notifier.Run()
|
go notifier.Run()
|
||||||
|
|
||||||
// Wait until the last pre-joined channel is seen.
|
// Wait until the pre-joined channel is seen.
|
||||||
testStep.Wait()
|
testStep.Wait()
|
||||||
|
|
||||||
// Simulate disconnection.
|
// Simulate disconnection.
|
||||||
testStep.Add(1)
|
testStep.Add(1)
|
||||||
server.Client.Close()
|
server.Client.Close()
|
||||||
|
|
||||||
// Wait again until the last pre-joined channel is seen.
|
// Wait again until the pre-joined channel is seen.
|
||||||
testStep.Wait()
|
testStep.Wait()
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
@ -388,14 +364,10 @@ func TestReconnect(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
// Commands from reconnection
|
// Commands from reconnection
|
||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,10 +408,7 @@ func TestConnectErrorRetry(t *testing.T) {
|
|||||||
notifier.Client.Config().SSL = false
|
notifier.Client.Config().SSL = false
|
||||||
joinStep.Add(1)
|
joinStep.Add(1)
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
joinStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
joinStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -456,8 +425,6 @@ func TestConnectErrorRetry(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,13 +442,10 @@ func TestIdentify(t *testing.T) {
|
|||||||
|
|
||||||
var testStep sync.WaitGroup
|
var testStep sync.WaitGroup
|
||||||
|
|
||||||
// Wait until the last pre-joined channel is seen (joining happens
|
// Wait until the pre-joined channel is seen (joining happens
|
||||||
// after identification).
|
// after identification).
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -499,8 +463,6 @@ func TestIdentify(t *testing.T) {
|
|||||||
"USER foo 12 * :",
|
"USER foo 12 * :",
|
||||||
"PRIVMSG NickServ :IDENTIFY nickpassword",
|
"PRIVMSG NickServ :IDENTIFY nickpassword",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,13 +494,10 @@ func TestGhostAndIdentify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
server.SetHandler("NICK", nickHandler)
|
server.SetHandler("NICK", nickHandler)
|
||||||
|
|
||||||
// Wait until the last pre-joined channel is seen (joining happens
|
// Wait until the pre-joined channel is seen (joining happens
|
||||||
// after identification).
|
// after identification).
|
||||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
// #baz is configured as the last channel to pre-join
|
testStep.Done()
|
||||||
if line.Args[0] == "#baz" {
|
|
||||||
testStep.Done()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server.SetHandler("JOIN", joinHandler)
|
server.SetHandler("JOIN", joinHandler)
|
||||||
@ -563,8 +522,6 @@ func TestGhostAndIdentify(t *testing.T) {
|
|||||||
"NICK foo",
|
"NICK foo",
|
||||||
"PRIVMSG NickServ :IDENTIFY nickpassword",
|
"PRIVMSG NickServ :IDENTIFY nickpassword",
|
||||||
"JOIN #foo",
|
"JOIN #foo",
|
||||||
"JOIN #bar",
|
|
||||||
"JOIN #baz",
|
|
||||||
"QUIT :see ya",
|
"QUIT :see ya",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,16 @@ import (
|
|||||||
irc "github.com/fluffle/goirc/client"
|
irc "github.com/fluffle/goirc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func makeReconcilerTestIRCConfig(IRCPort int) *Config {
|
||||||
|
config := makeTestIRCConfig(IRCPort)
|
||||||
|
config.IRCChannels = []IRCChannel{
|
||||||
|
IRCChannel{Name: "#foo"},
|
||||||
|
IRCChannel{Name: "#bar"},
|
||||||
|
IRCChannel{Name: "#baz"},
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
func makeTestReconciler(config *Config) (*ChannelReconciler, chan bool, chan bool) {
|
func makeTestReconciler(config *Config) (*ChannelReconciler, chan bool, chan bool) {
|
||||||
|
|
||||||
sessionUp := make(chan bool)
|
sessionUp := make(chan bool)
|
||||||
@ -48,7 +58,7 @@ func makeTestReconciler(config *Config) (*ChannelReconciler, chan bool, chan boo
|
|||||||
|
|
||||||
func TestPreJoinChannels(t *testing.T) {
|
func TestPreJoinChannels(t *testing.T) {
|
||||||
server, port := makeTestServer(t)
|
server, port := makeTestServer(t)
|
||||||
config := makeTestIRCConfig(port)
|
config := makeReconcilerTestIRCConfig(port)
|
||||||
reconciler, sessionUp, sessionDown := makeTestReconciler(config)
|
reconciler, sessionUp, sessionDown := makeTestReconciler(config)
|
||||||
|
|
||||||
var testStep sync.WaitGroup
|
var testStep sync.WaitGroup
|
||||||
|
Loading…
Reference in New Issue
Block a user