From 219d3672b708e9a8967398e4d18e233e3a9d32ca Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Fri, 27 Dec 2019 13:07:33 +0000 Subject: [PATCH] Clean up so that lint would pass Signed-off-by: Goutham Veeramachaneni --- config_test.go | 11 ++++++----- irc.go | 7 ++++--- irc_test.go | 22 ++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/config_test.go b/config_test.go index 3ca5cdd..4e0b438 100644 --- a/config_test.go +++ b/config_test.go @@ -16,10 +16,11 @@ package main import ( "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "os" "testing" + + "gopkg.in/yaml.v2" ) func TestNoConfig(t *testing.T) { @@ -87,8 +88,8 @@ func TestLoadBadFile(t *testing.T) { os.Remove(tmpfile.Name()) config, err := LoadConfig(tmpfile.Name()) - if config != nil { - t.Errorf("Expected no config upon non-existent file.") + if err == nil || config != nil { + t.Errorf("Expected no config upon non-existent file. err: %s", err) } } @@ -106,8 +107,8 @@ func TestLoadBadConfig(t *testing.T) { tmpfile.Close() config, err := LoadConfig(tmpfile.Name()) - if config != nil { - t.Errorf("Expected no config upon bad config.") + if err == nil || config != nil { + t.Errorf("Expected no config upon bad config. err: %s", err) } } diff --git a/irc.go b/irc.go index e897dc2..8658ed7 100644 --- a/irc.go +++ b/irc.go @@ -16,11 +16,12 @@ package main import ( "crypto/tls" - irc "github.com/fluffle/goirc/client" "log" "strconv" "strings" "time" + + irc "github.com/fluffle/goirc/client" ) const ( @@ -131,7 +132,7 @@ func (notifier *IRCNotifier) HandleKick(nick string, channel string) { return } state, ok := notifier.JoinedChannels[channel] - if ok == false { + if !ok { log.Printf("Being kicked out of non-joined channel (%s), ignoring", channel) return } @@ -149,7 +150,7 @@ func (notifier *IRCNotifier) CleanupChannels() { } func (notifier *IRCNotifier) JoinChannel(channel *IRCChannel) { - if _, joined := notifier.JoinedChannels[channel.Name]; joined == true { + if _, joined := notifier.JoinedChannels[channel.Name]; joined { return } log.Printf("Joining %s", channel.Name) diff --git a/irc_test.go b/irc_test.go index 9c8dfa4..8d39761 100644 --- a/irc_test.go +++ b/irc_test.go @@ -17,7 +17,6 @@ package main import ( "bufio" "fmt" - irc "github.com/fluffle/goirc/client" "io" "log" "net" @@ -26,17 +25,19 @@ import ( "sync" "testing" "time" + + irc "github.com/fluffle/goirc/client" ) 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]) - conn.WriteString(r) - return nil + _, err := conn.WriteString(r) + 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") } @@ -62,8 +63,8 @@ func (s *testServer) setDefaultHandlers() { if s.lineHandlers == nil { s.lineHandlers = make(map[string]LineHandlerFunc) } - s.lineHandlers["USER"] = h_USER - s.lineHandlers["QUIT"] = h_QUIT + s.lineHandlers["USER"] = hUSER + s.lineHandlers["QUIT"] = hQUIT } func (s *testServer) getHandler(cmd string) LineHandlerFunc { @@ -457,7 +458,7 @@ func TestSendAlertDisconnected(t *testing.T) { testStep.Wait() log.Printf("=Server= Completing session") holdUserStep.Done() - return h_USER(conn, line) + return hUSER(conn, line) } server.SetHandler("USER", holdUser) @@ -675,12 +676,13 @@ func TestGhostAndIdentify(t *testing.T) { usedNick.Add(1) unregisteredNickHandler.Add(1) nickHandler := func(conn *bufio.ReadWriter, line *irc.Line) error { + var err error 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() unregisteredNickHandler.Wait() - return nil + return err } server.SetHandler("NICK", nickHandler)