From e9c704eff56e600c4666bda417d9a87d3fafd3f9 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Sat, 22 Jun 2019 11:24:14 +0200 Subject: [PATCH] Fix router after #62 merge --- router.go | 5 ++--- router_test.go | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/router.go b/router.go index 5264a95..79837a6 100644 --- a/router.go +++ b/router.go @@ -155,8 +155,7 @@ func (r *Route) Packet(name string) *Route { type nsTypeMatcher []string func (m nsTypeMatcher) Match(p Packet, match *RouteMatch) bool { - // TODO: Rework after merge of #62 - var stanzaType string + var stanzaType StanzaType switch packet := p.(type) { case IQ: stanzaType = packet.Type @@ -172,7 +171,7 @@ func (m nsTypeMatcher) Match(p Packet, match *RouteMatch) bool { default: return false } - return matchInArray(m, stanzaType) + return matchInArray(m, string(stanzaType)) } // IQNamespaces adds an IQ matcher, expecting both an IQ and a diff --git a/router_test.go b/router_test.go index 02ff2b1..7da1218 100644 --- a/router_test.go +++ b/router_test.go @@ -83,7 +83,7 @@ func TestTypeMatcher(t *testing.T) { // Check that a packet with the proper type matches conn := NewSenderMock() - message := xmpp.NewMessage("normal", "", "test@localhost", "1", "") + message := xmpp.NewMessage(xmpp.Attrs{Type: "normal", To: "test@localhost", Id: "1"}) message.Body = "hello" router.Route(conn, message) @@ -93,7 +93,7 @@ func TestTypeMatcher(t *testing.T) { // We should match on default type 'normal' for message without a type conn = NewSenderMock() - message = xmpp.NewMessage("", "", "test@localhost", "1", "") + message = xmpp.NewMessage(xmpp.Attrs{To: "test@localhost", Id: "1"}) message.Body = "hello" router.Route(conn, message) @@ -103,7 +103,7 @@ func TestTypeMatcher(t *testing.T) { // We do not match on other types conn = NewSenderMock() - iqVersion := xmpp.NewIQ("get", "service.localhost", "test@localhost", "1", "") + iqVersion := xmpp.NewIQ(xmpp.Attrs{Type: "get", From: "service.localhost", To: "test@localhost", Id: "1"}) iqVersion.Payload = &xmpp.DiscoInfo{ XMLName: xml.Name{ Space: "jabber:iq:version", @@ -126,28 +126,28 @@ func TestCompositeMatcher(t *testing.T) { }) // Data set - getVersionIq := xmpp.NewIQ("get", "service.localhost", "test@localhost", "1", "") + getVersionIq := xmpp.NewIQ(xmpp.Attrs{Type: "get", From: "service.localhost", To: "test@localhost", Id: "1"}) getVersionIq.Payload = &xmpp.Version{ XMLName: xml.Name{ Space: "jabber:iq:version", Local: "query", }} - setVersionIq := xmpp.NewIQ("set", "service.localhost", "test@localhost", "1", "") + setVersionIq := xmpp.NewIQ(xmpp.Attrs{Type: "set", From: "service.localhost", To: "test@localhost", Id: "1"}) setVersionIq.Payload = &xmpp.Version{ XMLName: xml.Name{ Space: "jabber:iq:version", Local: "query", }} - GetDiscoIq := xmpp.NewIQ("get", "service.localhost", "test@localhost", "1", "") + GetDiscoIq := xmpp.NewIQ(xmpp.Attrs{Type: "get", From: "service.localhost", To: "test@localhost", Id: "1"}) GetDiscoIq.Payload = &xmpp.DiscoInfo{ XMLName: xml.Name{ Space: "http://jabber.org/protocol/disco#info", Local: "query", }} - message := xmpp.NewMessage("normal", "", "test@localhost", "1", "") + message := xmpp.NewMessage(xmpp.Attrs{Type: "normal", To: "test@localhost", Id: "1"}) message.Body = "hello" tests := []struct { @@ -186,7 +186,7 @@ func TestCatchallMatcher(t *testing.T) { // Check that we match on several packets conn := NewSenderMock() - message := xmpp.NewMessage("chat", "", "test@localhost", "1", "") + message := xmpp.NewMessage(xmpp.Attrs{Type: "chat", To: "test@localhost", Id: "1"}) message.Body = "hello" router.Route(conn, message) @@ -195,7 +195,7 @@ func TestCatchallMatcher(t *testing.T) { } conn = NewSenderMock() - iqVersion := xmpp.NewIQ("get", "service.localhost", "test@localhost", "1", "") + iqVersion := xmpp.NewIQ(xmpp.Attrs{Type: "get", From: "service.localhost", To: "test@localhost", Id: "1"}) iqVersion.Payload = &xmpp.DiscoInfo{ XMLName: xml.Name{ Space: "jabber:iq:version",