mirror of
https://github.com/gissleh/irc.git
synced 2026-10-15 16:42:53 +00:00
fix query messages' echoes not being put in right target (for real this time).
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1361,9 +1361,12 @@ func (client *Client) handleEvent(event *Event) {
|
|||||||
// Target the message
|
// Target the message
|
||||||
target := Target(client.status)
|
target := Target(client.status)
|
||||||
targetName := event.Arg(0)
|
targetName := event.Arg(0)
|
||||||
|
if targetName == client.Nick() {
|
||||||
|
targetName = event.Nick
|
||||||
|
}
|
||||||
|
|
||||||
if targetName == client.nick {
|
if event.Nick == client.nick || event.Arg(0) == client.nick {
|
||||||
queryTarget := client.Target("query", event.Nick)
|
queryTarget := client.Target("query", targetName)
|
||||||
if queryTarget == nil {
|
if queryTarget == nil {
|
||||||
query := &Query{
|
query := &Query{
|
||||||
id: client.id,
|
id: client.id,
|
||||||
|
|||||||
@@ -249,8 +249,11 @@ func TestClient(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
{Client: "PRIVMSG SevenAsterisks :hi!"},
|
{Client: "PRIVMSG SevenAsterisks :hi!"},
|
||||||
{Server: ":Test768!~Tester@127.0.0.1 PRIVMSG SevenAsterisks :hi!"},
|
{Server: ":Test768!~Tester@127.0.0.1 PRIVMSG SevenAsterisks :hi!"},
|
||||||
|
{Server: "PING :testserver.example.com"}, // Ping/Pong to sync.
|
||||||
|
{Client: "PONG :testserver.example.com"},
|
||||||
{Callback: func() error {
|
{Callback: func() error {
|
||||||
event := logger.Last("packet", "PRIVMSG")
|
event := logger.Last("packet", "PRIVMSG")
|
||||||
|
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return errors.New("did not find last query message")
|
return errors.New("did not find last query message")
|
||||||
}
|
}
|
||||||
@@ -260,6 +263,12 @@ func TestClient(t *testing.T) {
|
|||||||
if event.QueryTarget().Name() != "SevenAsterisks" {
|
if event.QueryTarget().Name() != "SevenAsterisks" {
|
||||||
return errors.New("incorrect query target")
|
return errors.New("incorrect query target")
|
||||||
}
|
}
|
||||||
|
if event.Nick != client.Nick() {
|
||||||
|
return errors.New("incorrect client nick")
|
||||||
|
}
|
||||||
|
if event.Arg(0) != "SevenAsterisks" {
|
||||||
|
return errors.New("incorrect client nick")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}},
|
}},
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package irc_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gissleh/irc"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type packetTestRow struct {
|
||||||
|
Data string
|
||||||
|
Kind string
|
||||||
|
Verb string
|
||||||
|
Args []string
|
||||||
|
Text string
|
||||||
|
Tags map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
var packetTestTable = []packetTestRow{
|
||||||
|
{":test.server PING Test", "packet", "PING", []string{"Test"}, "", map[string]string{}},
|
||||||
|
{":test.server PING :Test", "packet", "PING", []string{}, "Test", map[string]string{}},
|
||||||
|
{":Test2!test@test.example.com PRIVMSG Tester :\x01ACTION hello to you.\x01", "ctcp", "ACTION", []string{"Tester"}, "hello to you.", map[string]string{}},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParsePacket(t *testing.T) {
|
||||||
|
for _, row := range packetTestTable {
|
||||||
|
t.Run(row.Data, func(t *testing.T) {
|
||||||
|
event, err := irc.ParsePacket(row.Data)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Parse Failed", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, row.Kind, event.Kind(), "kind")
|
||||||
|
assert.Equal(t, row.Verb, event.Verb(), "kind")
|
||||||
|
assert.Equal(t, row.Args, event.Args, "kind")
|
||||||
|
assert.Equal(t, row.Text, event.Text, "kind")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user