mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-12-12 03:42:02 -08:00
Fix router after #62 merge
This commit is contained in:
parent
d9fdff0839
commit
e9c704eff5
@ -155,8 +155,7 @@ func (r *Route) Packet(name string) *Route {
|
|||||||
type nsTypeMatcher []string
|
type nsTypeMatcher []string
|
||||||
|
|
||||||
func (m nsTypeMatcher) Match(p Packet, match *RouteMatch) bool {
|
func (m nsTypeMatcher) Match(p Packet, match *RouteMatch) bool {
|
||||||
// TODO: Rework after merge of #62
|
var stanzaType StanzaType
|
||||||
var stanzaType string
|
|
||||||
switch packet := p.(type) {
|
switch packet := p.(type) {
|
||||||
case IQ:
|
case IQ:
|
||||||
stanzaType = packet.Type
|
stanzaType = packet.Type
|
||||||
@ -172,7 +171,7 @@ func (m nsTypeMatcher) Match(p Packet, match *RouteMatch) bool {
|
|||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return matchInArray(m, stanzaType)
|
return matchInArray(m, string(stanzaType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IQNamespaces adds an IQ matcher, expecting both an IQ and a
|
// IQNamespaces adds an IQ matcher, expecting both an IQ and a
|
||||||
|
@ -83,7 +83,7 @@ func TestTypeMatcher(t *testing.T) {
|
|||||||
|
|
||||||
// Check that a packet with the proper type matches
|
// Check that a packet with the proper type matches
|
||||||
conn := NewSenderMock()
|
conn := NewSenderMock()
|
||||||
message := xmpp.NewMessage("normal", "", "test@localhost", "1", "")
|
message := xmpp.NewMessage(xmpp.Attrs{Type: "normal", To: "test@localhost", Id: "1"})
|
||||||
message.Body = "hello"
|
message.Body = "hello"
|
||||||
router.Route(conn, message)
|
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
|
// We should match on default type 'normal' for message without a type
|
||||||
conn = NewSenderMock()
|
conn = NewSenderMock()
|
||||||
message = xmpp.NewMessage("", "", "test@localhost", "1", "")
|
message = xmpp.NewMessage(xmpp.Attrs{To: "test@localhost", Id: "1"})
|
||||||
message.Body = "hello"
|
message.Body = "hello"
|
||||||
router.Route(conn, message)
|
router.Route(conn, message)
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ func TestTypeMatcher(t *testing.T) {
|
|||||||
|
|
||||||
// We do not match on other types
|
// We do not match on other types
|
||||||
conn = NewSenderMock()
|
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{
|
iqVersion.Payload = &xmpp.DiscoInfo{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: "jabber:iq:version",
|
Space: "jabber:iq:version",
|
||||||
@ -126,28 +126,28 @@ func TestCompositeMatcher(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Data set
|
// 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{
|
getVersionIq.Payload = &xmpp.Version{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: "jabber:iq:version",
|
Space: "jabber:iq:version",
|
||||||
Local: "query",
|
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{
|
setVersionIq.Payload = &xmpp.Version{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: "jabber:iq:version",
|
Space: "jabber:iq:version",
|
||||||
Local: "query",
|
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{
|
GetDiscoIq.Payload = &xmpp.DiscoInfo{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: "http://jabber.org/protocol/disco#info",
|
Space: "http://jabber.org/protocol/disco#info",
|
||||||
Local: "query",
|
Local: "query",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
message := xmpp.NewMessage("normal", "", "test@localhost", "1", "")
|
message := xmpp.NewMessage(xmpp.Attrs{Type: "normal", To: "test@localhost", Id: "1"})
|
||||||
message.Body = "hello"
|
message.Body = "hello"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -186,7 +186,7 @@ func TestCatchallMatcher(t *testing.T) {
|
|||||||
|
|
||||||
// Check that we match on several packets
|
// Check that we match on several packets
|
||||||
conn := NewSenderMock()
|
conn := NewSenderMock()
|
||||||
message := xmpp.NewMessage("chat", "", "test@localhost", "1", "")
|
message := xmpp.NewMessage(xmpp.Attrs{Type: "chat", To: "test@localhost", Id: "1"})
|
||||||
message.Body = "hello"
|
message.Body = "hello"
|
||||||
router.Route(conn, message)
|
router.Route(conn, message)
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ func TestCatchallMatcher(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn = NewSenderMock()
|
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{
|
iqVersion.Payload = &xmpp.DiscoInfo{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: "jabber:iq:version",
|
Space: "jabber:iq:version",
|
||||||
|
Loading…
Reference in New Issue
Block a user