Merge pull request #35 from slingamn/example_update
update examples, run gofmt
This commit is contained in:
commit
c8d87a2fa8
4
Makefile
4
Makefile
@ -9,9 +9,11 @@ test:
|
||||
$(info Note: ircevent must be tested separately)
|
||||
./.check-gofmt.sh
|
||||
|
||||
# ircevent requires a local ircd for testing, plus some env vars
|
||||
# ircevent requires a local ircd for testing, plus some env vars:
|
||||
# IRCEVENT_SASL_LOGIN and IRCEVENT_SASL_PASSWORD
|
||||
ircevent:
|
||||
cd ircevent && go test . && go vet .
|
||||
./.check-gofmt.sh
|
||||
|
||||
gofmt:
|
||||
./.check-gofmt.sh --fix
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -19,16 +20,20 @@ func getenv(key, defaultValue string) (value string) {
|
||||
|
||||
func main() {
|
||||
nick := getenv("IRCEVENT_NICK", "robot")
|
||||
server := getenv("IRCEVENT_SERVER", "localhost:6697")
|
||||
server := getenv("IRCEVENT_SERVER", "testnet.oragono.io:6697")
|
||||
channel := getenv("IRCEVENT_CHANNEL", "#ircevent-test")
|
||||
saslLogin := os.Getenv("IRCEVENT_SASL_LOGIN")
|
||||
saslPassword := os.Getenv("IRCEVENT_SASL_PASSWORD")
|
||||
|
||||
irc := &ircevent.Connection{
|
||||
Server: server,
|
||||
Nick: nick,
|
||||
Debug: true,
|
||||
UseTLS: true,
|
||||
TLSConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
RequestCaps: []string{"server-time", "message-tags"},
|
||||
Server: server,
|
||||
Nick: nick,
|
||||
Debug: true,
|
||||
UseTLS: true,
|
||||
TLSConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
RequestCaps: []string{"server-time", "message-tags"},
|
||||
SASLLogin: saslLogin, // SASL will be enabled automatically if these are set
|
||||
SASLPassword: saslPassword,
|
||||
}
|
||||
|
||||
irc.AddCallback("001", func(e ircevent.Event) { irc.Join(channel) })
|
||||
@ -63,7 +68,7 @@ func main() {
|
||||
})
|
||||
err := irc.Connect()
|
||||
if err != nil {
|
||||
return
|
||||
log.Fatal(err)
|
||||
}
|
||||
irc.Loop()
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func main() {
|
||||
})
|
||||
err := irc.Connect()
|
||||
if err != nil {
|
||||
return
|
||||
log.Fatal(err)
|
||||
}
|
||||
irc.Loop()
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func (irc *Connection) processTick(tick int) {
|
||||
return
|
||||
}
|
||||
pingModulus := int(irc.KeepAlive / irc.Timeout)
|
||||
if tick % pingModulus == 0 {
|
||||
if tick%pingModulus == 0 {
|
||||
shouldPing = true
|
||||
irc.pingSent = true
|
||||
if irc.currentNick != irc.Nick {
|
||||
@ -664,7 +664,7 @@ func (irc *Connection) negotiateCaps() error {
|
||||
case <-timer.C:
|
||||
// The server probably doesn't implement CAP LS, which is "normal".
|
||||
return nil
|
||||
case <- irc.end:
|
||||
case <-irc.end:
|
||||
return ServerDisconnected
|
||||
}
|
||||
}
|
||||
@ -678,7 +678,7 @@ func (irc *Connection) negotiateCaps() error {
|
||||
case <-time.After(CAPTimeout):
|
||||
// Raise an error if we can't authenticate with SASL.
|
||||
return SASLFailed
|
||||
case <- irc.end:
|
||||
case <-irc.end:
|
||||
return ServerDisconnected
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,17 @@ import (
|
||||
|
||||
const (
|
||||
serverEnvVar = "IRCEVENT_SERVER"
|
||||
saslEnvVar = "IRCEVENT_SASL_LOGIN"
|
||||
saslAccVar = "IRCEVENT_SASL_LOGIN"
|
||||
saslPassVar = "IRCEVENT_SASL_PASSWORD"
|
||||
)
|
||||
|
||||
func getSaslCreds() (account, password string) {
|
||||
return os.Getenv(saslEnvVar), os.Getenv(saslPassVar)
|
||||
func setSaslTestCreds(irc *Connection, t *testing.T) {
|
||||
acc := os.Getenv(saslAccVar)
|
||||
if acc == "" {
|
||||
t.Fatalf("define %s and %s environment variables to test SASL", saslAccVar, saslPassVar)
|
||||
}
|
||||
irc.SASLLogin = acc
|
||||
irc.SASLPassword = os.Getenv(saslPassVar)
|
||||
}
|
||||
|
||||
func getenv(key, defaultValue string) (value string) {
|
||||
@ -35,20 +40,11 @@ func getServer(sasl bool) string {
|
||||
|
||||
// set SASLLogin and SASLPassword environment variables before testing
|
||||
func runCAPTest(caps []string, useSASL bool, t *testing.T) {
|
||||
SASLLogin, SASLPassword := getSaslCreds()
|
||||
if useSASL {
|
||||
if SASLLogin == "" {
|
||||
t.Skip("Define SASLLogin and SASLPasword environment varables to test SASL")
|
||||
}
|
||||
}
|
||||
|
||||
irccon := connForTesting("go-eventirc", "go-eventirc", true)
|
||||
irccon.Debug = true
|
||||
irccon.UseTLS = true
|
||||
if useSASL {
|
||||
irccon.UseSASL = true
|
||||
irccon.SASLLogin = SASLLogin
|
||||
irccon.SASLPassword = SASLPassword
|
||||
setSaslTestCreds(irccon, t)
|
||||
}
|
||||
irccon.RequestCaps = caps
|
||||
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
|
@ -52,16 +52,16 @@ type Connection struct {
|
||||
AllowPanic bool // if set, don't recover() from panics in callbacks
|
||||
|
||||
// networking and synchronization
|
||||
stateMutex sync.Mutex // innermost mutex: don't block while holding this
|
||||
end chan empty // closing this causes the goroutines to exit (think threading.Event)
|
||||
pwrite chan []byte // receives IRC lines to be sent to the socket
|
||||
wg sync.WaitGroup // after closing end, wait on this for all the goroutines to stop
|
||||
socket net.Conn
|
||||
lastError error
|
||||
quitAt time.Time // time Quit() was called
|
||||
running bool // is a connection active? is `end` open?
|
||||
quit bool // user called Quit, do not reconnect
|
||||
pingSent bool // we sent PING and are waiting for PONG
|
||||
stateMutex sync.Mutex // innermost mutex: don't block while holding this
|
||||
end chan empty // closing this causes the goroutines to exit (think threading.Event)
|
||||
pwrite chan []byte // receives IRC lines to be sent to the socket
|
||||
wg sync.WaitGroup // after closing end, wait on this for all the goroutines to stop
|
||||
socket net.Conn
|
||||
lastError error
|
||||
quitAt time.Time // time Quit() was called
|
||||
running bool // is a connection active? is `end` open?
|
||||
quit bool // user called Quit, do not reconnect
|
||||
pingSent bool // we sent PING and are waiting for PONG
|
||||
|
||||
// IRC protocol connection state
|
||||
currentNick string // nickname assigned by the server, empty before registration
|
||||
|
@ -196,15 +196,8 @@ func runReconnectTest(useSASL bool, t *testing.T) {
|
||||
ircnick1 := randStr(8)
|
||||
irccon := connForTesting(ircnick1, "IRCTestRe", false)
|
||||
irccon.ReconnectFreq = time.Second * 1
|
||||
saslLogin, saslPassword := getSaslCreds()
|
||||
if useSASL {
|
||||
if saslLogin == "" {
|
||||
t.Skip("Define SASL environment varables to test SASL")
|
||||
} else {
|
||||
irccon.UseSASL = true
|
||||
irccon.SASLLogin = saslLogin
|
||||
irccon.SASLPassword = saslPassword
|
||||
}
|
||||
setSaslTestCreds(irccon, t)
|
||||
}
|
||||
debugTest(irccon)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user