Пример #1
0
func TestWriteStanza(t *testing.T) {
	t.Parallel()

	var want, got []byte

	to, from := jid.New("foo@bar"), jid.New("baz@quux")
	iq := stanza.NewIQResult(to, from, "test", stanza.IQResult)
	want = iq.TransformElement().WriteBytes()
	got = make([]byte, len(want))

	read, write := net.Pipe()
	tcpTsp := NewTCP(write, stream.Receiving, nil, false)

	go func() {
		_, err := read.Read(got)
		if err != nil {
			t.Errorf("Received error while reading from connection: %s", err)
		}
	}()

	err := tcpTsp.WriteStanza(iq.TransformStanza())
	if err != nil {
		t.Errorf("Unexpected error from WriteElement: %s", err)
	}

	if !reflect.DeepEqual(want, got) {
		t.Error("Should be able to write element to TCP stream.")
		t.Errorf("\nWant:%v\nGot :%v", want, got)
	}
}
Пример #2
0
func (sh SessionHandler) HandleIQ(iq stanza.IQ, props stream.Properties) (
	[]stanza.Stanza, stream.Properties) {
	var sts []stanza.Stanza
	to := jid.New(iq.From)
	from := jid.New(iq.To)
	res := stanza.NewIQResult(to, from, iq.ID, stanza.IQResult)
	sts = append(sts, res.TransformStanza())
	return sts, props
}