Fix router after #62 merge

disco_info_form
Mickael Remond 5 years ago
parent d9fdff0839
commit e9c704eff5
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3

@ -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

@ -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",

Loading…
Cancel
Save