~samwhited/xmpp

ref: b8d4b070f83a6621be2cfadf3a31042a1ae6ecc1 xmpp/session_test.go -rw-r--r-- 664 bytes
b8d4b070Sam Whited Add partial Send() function 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package xmpp

import (
	"bytes"
	"encoding/xml"
	"testing"
)

// ping is an XEP-0199 ping
type ping struct {
	IQ
	Ping struct{} `xml:"urn:xmpp:ping ping"`
}

func newDummySession() (*bytes.Buffer, *Session) {
	b := new(bytes.Buffer)
	s := &Session{
		rw:         b,
		features:   make(map[string]interface{}),
		negotiated: make(map[string]struct{}),
	}
	s.out.e = xml.NewEncoder(b)
	return b, s
}

func TestSendEnforcesIQSemantics(t *testing.T) {
	_, s := newDummySession()
	p := &ping{}
	err := s.Send(p)
	if err != nil {
		t.Fatal(err)
	}
	p2 := ping{}
	if *p != p2 {
		t.Fatalf("Sending mutated original struct")
	}
	// TODO: Test to make sure we set the ID
}