This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
thrempp/component/receiver_test.go

66 lines
1.4 KiB
Go
Raw Normal View History

2019-06-01 04:38:35 +02:00
package component
import (
"testing"
"github.com/stretchr/testify/assert"
"gosrc.io/xmpp"
)
func TestReceive(t *testing.T) {
assert := assert.New(t)
2019-06-06 21:20:51 +02:00
c := Config{Host: "example.org", Type: "monkeyservice", XMPPDebug: true}
2019-06-01 04:38:35 +02:00
// ignoring packet
p, _ := c.receiving(xmpp.Handshake{})
2019-06-01 04:38:35 +02:00
assert.Nil(p)
// receive presence
p, _ = c.receiving(xmpp.Presence{})
2019-06-01 04:38:35 +02:00
assert.Nil(p)
// message
p, back := c.receiving(xmpp.Message{})
2019-06-01 04:38:35 +02:00
assert.False(back)
assert.NotNil(p)
// unsupported iq
p, back = c.receiving(xmpp.IQ{Payload: []xmpp.IQPayload{
2019-06-01 04:38:35 +02:00
&xmpp.Err{},
}})
assert.True(back)
assert.NotNil(p)
iq := p.(xmpp.IQ)
assert.Equal("error", iq.Type)
assert.Equal("feature-not-implemented", iq.Error.Reason)
// iq disco info
p, back = c.receiving(xmpp.IQ{
2019-06-01 04:38:35 +02:00
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
Payload: []xmpp.IQPayload{
&xmpp.DiscoInfo{},
},
})
assert.True(back)
assert.NotNil(p)
iq = p.(xmpp.IQ)
assert.Equal("result", iq.Type)
dinfo := iq.Payload[0].(*xmpp.DiscoInfo)
assert.Equal("monkeyservice", dinfo.Identity.Name)
// iq disco items
p, back = c.receiving(xmpp.IQ{
2019-06-01 04:38:35 +02:00
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
Payload: []xmpp.IQPayload{
&xmpp.DiscoItems{},
},
})
assert.True(back)
assert.NotNil(p)
iq = p.(xmpp.IQ)
assert.Equal("result", iq.Type)
ditems := iq.Payload[0].(*xmpp.DiscoItems)
assert.Equal("monkeyservice", ditems.Items[0].Name)
}