mirror of https://github.com/fluffle/goirc
Run gofmt, since it's clearly been a while.
This commit is contained in:
parent
a674267128
commit
f27e56c8b0
|
@ -1,11 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
irc "github.com/fluffle/goirc/client"
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
irc "github.com/fluffle/goirc/client"
|
||||||
"os"
|
"os"
|
||||||
"bufio"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ type Conn struct {
|
||||||
Flood bool
|
Flood bool
|
||||||
|
|
||||||
// Internal counters for flood protection
|
// Internal counters for flood protection
|
||||||
badness time.Duration
|
badness time.Duration
|
||||||
lastsent time.Time
|
lastsent time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package client
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"code.google.com/p/gomock/gomock"
|
"code.google.com/p/gomock/gomock"
|
||||||
"github.com/fluffle/golog/logging"
|
|
||||||
"github.com/fluffle/goirc/state"
|
"github.com/fluffle/goirc/state"
|
||||||
|
"github.com/fluffle/golog/logging"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -57,7 +57,7 @@ func TestEOF(t *testing.T) {
|
||||||
|
|
||||||
// Set up a handler to detect whether disconnected handlers are called
|
// Set up a handler to detect whether disconnected handlers are called
|
||||||
dcon := false
|
dcon := false
|
||||||
c.HandleFunc("disconnected", func (conn *Conn, line *Line) {
|
c.HandleFunc("disconnected", func(conn *Conn, line *Line) {
|
||||||
dcon = true
|
dcon = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -356,12 +356,12 @@ func TestRunLoop(t *testing.T) {
|
||||||
|
|
||||||
// Set up a handler to detect whether 001 handler is called
|
// Set up a handler to detect whether 001 handler is called
|
||||||
h001 := false
|
h001 := false
|
||||||
c.HandleFunc("001", func (conn *Conn, line *Line) {
|
c.HandleFunc("001", func(conn *Conn, line *Line) {
|
||||||
h001 = true
|
h001 = true
|
||||||
})
|
})
|
||||||
// Set up a handler to detect whether 002 handler is called
|
// Set up a handler to detect whether 002 handler is called
|
||||||
h002 := false
|
h002 := false
|
||||||
c.HandleFunc("002", func (conn *Conn, line *Line) {
|
c.HandleFunc("002", func(conn *Conn, line *Line) {
|
||||||
h002 = true
|
h002 = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ func TestRateLimit(t *testing.T) {
|
||||||
|
|
||||||
// We'll be needing this later...
|
// We'll be needing this later...
|
||||||
abs := func(i time.Duration) time.Duration {
|
abs := func(i time.Duration) time.Duration {
|
||||||
if (i < 0) {
|
if i < 0 {
|
||||||
return -i
|
return -i
|
||||||
}
|
}
|
||||||
return i
|
return i
|
||||||
|
@ -491,13 +491,13 @@ func TestRateLimit(t *testing.T) {
|
||||||
// 2.5 seconds minus the delta between the two ratelimit calls. This should
|
// 2.5 seconds minus the delta between the two ratelimit calls. This should
|
||||||
// be minimal but it's guaranteed that it won't be zero. Use 10us as a fuzz.
|
// be minimal but it's guaranteed that it won't be zero. Use 10us as a fuzz.
|
||||||
if l := c.rateLimit(60); l != 0 ||
|
if l := c.rateLimit(60); l != 0 ||
|
||||||
abs(c.badness - 2500*time.Millisecond) > 10 * time.Microsecond {
|
abs(c.badness-2500*time.Millisecond) > 10*time.Microsecond {
|
||||||
t.Errorf("Rate limit calculating badness incorrectly.")
|
t.Errorf("Rate limit calculating badness incorrectly.")
|
||||||
}
|
}
|
||||||
// At this point, we can tip over the badness scale, with a bit of help.
|
// At this point, we can tip over the badness scale, with a bit of help.
|
||||||
// 720 chars => +8 seconds of badness => 10.5 seconds => ratelimit
|
// 720 chars => +8 seconds of badness => 10.5 seconds => ratelimit
|
||||||
if l := c.rateLimit(720); l != 8 * time.Second ||
|
if l := c.rateLimit(720); l != 8*time.Second ||
|
||||||
abs(c.badness - 10500*time.Millisecond) > 10 * time.Microsecond {
|
abs(c.badness-10500*time.Millisecond) > 10*time.Microsecond {
|
||||||
t.Errorf("Rate limit failed to return correct limiting values.")
|
t.Errorf("Rate limit failed to return correct limiting values.")
|
||||||
t.Errorf("l=%d, badness=%d", l, c.badness)
|
t.Errorf("l=%d, badness=%d", l, c.badness)
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,9 @@ func (hs *hSet) dispatch(conn *Conn, line *Line) {
|
||||||
defer hs.RUnlock()
|
defer hs.RUnlock()
|
||||||
ev := strings.ToLower(line.Cmd)
|
ev := strings.ToLower(line.Cmd)
|
||||||
list, ok := hs.set[ev]
|
list, ok := hs.set[ev]
|
||||||
if !ok { return }
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
for hn := list.start; hn != nil; hn = hn.next {
|
for hn := list.start; hn != nil; hn = hn.next {
|
||||||
go hn.Handle(conn, line)
|
go hn.Handle(conn, line)
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ func TestHandlerSet(t *testing.T) {
|
||||||
if callcount != 0 {
|
if callcount != 0 {
|
||||||
t.Errorf("Something incremented call count before we were expecting it.")
|
t.Errorf("Something incremented call count before we were expecting it.")
|
||||||
}
|
}
|
||||||
hs.dispatch(nil, &Line{Cmd:"One"})
|
hs.dispatch(nil, &Line{Cmd: "One"})
|
||||||
<-time.After(time.Millisecond)
|
<-time.After(time.Millisecond)
|
||||||
if callcount != 4 {
|
if callcount != 4 {
|
||||||
t.Errorf("Our handler wasn't called four times :-(")
|
t.Errorf("Our handler wasn't called four times :-(")
|
||||||
|
@ -107,7 +107,7 @@ func TestHandlerSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch should result in 3 additions.
|
// Dispatch should result in 3 additions.
|
||||||
hs.dispatch(nil, &Line{Cmd:"One"})
|
hs.dispatch(nil, &Line{Cmd: "One"})
|
||||||
<-time.After(time.Millisecond)
|
<-time.After(time.Millisecond)
|
||||||
if callcount != 7 {
|
if callcount != 7 {
|
||||||
t.Errorf("Our handler wasn't called three times :-(")
|
t.Errorf("Our handler wasn't called three times :-(")
|
||||||
|
@ -129,7 +129,7 @@ func TestHandlerSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch should result in 2 additions.
|
// Dispatch should result in 2 additions.
|
||||||
hs.dispatch(nil, &Line{Cmd:"One"})
|
hs.dispatch(nil, &Line{Cmd: "One"})
|
||||||
<-time.After(time.Millisecond)
|
<-time.After(time.Millisecond)
|
||||||
if callcount != 9 {
|
if callcount != 9 {
|
||||||
t.Errorf("Our handler wasn't called two times :-(")
|
t.Errorf("Our handler wasn't called two times :-(")
|
||||||
|
@ -151,7 +151,7 @@ func TestHandlerSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch should result in 1 addition.
|
// Dispatch should result in 1 addition.
|
||||||
hs.dispatch(nil, &Line{Cmd:"One"})
|
hs.dispatch(nil, &Line{Cmd: "One"})
|
||||||
<-time.After(time.Millisecond)
|
<-time.After(time.Millisecond)
|
||||||
if callcount != 10 {
|
if callcount != 10 {
|
||||||
t.Errorf("Our handler wasn't called once :-(")
|
t.Errorf("Our handler wasn't called once :-(")
|
||||||
|
@ -170,7 +170,7 @@ func TestHandlerSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch should result in NO additions.
|
// Dispatch should result in NO additions.
|
||||||
hs.dispatch(nil, &Line{Cmd:"One"})
|
hs.dispatch(nil, &Line{Cmd: "One"})
|
||||||
<-time.After(time.Millisecond)
|
<-time.After(time.Millisecond)
|
||||||
if callcount != 10 {
|
if callcount != 10 {
|
||||||
t.Errorf("Our handler was called?")
|
t.Errorf("Our handler was called?")
|
||||||
|
@ -184,7 +184,7 @@ func TestCommandSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &command{
|
c := &command{
|
||||||
fn: func(c *Conn, l *Line) {},
|
fn: func(c *Conn, l *Line) {},
|
||||||
help: "wtf?",
|
help: "wtf?",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ func TestCommandSet(t *testing.T) {
|
||||||
if fail := cs.add("one", c); fail != nil {
|
if fail := cs.add("one", c); fail != nil {
|
||||||
t.Errorf("Adding a second 'one' command did not fail as expected.")
|
t.Errorf("Adding a second 'one' command did not fail as expected.")
|
||||||
}
|
}
|
||||||
|
|
||||||
cn2 := cs.add("One Two", c).(*cNode)
|
cn2 := cs.add("One Two", c).(*cNode)
|
||||||
if _, ok := cs.set["one two"]; !ok || cn2.set != cs || cn2.prefix != "one two" {
|
if _, ok := cs.set["one two"]; !ok || cn2.set != cs || cn2.prefix != "one two" {
|
||||||
t.Errorf("Command 'one two' not added to set correctly.")
|
t.Errorf("Command 'one two' not added to set correctly.")
|
||||||
|
@ -208,7 +208,7 @@ func TestCommandSet(t *testing.T) {
|
||||||
if c, l := cs.match("one"); c.(*cNode) != cn1 || l != 3 {
|
if c, l := cs.match("one"); c.(*cNode) != cn1 || l != 3 {
|
||||||
t.Errorf("Didn't match 'one' when we should have.")
|
t.Errorf("Didn't match 'one' when we should have.")
|
||||||
}
|
}
|
||||||
if c, l := cs.match ("one two three"); c.(*cNode) != cn2 || l != 7 {
|
if c, l := cs.match("one two three"); c.(*cNode) != cn2 || l != 7 {
|
||||||
t.Errorf("Didn't match 'one two' when we should have.")
|
t.Errorf("Didn't match 'one two' when we should have.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,14 +216,14 @@ func TestCommandSet(t *testing.T) {
|
||||||
if _, ok := cs.set["one two"]; ok || cn2.set != nil {
|
if _, ok := cs.set["one two"]; ok || cn2.set != nil {
|
||||||
t.Errorf("Command 'one two' not removed correctly.")
|
t.Errorf("Command 'one two' not removed correctly.")
|
||||||
}
|
}
|
||||||
if c, l := cs.match ("one two three"); c.(*cNode) != cn1 || l != 3 {
|
if c, l := cs.match("one two three"); c.(*cNode) != cn1 || l != 3 {
|
||||||
t.Errorf("Didn't match 'one' when we should have.")
|
t.Errorf("Didn't match 'one' when we should have.")
|
||||||
}
|
}
|
||||||
cn1.Remove()
|
cn1.Remove()
|
||||||
if _, ok := cs.set["one"]; ok || cn1.set != nil {
|
if _, ok := cs.set["one"]; ok || cn1.set != nil {
|
||||||
t.Errorf("Command 'one' not removed correctly.")
|
t.Errorf("Command 'one' not removed correctly.")
|
||||||
}
|
}
|
||||||
if c, l := cs.match ("one two three"); c != nil || l != 0 {
|
if c, l := cs.match("one two three"); c != nil || l != 0 {
|
||||||
t.Errorf("Matched 'one' when we shouldn't have.")
|
t.Errorf("Matched 'one' when we shouldn't have.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
// sets up the internal event handlers to do essential IRC protocol things
|
// sets up the internal event handlers to do essential IRC protocol things
|
||||||
var intHandlers = map[string]HandlerFunc{
|
var intHandlers = map[string]HandlerFunc{
|
||||||
"001": (*Conn).h_001,
|
"001": (*Conn).h_001,
|
||||||
"433": (*Conn).h_433,
|
"433": (*Conn).h_433,
|
||||||
"CTCP": (*Conn).h_CTCP,
|
"CTCP": (*Conn).h_CTCP,
|
||||||
"NICK": (*Conn).h_NICK,
|
"NICK": (*Conn).h_NICK,
|
||||||
"PING": (*Conn).h_PING,
|
"PING": (*Conn).h_PING,
|
||||||
|
@ -99,7 +99,9 @@ func (conn *Conn) h_PRIVMSG(line *Line) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd, l := conn.cmdMatch(txt)
|
cmd, l := conn.cmdMatch(txt)
|
||||||
if cmd == nil { return }
|
if cmd == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if conn.CommandStripPrefix {
|
if conn.CommandStripPrefix {
|
||||||
txt = strings.TrimSpace(txt[l:])
|
txt = strings.TrimSpace(txt[l:])
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func Test001(t *testing.T) {
|
||||||
l := parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com")
|
l := parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com")
|
||||||
// Set up a handler to detect whether connected handler is called from 001
|
// Set up a handler to detect whether connected handler is called from 001
|
||||||
hcon := false
|
hcon := false
|
||||||
c.HandleFunc("connected", func (conn *Conn, line *Line) {
|
c.HandleFunc("connected", func(conn *Conn, line *Line) {
|
||||||
hcon = true
|
hcon = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -139,11 +139,11 @@ func TestCTCP(t *testing.T) {
|
||||||
c.h_CTCP(parseLine(":blah!moo@cows.com PRIVMSG test :\001UNKNOWN ctcp\001"))
|
c.h_CTCP(parseLine(":blah!moo@cows.com PRIVMSG test :\001UNKNOWN ctcp\001"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPRIVMSG(t *testing.T){
|
func TestPRIVMSG(t *testing.T) {
|
||||||
c, s := setUp(t)
|
c, s := setUp(t)
|
||||||
defer s.tearDown()
|
defer s.tearDown()
|
||||||
|
|
||||||
f := func (conn *Conn, line *Line) {
|
f := func(conn *Conn, line *Line) {
|
||||||
conn.Privmsg(line.Args[0], line.Args[1])
|
conn.Privmsg(line.Args[0], line.Args[1])
|
||||||
}
|
}
|
||||||
c.CommandFunc("prefix", f, "")
|
c.CommandFunc("prefix", f, "")
|
||||||
|
@ -188,7 +188,6 @@ func TestPRIVMSG(t *testing.T){
|
||||||
c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test! prefix bar"))
|
c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test! prefix bar"))
|
||||||
s.nc.ExpectNothing()
|
s.nc.ExpectNothing()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the handler for JOIN messages
|
// Test the handler for JOIN messages
|
||||||
|
@ -317,7 +316,6 @@ func TestMODE(t *testing.T) {
|
||||||
t.Errorf("Channel.ParseModes() not called correctly.")
|
t.Errorf("Channel.ParseModes() not called correctly.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send a nick mode line, returning Me
|
// Send a nick mode line, returning Me
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
s.st.EXPECT().GetChannel("test").Return(nil),
|
s.st.EXPECT().GetChannel("test").Return(nil),
|
||||||
|
|
|
@ -7,14 +7,14 @@ import (
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
l1 := &Line{
|
l1 := &Line{
|
||||||
Nick: "nick",
|
Nick: "nick",
|
||||||
Ident: "ident",
|
Ident: "ident",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Src: "src",
|
Src: "src",
|
||||||
Cmd: "cmd",
|
Cmd: "cmd",
|
||||||
Raw: "raw",
|
Raw: "raw",
|
||||||
Args: []string{"arg", "text"},
|
Args: []string{"arg", "text"},
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
l2 := l1.Copy()
|
l2 := l1.Copy()
|
||||||
|
|
|
@ -9,19 +9,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var stHandlers = map[string]HandlerFunc{
|
var stHandlers = map[string]HandlerFunc{
|
||||||
"JOIN": (*Conn).h_JOIN,
|
"JOIN": (*Conn).h_JOIN,
|
||||||
"KICK": (*Conn).h_KICK,
|
"KICK": (*Conn).h_KICK,
|
||||||
"MODE": (*Conn).h_MODE,
|
"MODE": (*Conn).h_MODE,
|
||||||
"NICK": (*Conn).h_STNICK,
|
"NICK": (*Conn).h_STNICK,
|
||||||
"PART": (*Conn).h_PART,
|
"PART": (*Conn).h_PART,
|
||||||
"QUIT": (*Conn).h_QUIT,
|
"QUIT": (*Conn).h_QUIT,
|
||||||
"TOPIC": (*Conn).h_TOPIC,
|
"TOPIC": (*Conn).h_TOPIC,
|
||||||
"311": (*Conn).h_311,
|
"311": (*Conn).h_311,
|
||||||
"324": (*Conn).h_324,
|
"324": (*Conn).h_324,
|
||||||
"332": (*Conn).h_332,
|
"332": (*Conn).h_332,
|
||||||
"352": (*Conn).h_352,
|
"352": (*Conn).h_352,
|
||||||
"353": (*Conn).h_353,
|
"353": (*Conn).h_353,
|
||||||
"671": (*Conn).h_671,
|
"671": (*Conn).h_671,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Conn) addSTHandlers() {
|
func (conn *Conn) addSTHandlers() {
|
||||||
|
|
Loading…
Reference in New Issue