mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2025-01-06 02:02:51 +01:00
move channel-specific tests to new management object
Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
parent
9690575d68
commit
4e0b0497f4
38
irc_test.go
38
irc_test.go
@ -59,44 +59,6 @@ func makeTestNotifier(t *testing.T, config *Config) (*IRCNotifier, chan AlertMsg
|
||||
return notifier, alertMsgs, cancel, &stopWg
|
||||
}
|
||||
|
||||
func TestPreJoinChannels(t *testing.T) {
|
||||
server, port := makeTestServer(t)
|
||||
config := makeTestIRCConfig(port)
|
||||
notifier, _, cancel, _ := makeTestNotifier(t, config)
|
||||
|
||||
var testStep sync.WaitGroup
|
||||
|
||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||
// #baz is configured as the last channel to pre-join
|
||||
if line.Args[0] == "#baz" {
|
||||
testStep.Done()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
server.SetHandler("JOIN", joinHandler)
|
||||
|
||||
testStep.Add(1)
|
||||
go notifier.Run()
|
||||
|
||||
testStep.Wait()
|
||||
|
||||
cancel()
|
||||
server.Stop()
|
||||
|
||||
expectedCommands := []string{
|
||||
"NICK foo",
|
||||
"USER foo 12 * :",
|
||||
"JOIN #foo",
|
||||
"JOIN #bar",
|
||||
"JOIN #baz",
|
||||
"QUIT :see ya",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedCommands, server.Log) {
|
||||
t.Error("Did not pre-join channels")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerPassword(t *testing.T) {
|
||||
server, port := makeTestServer(t)
|
||||
config := makeTestIRCConfig(port)
|
||||
|
91
reconciler_test.go
Normal file
91
reconciler_test.go
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
irc "github.com/fluffle/goirc/client"
|
||||
)
|
||||
|
||||
func makeTestReconciler(config *Config) (*ChannelReconciler, chan bool, chan bool) {
|
||||
|
||||
sessionUp := make(chan bool)
|
||||
sessionDown := make(chan bool)
|
||||
|
||||
client := irc.Client(makeGOIRCConfig(config))
|
||||
client.Config().Flood = true
|
||||
client.HandleFunc(irc.CONNECTED,
|
||||
func(*irc.Conn, *irc.Line) {
|
||||
sessionUp <- true
|
||||
})
|
||||
|
||||
client.HandleFunc(irc.DISCONNECTED,
|
||||
func(*irc.Conn, *irc.Line) {
|
||||
sessionDown <- false
|
||||
})
|
||||
|
||||
fakeDelayerMaker := &FakeDelayerMaker{}
|
||||
reconciler := NewChannelReconciler(config, client, fakeDelayerMaker)
|
||||
|
||||
return reconciler, sessionUp, sessionDown
|
||||
}
|
||||
|
||||
func TestPreJoinChannels(t *testing.T) {
|
||||
server, port := makeTestServer(t)
|
||||
config := makeTestIRCConfig(port)
|
||||
reconciler, sessionUp, sessionDown := makeTestReconciler(config)
|
||||
|
||||
var testStep sync.WaitGroup
|
||||
|
||||
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||
// #baz is configured as the last channel to pre-join
|
||||
if line.Args[0] == "#baz" {
|
||||
testStep.Done()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
server.SetHandler("JOIN", joinHandler)
|
||||
|
||||
testStep.Add(1)
|
||||
|
||||
reconciler.client.Connect()
|
||||
|
||||
<-sessionUp
|
||||
reconciler.JoinChannels()
|
||||
|
||||
testStep.Wait()
|
||||
|
||||
reconciler.client.Quit("see ya")
|
||||
<-sessionDown
|
||||
|
||||
server.Stop()
|
||||
|
||||
expectedCommands := []string{
|
||||
"NICK foo",
|
||||
"USER foo 12 * :",
|
||||
"JOIN #foo",
|
||||
"JOIN #bar",
|
||||
"JOIN #baz",
|
||||
"QUIT :see ya",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedCommands, server.Log) {
|
||||
t.Error("Did not pre-join channels")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user