mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-12-25 04:12:46 +01:00
Clean up so that lint would pass
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
This commit is contained in:
parent
ae6594c606
commit
219d3672b7
@ -16,10 +16,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNoConfig(t *testing.T) {
|
func TestNoConfig(t *testing.T) {
|
||||||
@ -87,8 +88,8 @@ func TestLoadBadFile(t *testing.T) {
|
|||||||
os.Remove(tmpfile.Name())
|
os.Remove(tmpfile.Name())
|
||||||
|
|
||||||
config, err := LoadConfig(tmpfile.Name())
|
config, err := LoadConfig(tmpfile.Name())
|
||||||
if config != nil {
|
if err == nil || config != nil {
|
||||||
t.Errorf("Expected no config upon non-existent file.")
|
t.Errorf("Expected no config upon non-existent file. err: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +107,8 @@ func TestLoadBadConfig(t *testing.T) {
|
|||||||
tmpfile.Close()
|
tmpfile.Close()
|
||||||
|
|
||||||
config, err := LoadConfig(tmpfile.Name())
|
config, err := LoadConfig(tmpfile.Name())
|
||||||
if config != nil {
|
if err == nil || config != nil {
|
||||||
t.Errorf("Expected no config upon bad config.")
|
t.Errorf("Expected no config upon bad config. err: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
irc.go
7
irc.go
@ -16,11 +16,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
irc "github.com/fluffle/goirc/client"
|
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
irc "github.com/fluffle/goirc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -131,7 +132,7 @@ func (notifier *IRCNotifier) HandleKick(nick string, channel string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
state, ok := notifier.JoinedChannels[channel]
|
state, ok := notifier.JoinedChannels[channel]
|
||||||
if ok == false {
|
if !ok {
|
||||||
log.Printf("Being kicked out of non-joined channel (%s), ignoring", channel)
|
log.Printf("Being kicked out of non-joined channel (%s), ignoring", channel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -149,7 +150,7 @@ func (notifier *IRCNotifier) CleanupChannels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (notifier *IRCNotifier) JoinChannel(channel *IRCChannel) {
|
func (notifier *IRCNotifier) JoinChannel(channel *IRCChannel) {
|
||||||
if _, joined := notifier.JoinedChannels[channel.Name]; joined == true {
|
if _, joined := notifier.JoinedChannels[channel.Name]; joined {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Joining %s", channel.Name)
|
log.Printf("Joining %s", channel.Name)
|
||||||
|
22
irc_test.go
22
irc_test.go
@ -17,7 +17,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
irc "github.com/fluffle/goirc/client"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -26,17 +25,19 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
irc "github.com/fluffle/goirc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LineHandlerFunc func(*bufio.ReadWriter, *irc.Line) error
|
type LineHandlerFunc func(*bufio.ReadWriter, *irc.Line) error
|
||||||
|
|
||||||
func h_USER(conn *bufio.ReadWriter, line *irc.Line) error {
|
func hUSER(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
r := fmt.Sprintf(":example.com 001 %s :Welcome\n", line.Args[0])
|
r := fmt.Sprintf(":example.com 001 %s :Welcome\n", line.Args[0])
|
||||||
conn.WriteString(r)
|
_, err := conn.WriteString(r)
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func h_QUIT(conn *bufio.ReadWriter, line *irc.Line) error {
|
func hQUIT(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
return fmt.Errorf("client asked to terminate")
|
return fmt.Errorf("client asked to terminate")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +63,8 @@ func (s *testServer) setDefaultHandlers() {
|
|||||||
if s.lineHandlers == nil {
|
if s.lineHandlers == nil {
|
||||||
s.lineHandlers = make(map[string]LineHandlerFunc)
|
s.lineHandlers = make(map[string]LineHandlerFunc)
|
||||||
}
|
}
|
||||||
s.lineHandlers["USER"] = h_USER
|
s.lineHandlers["USER"] = hUSER
|
||||||
s.lineHandlers["QUIT"] = h_QUIT
|
s.lineHandlers["QUIT"] = hQUIT
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) getHandler(cmd string) LineHandlerFunc {
|
func (s *testServer) getHandler(cmd string) LineHandlerFunc {
|
||||||
@ -457,7 +458,7 @@ func TestSendAlertDisconnected(t *testing.T) {
|
|||||||
testStep.Wait()
|
testStep.Wait()
|
||||||
log.Printf("=Server= Completing session")
|
log.Printf("=Server= Completing session")
|
||||||
holdUserStep.Done()
|
holdUserStep.Done()
|
||||||
return h_USER(conn, line)
|
return hUSER(conn, line)
|
||||||
}
|
}
|
||||||
server.SetHandler("USER", holdUser)
|
server.SetHandler("USER", holdUser)
|
||||||
|
|
||||||
@ -675,12 +676,13 @@ func TestGhostAndIdentify(t *testing.T) {
|
|||||||
usedNick.Add(1)
|
usedNick.Add(1)
|
||||||
unregisteredNickHandler.Add(1)
|
unregisteredNickHandler.Add(1)
|
||||||
nickHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
nickHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
|
var err error
|
||||||
if line.Args[0] == "foo" {
|
if line.Args[0] == "foo" {
|
||||||
conn.WriteString(":example.com 433 * foo :nick in use\n")
|
_, err = conn.WriteString(":example.com 433 * foo :nick in use\n")
|
||||||
}
|
}
|
||||||
usedNick.Done()
|
usedNick.Done()
|
||||||
unregisteredNickHandler.Wait()
|
unregisteredNickHandler.Wait()
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
server.SetHandler("NICK", nickHandler)
|
server.SetHandler("NICK", nickHandler)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user