Compare commits
16 Commits
fix_bad_la
...
test_cover
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0e07999cb2 | ||
![]() |
79c60eafaf | ||
![]() |
0ec9aaa5eb | ||
![]() |
90910a20b1 | ||
![]() |
43e4726461 | ||
![]() |
493b58459d | ||
![]() |
d53b08b3a0 | ||
![]() |
8ba7a2c1e2 | ||
![]() |
aed917ea2f | ||
![]() |
94bbfe4baf | ||
![]() |
8732f70630 | ||
![]() |
b7f798d600 | ||
![]() |
caab002d51 | ||
![]() |
7ff892bba9 | ||
![]() |
233238b709 | ||
![]() |
59e0792db1 |
@@ -6,9 +6,15 @@ pipeline:
|
|||||||
build:
|
build:
|
||||||
image: golang
|
image: golang
|
||||||
commands:
|
commands:
|
||||||
- go get -d
|
- go get -d ./...
|
||||||
- go build .
|
- go build .
|
||||||
|
|
||||||
|
test:
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- go get -d ./...
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
repo: r.mills.io/prologic/eris
|
repo: r.mills.io/prologic/eris
|
||||||
|
18
.gitmodules
vendored
18
.gitmodules
vendored
@@ -43,9 +43,15 @@
|
|||||||
[submodule "vendor/github.com/prometheus/procfs"]
|
[submodule "vendor/github.com/prometheus/procfs"]
|
||||||
path = vendor/github.com/prometheus/procfs
|
path = vendor/github.com/prometheus/procfs
|
||||||
url = https://github.com/prometheus/procfs
|
url = https://github.com/prometheus/procfs
|
||||||
[submodule "vendor/github.com/sasha-s/go-deadlock"]
|
[submodule "vendor/github.com/thoj/go-ircevent"]
|
||||||
path = vendor/github.com/sasha-s/go-deadlock
|
path = vendor/github.com/thoj/go-ircevent
|
||||||
url = https://github.com/sasha-s/go-deadlock
|
url = https://github.com/thoj/go-ircevent
|
||||||
[submodule "vendor/github.com/petermattis/goid"]
|
[submodule "vendor/github.com/stretchr/testify"]
|
||||||
path = vendor/github.com/petermattis/goid
|
path = vendor/github.com/stretchr/testify
|
||||||
url = https://github.com/petermattis/goid
|
url = https://github.com/stretchr/testify
|
||||||
|
[submodule "vendor/github.com/renstrom/shortuuid"]
|
||||||
|
path = vendor/github.com/renstrom/shortuuid
|
||||||
|
url = https://github.com/renstrom/shortuuid
|
||||||
|
[submodule "vendor/github.com/satori/go.uuid"]
|
||||||
|
path = vendor/github.com/satori/go.uuid
|
||||||
|
url = https://github.com/satori/go.uuid
|
||||||
|
@@ -72,8 +72,14 @@ func NewClient(server *Server, conn net.Conn) *Client {
|
|||||||
//
|
//
|
||||||
|
|
||||||
func (client *Client) writeloop() {
|
func (client *Client) writeloop() {
|
||||||
for reply := range client.replies {
|
for {
|
||||||
client.socket.Write(reply)
|
select {
|
||||||
|
case reply, ok := <-client.replies:
|
||||||
|
if !ok || reply == "" || client.socket == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
client.socket.Write(reply)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,13 +125,6 @@ func (client *Client) readloop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) processCommand(cmd Command) {
|
func (client *Client) processCommand(cmd Command) {
|
||||||
client.server.metrics.Counter("client", "commands").Inc()
|
|
||||||
|
|
||||||
defer func(t time.Time) {
|
|
||||||
v := client.server.metrics.SummaryVec("client", "command_duration_seconds")
|
|
||||||
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
|
|
||||||
}(time.Now())
|
|
||||||
|
|
||||||
cmd.SetClient(client)
|
cmd.SetClient(client)
|
||||||
|
|
||||||
if !client.registered {
|
if !client.registered {
|
||||||
@@ -144,6 +143,13 @@ func (client *Client) processCommand(cmd Command) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.server.metrics.Counter("client", "commands").Inc()
|
||||||
|
|
||||||
|
defer func(t time.Time) {
|
||||||
|
v := client.server.metrics.SummaryVec("client", "command_duration_seconds")
|
||||||
|
v.WithLabelValues(cmd.Code().String()).Observe(time.Now().Sub(t).Seconds())
|
||||||
|
}(time.Now())
|
||||||
|
|
||||||
switch srvCmd.(type) {
|
switch srvCmd.(type) {
|
||||||
case *PingCommand, *PongCommand:
|
case *PingCommand, *PongCommand:
|
||||||
client.Touch()
|
client.Touch()
|
||||||
|
@@ -4,9 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
|
|
||||||
"github.com/DanielOaks/girc-go/ircmatch"
|
"github.com/DanielOaks/girc-go/ircmatch"
|
||||||
)
|
)
|
||||||
|
@@ -4,9 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@@ -4,9 +4,8 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -2,9 +2,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SaslState struct {
|
type SaslState struct {
|
||||||
|
@@ -202,6 +202,10 @@ func (server *Server) Shutdown() {
|
|||||||
server.Global("shutting down...")
|
server.Global("shutting down...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (server *Server) Stop() {
|
||||||
|
server.done <- true
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) Run() {
|
func (server *Server) Run() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -212,7 +216,7 @@ func (server *Server) Run() {
|
|||||||
// Give at least 1s for clients to see the shutdown
|
// Give at least 1s for clients to see the shutdown
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
server.done <- true
|
server.Stop()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
case conn := <-server.newConns:
|
case conn := <-server.newConns:
|
||||||
|
@@ -3,9 +3,7 @@ package irc
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@@ -9,7 +9,7 @@ var (
|
|||||||
Package = "eris"
|
Package = "eris"
|
||||||
|
|
||||||
// Version release version
|
// Version release version
|
||||||
Version = "1.6.3"
|
Version = "1.6.4"
|
||||||
|
|
||||||
// Build will be overwritten automatically by the build system
|
// Build will be overwritten automatically by the build system
|
||||||
Build = "dev"
|
Build = "dev"
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"sync"
|
"sync"
|
||||||
|
|
||||||
sync "github.com/sasha-s/go-deadlock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type WhoWasList struct {
|
type WhoWasList struct {
|
||||||
|
529
main_test.go
Normal file
529
main_test.go
Normal file
@@ -0,0 +1,529 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/renstrom/shortuuid"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/thoj/go-ircevent"
|
||||||
|
|
||||||
|
eris "github.com/prologic/eris/irc"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TIMEOUT = 3 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
server *eris.Server
|
||||||
|
|
||||||
|
debug = flag.Bool("d", false, "enable debug logging")
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupServer() *eris.Server {
|
||||||
|
config := &eris.Config{}
|
||||||
|
|
||||||
|
config.Network.Name = "Test"
|
||||||
|
config.Server.Name = "test"
|
||||||
|
config.Server.Description = "Test"
|
||||||
|
config.Server.Listen = []string{":6667"}
|
||||||
|
|
||||||
|
// SASL
|
||||||
|
config.Account = map[string]*eris.PassConfig{
|
||||||
|
"admin": &eris.PassConfig{"JDJhJDA0JGtUU1JVc1JOUy9DbEh1WEdvYVlMdGVnclp6YnA3NDBOZGY1WUZhdTZtRzVmb1VKdXQ5ckZD"},
|
||||||
|
}
|
||||||
|
|
||||||
|
server := eris.NewServer(config)
|
||||||
|
|
||||||
|
go server.Run()
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomValidName() string {
|
||||||
|
var name eris.Name
|
||||||
|
for {
|
||||||
|
name = eris.NewName(shortuuid.New())
|
||||||
|
if name.IsNickname() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func newClient(start bool) *irc.Connection {
|
||||||
|
name := randomValidName()
|
||||||
|
client := irc.IRC(name, name)
|
||||||
|
client.RealName = fmt.Sprintf("Test Client: %s", name)
|
||||||
|
|
||||||
|
err := client.Connect("localhost:6667")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error setting up test client: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if start {
|
||||||
|
go client.Loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *debug {
|
||||||
|
log.SetLevel(log.DebugLevel)
|
||||||
|
} else {
|
||||||
|
log.SetLevel(log.WarnLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
server = setupServer()
|
||||||
|
|
||||||
|
result := m.Run()
|
||||||
|
|
||||||
|
server.Stop()
|
||||||
|
|
||||||
|
os.Exit(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConnection(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected bool
|
||||||
|
actual chan bool
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = true
|
||||||
|
actual = make(chan bool)
|
||||||
|
|
||||||
|
client := newClient(false)
|
||||||
|
|
||||||
|
client.AddCallback("001", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client.Quit()
|
||||||
|
go client.Loop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSASL(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
expected := true
|
||||||
|
actual := make(chan bool)
|
||||||
|
|
||||||
|
client := newClient(false)
|
||||||
|
client.SASLLogin = "admin"
|
||||||
|
client.SASLPassword = "admin"
|
||||||
|
|
||||||
|
client.AddCallback("001", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client.Quit()
|
||||||
|
go client.Loop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRplWelcome(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected string
|
||||||
|
actual chan string
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = "Welcome to the .* Internet Relay Network .*!.*@.*"
|
||||||
|
actual = make(chan string)
|
||||||
|
|
||||||
|
client := newClient(false)
|
||||||
|
|
||||||
|
client.AddCallback("001", func(e *irc.Event) {
|
||||||
|
actual <- e.Message()
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client.Quit()
|
||||||
|
go client.Loop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Regexp(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUser_JOIN(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected []string
|
||||||
|
actual chan string
|
||||||
|
)
|
||||||
|
|
||||||
|
actual = make(chan string)
|
||||||
|
|
||||||
|
client := newClient(true)
|
||||||
|
|
||||||
|
client.AddCallback("001", func(e *irc.Event) {
|
||||||
|
expected = []string{e.Arguments[0], "=", "#join", fmt.Sprintf("@%s", e.Arguments[0])}
|
||||||
|
})
|
||||||
|
client.AddCallback("353", func(e *irc.Event) {
|
||||||
|
for i := range e.Arguments {
|
||||||
|
actual <- e.Arguments[i]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client.Quit()
|
||||||
|
|
||||||
|
client.Join("#join")
|
||||||
|
client.SendRaw("NAMES #join")
|
||||||
|
|
||||||
|
for i := range expected {
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected[i], res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_InviteOnly(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected bool
|
||||||
|
actual chan bool
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = true
|
||||||
|
actual = make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("324", func(e *irc.Event) {
|
||||||
|
if strings.Contains(e.Arguments[2], "i") {
|
||||||
|
client2.Join("#inviteonly")
|
||||||
|
} else {
|
||||||
|
client1.Mode("#inviteonly")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.AddCallback("473", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
actual <- false
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.Join("#inviteonly")
|
||||||
|
client1.Mode("#inviteonly", "+i")
|
||||||
|
client1.Mode("#inviteonly")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUser_PRIVMSG(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected string
|
||||||
|
actual chan string
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = "Hello World!"
|
||||||
|
actual = make(chan string)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("001", func(e *irc.Event) {
|
||||||
|
client1.Privmsg(client2.GetNick(), expected)
|
||||||
|
|
||||||
|
})
|
||||||
|
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
actual <- e.Message()
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.AddCallback("001", func(e *irc.Event) {
|
||||||
|
client2.Privmsg(client1.GetNick(), expected)
|
||||||
|
})
|
||||||
|
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
actual <- e.Message()
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_PRIVMSG(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected string
|
||||||
|
actual chan string
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = "Hello World!"
|
||||||
|
actual = make(chan string)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
client1.Privmsg(e.Arguments[0], expected)
|
||||||
|
})
|
||||||
|
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
client2.Privmsg(e.Arguments[0], expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
client1.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
actual <- e.Message()
|
||||||
|
})
|
||||||
|
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
actual <- e.Message()
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.Join("#channelprivmsg")
|
||||||
|
client2.Join("#channelprivmsg")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_NoExternal(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected bool
|
||||||
|
actual chan bool
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = true
|
||||||
|
actual = make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
channel := e.Arguments[0]
|
||||||
|
if channel == "#noexternal" {
|
||||||
|
if e.Nick == client1.GetNick() {
|
||||||
|
client2.Privmsg("#noexternal", "FooBar!")
|
||||||
|
} else {
|
||||||
|
assert.Fail(fmt.Sprintf("unexpected user %s joined %s", e.Nick, channel))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert.Fail(fmt.Sprintf("unexpected channel %s", channel))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||||
|
if e.Arguments[0] == "#noexternal" {
|
||||||
|
actual <- false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
client2.AddCallback("404", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.Join("#noexternal")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_SetTopic_InvalidChannel(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
expected := true
|
||||||
|
actual := make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
defer client1.Quit()
|
||||||
|
|
||||||
|
client1.AddCallback("403", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
|
||||||
|
client1.SendRaw("TOPIC #invalidchannel :FooBar")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_SetTopic_NotOnChannel(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
expected := true
|
||||||
|
actual := make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.AddCallback("442", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
client1.SendRaw("TOPIC #notonchannel :FooBar")
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.Join("#notonchannel")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_BadChannelKey(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected bool
|
||||||
|
actual chan bool
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = true
|
||||||
|
actual = make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("324", func(e *irc.Event) {
|
||||||
|
if strings.Contains(e.Arguments[2], "k") {
|
||||||
|
client2.Join(e.Arguments[1])
|
||||||
|
} else {
|
||||||
|
client1.Mode("#badchannelkey")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
if e.Nick == client2.GetNick() && e.Arguments[0] == "#badchannelkey" {
|
||||||
|
actual <- false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
client2.AddCallback("475", func(e *irc.Event) {
|
||||||
|
actual <- true
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.Join("#badchannelkey")
|
||||||
|
client1.Mode("#badchannelkey", "+k", "opensesame")
|
||||||
|
client1.Mode("#badchannelkey")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChannel_GoodChannelKey(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expected bool
|
||||||
|
actual chan bool
|
||||||
|
)
|
||||||
|
|
||||||
|
expected = true
|
||||||
|
actual = make(chan bool)
|
||||||
|
|
||||||
|
client1 := newClient(true)
|
||||||
|
client2 := newClient(true)
|
||||||
|
|
||||||
|
client1.AddCallback("324", func(e *irc.Event) {
|
||||||
|
if strings.Contains(e.Arguments[2], "k") {
|
||||||
|
client2.SendRawf("JOIN %s :opensesame", e.Arguments[1])
|
||||||
|
} else {
|
||||||
|
client1.Mode("#goodchannelkey")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client2.AddCallback("JOIN", func(e *irc.Event) {
|
||||||
|
if e.Nick == client2.GetNick() && e.Arguments[0] == "#goodchannelkey" {
|
||||||
|
actual <- true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
client2.AddCallback("475", func(e *irc.Event) {
|
||||||
|
actual <- false
|
||||||
|
})
|
||||||
|
|
||||||
|
defer client1.Quit()
|
||||||
|
defer client2.Quit()
|
||||||
|
|
||||||
|
client1.Join("#goodchannelkey")
|
||||||
|
client1.Mode("#goodchannelkey", "+k", "opensesame")
|
||||||
|
client1.Mode("#goodchannelkey")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case res := <-actual:
|
||||||
|
assert.Equal(expected, res)
|
||||||
|
case <-time.After(TIMEOUT):
|
||||||
|
assert.Fail("timeout")
|
||||||
|
}
|
||||||
|
}
|
1
vendor/github.com/petermattis/goid
generated
vendored
1
vendor/github.com/petermattis/goid
generated
vendored
Submodule vendor/github.com/petermattis/goid deleted from 3db12ebb2a
2
vendor/github.com/prometheus/client_golang
generated
vendored
2
vendor/github.com/prometheus/client_golang
generated
vendored
Submodule vendor/github.com/prometheus/client_golang updated: 1cdba8fdde...661e31bf84
1
vendor/github.com/renstrom/shortuuid
generated
vendored
Submodule
1
vendor/github.com/renstrom/shortuuid
generated
vendored
Submodule
Submodule vendor/github.com/renstrom/shortuuid added at d728e00b72
1
vendor/github.com/sasha-s/go-deadlock
generated
vendored
1
vendor/github.com/sasha-s/go-deadlock
generated
vendored
Submodule vendor/github.com/sasha-s/go-deadlock deleted from 565eb44395
1
vendor/github.com/satori/go.uuid
generated
vendored
Submodule
1
vendor/github.com/satori/go.uuid
generated
vendored
Submodule
Submodule vendor/github.com/satori/go.uuid added at 5bf94b69c6
1
vendor/github.com/stretchr/testify
generated
vendored
Submodule
1
vendor/github.com/stretchr/testify
generated
vendored
Submodule
Submodule vendor/github.com/stretchr/testify added at 2aa2c176b9
1
vendor/github.com/thoj/go-ircevent
generated
vendored
Submodule
1
vendor/github.com/thoj/go-ircevent
generated
vendored
Submodule
Submodule vendor/github.com/thoj/go-ircevent added at db5bd176f7
2
vendor/golang.org/x/crypto
generated
vendored
2
vendor/golang.org/x/crypto
generated
vendored
Submodule vendor/golang.org/x/crypto updated: b080dc9a8c...94eea52f7b
2
vendor/golang.org/x/sys
generated
vendored
2
vendor/golang.org/x/sys
generated
vendored
Submodule vendor/golang.org/x/sys updated: 4ff8c001ce...8b4580aae2
2
vendor/golang.org/x/text
generated
vendored
2
vendor/golang.org/x/text
generated
vendored
Submodule vendor/golang.org/x/text updated: 88f656faf3...556d234e9c
Reference in New Issue
Block a user