mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 10:02:00 -08:00
Add builder & test on software version helpers
This commit is contained in:
parent
0e3101c2be
commit
6872ed8d1b
@ -14,7 +14,7 @@ func TestDiscoInfo_Builder(t *testing.T) {
|
||||
disco.AddIdentity("Test Component", "gateway", "service")
|
||||
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1")
|
||||
|
||||
parsedIQ, err := marshallUnmarshall(t, iq)
|
||||
parsedIQ, err := checkMarshalling(t, iq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -57,7 +57,7 @@ func TestDiscoItems_Builder(t *testing.T) {
|
||||
AddItem("catalog.shakespeare.lit", "clothing", "Wear your literary taste with pride").
|
||||
AddItem("catalog.shakespeare.lit", "music", "Music from the time of Shakespeare")
|
||||
|
||||
parsedIQ, err := marshallUnmarshall(t, iq)
|
||||
parsedIQ, err := checkMarshalling(t, iq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -79,6 +79,12 @@ func TestDiscoItems_Builder(t *testing.T) {
|
||||
if item.JID != items[i].JID {
|
||||
t.Errorf("JID Mismatch (expected: %s): %s", items[i].JID, item.JID)
|
||||
}
|
||||
if item.Node != items[i].Node {
|
||||
t.Errorf("Node Mismatch (expected: %s): %s", items[i].JID, item.JID)
|
||||
}
|
||||
if item.Name != items[i].Name {
|
||||
t.Errorf("Name Mismatch (expected: %s): %s", items[i].JID, item.JID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,26 @@ func (v *Version) Namespace() string {
|
||||
return v.XMLName.Space
|
||||
}
|
||||
|
||||
// ---------------
|
||||
// Builder helpers
|
||||
|
||||
// Version builds a default software version payload
|
||||
func (iq *IQ) Version() *Version {
|
||||
d := Version{
|
||||
XMLName: xml.Name{Space: "jabber:iq:version", Local: "query"},
|
||||
}
|
||||
iq.Payload = &d
|
||||
return &d
|
||||
}
|
||||
|
||||
// Set all software version info
|
||||
func (v *Version) SetInfo(name, version, os string) *Version {
|
||||
v.Name = name
|
||||
v.Version = version
|
||||
v.OS = os
|
||||
return v
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Registry init
|
||||
|
||||
|
40
stanza/iq_version_test.go
Normal file
40
stanza/iq_version_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package stanza_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gosrc.io/xmpp/stanza"
|
||||
)
|
||||
|
||||
// Build a Software Version reply
|
||||
// https://xmpp.org/extensions/xep-0092.html#example-2
|
||||
func TestVersion_Builder(t *testing.T) {
|
||||
name := "Exodus"
|
||||
version := "0.7.0.4"
|
||||
os := "Windows-XP 5.01.2600"
|
||||
iq := stanza.NewIQ(stanza.Attrs{Type: "result", From: "romeo@montague.net/orchard",
|
||||
To: "juliet@capulet.com/balcony", Id: "version_1"})
|
||||
iq.Version().SetInfo(name, version, os)
|
||||
|
||||
parsedIQ, err := checkMarshalling(t, iq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Check result
|
||||
pp, ok := parsedIQ.Payload.(*stanza.Version)
|
||||
if !ok {
|
||||
t.Errorf("Parsed stanza does not contain correct IQ payload")
|
||||
}
|
||||
|
||||
// Check version info
|
||||
if pp.Name != name {
|
||||
t.Errorf("Name Mismatch (expected: %s): %s", name, pp.Name)
|
||||
}
|
||||
if pp.Version != version {
|
||||
t.Errorf("Version Mismatch (expected: %s): %s", version, pp.Version)
|
||||
}
|
||||
if pp.OS != os {
|
||||
t.Errorf("OS Mismatch (expected: %s): %s", os, pp.OS)
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import (
|
||||
// ============================================================================
|
||||
// Marshaller / unmarshaller test
|
||||
|
||||
func marshallUnmarshall(t *testing.T, iq stanza.IQ) (*stanza.IQ, error) {
|
||||
func checkMarshalling(t *testing.T, iq stanza.IQ) (*stanza.IQ, error) {
|
||||
// Marshall
|
||||
data, err := xml.Marshal(iq)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user