From d6f6207ebb3d5256256a7810a3d3d0bdc8ba04a5 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Mon, 25 Nov 2019 00:20:07 +0200 Subject: Refactoring: move SendPresence to xmpp/gateway package --- xmpp/gateway/gateway_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 xmpp/gateway/gateway_test.go (limited to 'xmpp/gateway/gateway_test.go') diff --git a/xmpp/gateway/gateway_test.go b/xmpp/gateway/gateway_test.go new file mode 100644 index 0000000..6191844 --- /dev/null +++ b/xmpp/gateway/gateway_test.go @@ -0,0 +1,54 @@ +package gateway + +import ( + "encoding/xml" + "testing" + + "gosrc.io/xmpp/stanza" +) + +func testPresence(t *testing.T, presence stanza.Presence, reference string) { + byteXML, err := xml.Marshal(presence) + if err != nil { + t.Errorf("XML parse error: %v", err) + } + xmlText := string(byteXML) + if xmlText != reference { + t.Errorf("%v does not match %v", xmlText, reference) + } +} + +func TestPresenceFrom(t *testing.T) { + presence := newPresence("from@test", "to@test", SPFrom("test")) + testPresence(t, presence, "") +} + +func TestPresenceNoFrom(t *testing.T) { + presence := newPresence("from@test", "to@test") + testPresence(t, presence, "") +} + +func TestPresenceType(t *testing.T) { + presence := newPresence("from@test", "to@test", SPType("subscribe")) + testPresence(t, presence, "") +} + +func TestPresenceShow(t *testing.T) { + presence := newPresence("from@test", "to@test", SPShow("dnd")) + testPresence(t, presence, "dnd") +} + +func TestPresenceStatus(t *testing.T) { + presence := newPresence("from@test", "to@test", SPStatus("cooking")) + testPresence(t, presence, "cooking") +} + +func TestPresenceNickname(t *testing.T) { + presence := newPresence("from@test", "to@test", SPNickname("Ishmael")) + testPresence(t, presence, "Ishmael") +} + +func TestPresencePhoto(t *testing.T) { + presence := newPresence("from@test", "to@test", SPPhoto("01b87fcd030b72895ff8e88db57ec525450f000d")) + testPresence(t, presence, "01b87fcd030b72895ff8e88db57ec525450f000d") +} -- cgit v1.2.3