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
|
2019-06-02 10:41:19 +02:00
|
|
|
p, _ := c.receiving(xmpp.Handshake{})
|
2019-06-01 04:38:35 +02:00
|
|
|
assert.Nil(p)
|
|
|
|
|
|
|
|
// receive presence
|
2019-06-02 10:41:19 +02:00
|
|
|
p, _ = c.receiving(xmpp.Presence{})
|
2019-06-01 04:38:35 +02:00
|
|
|
assert.Nil(p)
|
|
|
|
|
|
|
|
// message
|
2019-06-02 10:41:19 +02:00
|
|
|
p, back := c.receiving(xmpp.Message{})
|
2019-06-01 04:38:35 +02:00
|
|
|
assert.False(back)
|
|
|
|
assert.NotNil(p)
|
|
|
|
|
|
|
|
// unsupported iq
|
2019-06-02 10:41:19 +02:00
|
|
|
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
|
2019-06-02 10:41:19 +02:00
|
|
|
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
|
2019-06-02 10:41:19 +02:00
|
|
|
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)
|
|
|
|
}
|