From 5ed66de79e1b76a637f30e9c059452294cab2c16 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Wed, 26 Jun 2019 17:28:54 +0200 Subject: [PATCH] Fix tests after refactor --- stanza/iq_test.go | 37 +++++++++++++++++++------------------ stanza/message_test.go | 15 ++++++++------- stanza/msg_html_test.go | 12 +++++++----- stanza/msg_receipts_test.go | 6 ++++-- stanza/pres_muc_test.go | 10 ++++++---- stanza/presence_test.go | 17 +++++++++-------- 6 files changed, 53 insertions(+), 44 deletions(-) diff --git a/stanza/iq_test.go b/stanza/iq_test.go index a880192..39df2aa 100644 --- a/stanza/iq_test.go +++ b/stanza/iq_test.go @@ -6,21 +6,22 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "gosrc.io/xmpp/stanza" ) func TestUnmarshalIqs(t *testing.T) { //var cs1 = new(iot.ControlSet) var tests = []struct { iqString string - parsedIQ IQ + parsedIQ stanza.IQ }{ {"", - IQ{XMLName: xml.Name{Local: "iq"}, Attrs: Attrs{Type: IQTypeSet, To: "test@localhost", Id: "1"}}}, + stanza.IQ{XMLName: xml.Name{Local: "iq"}, Attrs: stanza.Attrs{Type: stanza.IQTypeSet, To: "test@localhost", Id: "1"}}}, //{"", IQ{XMLName: xml.Name{Space: "jabber:client", Local: "iq"}, PacketAttrs: PacketAttrs{To: "test@localhost", From: "server", Type: "set", Id: "2"}, Payload: cs1}}, } for _, test := range tests { - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} err := xml.Unmarshal([]byte(test.iqString), &parsedIQ) if err != nil { t.Errorf("Unmarshal(%s) returned error", test.iqString) @@ -34,16 +35,16 @@ func TestUnmarshalIqs(t *testing.T) { } func TestGenerateIq(t *testing.T) { - iq := NewIQ(Attrs{Type: IQTypeResult, From: "admin@localhost", To: "test@localhost", Id: "1"}) - payload := DiscoInfo{ - Identity: Identity{ + iq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeResult, From: "admin@localhost", To: "test@localhost", Id: "1"}) + payload := stanza.DiscoInfo{ + Identity: stanza.Identity{ Name: "Test Gateway", Category: "gateway", Type: "mqtt", }, - Features: []Feature{ - {Var: NSDiscoInfo}, - {Var: NSDiscoItems}, + Features: []stanza.Feature{ + {Var: stanza.NSDiscoInfo}, + {Var: stanza.NSDiscoItems}, }, } iq.Payload = &payload @@ -57,7 +58,7 @@ func TestGenerateIq(t *testing.T) { t.Error("empty error should not be serialized") } - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} if err = xml.Unmarshal(data, &parsedIQ); err != nil { t.Errorf("Unmarshal(%s) returned error", data) } @@ -68,7 +69,7 @@ func TestGenerateIq(t *testing.T) { } func TestErrorTag(t *testing.T) { - xError := Err{ + xError := stanza.Err{ XMLName: xml.Name{Local: "error"}, Code: 503, Type: "cancel", @@ -81,7 +82,7 @@ func TestErrorTag(t *testing.T) { t.Errorf("cannot marshal xml structure: %s", err) } - parsedError := Err{} + parsedError := stanza.Err{} if err = xml.Unmarshal(data, &parsedError); err != nil { t.Errorf("Unmarshal(%s) returned error", data) } @@ -92,8 +93,8 @@ func TestErrorTag(t *testing.T) { } func TestDiscoItems(t *testing.T) { - iq := NewIQ(Attrs{Type: IQTypeGet, From: "romeo@montague.net/orchard", To: "catalog.shakespeare.lit", Id: "items3"}) - payload := DiscoItems{ + iq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeGet, From: "romeo@montague.net/orchard", To: "catalog.shakespeare.lit", Id: "items3"}) + payload := stanza.DiscoItems{ Node: "music", } iq.Payload = &payload @@ -103,7 +104,7 @@ func TestDiscoItems(t *testing.T) { t.Errorf("cannot marshal xml structure") } - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} if err = xml.Unmarshal(data, &parsedIQ); err != nil { t.Errorf("Unmarshal(%s) returned error", data) } @@ -116,7 +117,7 @@ func TestDiscoItems(t *testing.T) { func TestUnmarshalPayload(t *testing.T) { query := "" - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} err := xml.Unmarshal([]byte(query), &parsedIQ) if err != nil { t.Errorf("Unmarshal(%s) returned error", query) @@ -141,7 +142,7 @@ func TestPayloadWithError(t *testing.T) { ` - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} err := xml.Unmarshal([]byte(iq), &parsedIQ) if err != nil { t.Errorf("Unmarshal error: %s", iq) @@ -157,7 +158,7 @@ func TestUnknownPayload(t *testing.T) { iq := ` ` - parsedIQ := IQ{} + parsedIQ := stanza.IQ{} err := xml.Unmarshal([]byte(iq), &parsedIQ) if err != nil { t.Errorf("Unmarshal error: %#v (%s)", err, iq) diff --git a/stanza/message_test.go b/stanza/message_test.go index 9427c4a..4681694 100644 --- a/stanza/message_test.go +++ b/stanza/message_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "gosrc.io/xmpp/stanza" ) func TestGenerateMessage(t *testing.T) { - message := NewMessage(Attrs{Type: MessageTypeChat, From: "admin@localhost", To: "test@localhost", Id: "1"}) + message := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: "admin@localhost", To: "test@localhost", Id: "1"}) message.Body = "Hi" message.Subject = "Msg Subject" @@ -17,7 +18,7 @@ func TestGenerateMessage(t *testing.T) { t.Errorf("cannot marshal xml structure") } - parsedMessage := Message{} + parsedMessage := stanza.Message{} if err = xml.Unmarshal(data, &parsedMessage); err != nil { t.Errorf("Unmarshal(%s) returned error", data) } @@ -37,7 +38,7 @@ func TestDecodeError(t *testing.T) { ` - parsedMessage := Message{} + parsedMessage := stanza.Message{} if err := xml.Unmarshal([]byte(str), &parsedMessage); err != nil { t.Errorf("message error stanza unmarshall error: %v", err) return @@ -49,15 +50,15 @@ func TestDecodeError(t *testing.T) { func TestGetOOB(t *testing.T) { image := "https://localhost/image.png" - msg := NewMessage(Attrs{To: "test@localhost"}) - ext := OOB{ + msg := stanza.NewMessage(stanza.Attrs{To: "test@localhost"}) + ext := stanza.OOB{ XMLName: xml.Name{Space: "jabber:x:oob", Local: "x"}, URL: image, } msg.Extensions = append(msg.Extensions, &ext) // OOB can properly be found - var oob OOB + var oob stanza.OOB // Try to find and if ok := msg.Get(&oob); !ok { t.Error("could not find oob extension") @@ -68,7 +69,7 @@ func TestGetOOB(t *testing.T) { } // Markable is not found - var m Markable + var m stanza.Markable if ok := msg.Get(&m); ok { t.Error("we should not have found markable extension") } diff --git a/stanza/msg_html_test.go b/stanza/msg_html_test.go index 1dbaa00..b37e9d6 100644 --- a/stanza/msg_html_test.go +++ b/stanza/msg_html_test.go @@ -3,16 +3,18 @@ package stanza_test import ( "encoding/xml" "testing" + + "gosrc.io/xmpp/stanza" ) func TestHTMLGen(t *testing.T) { htmlBody := "

Hello World

" - msg := NewMessage(Attrs{To: "test@localhost"}) + msg := stanza.NewMessage(stanza.Attrs{To: "test@localhost"}) msg.Body = "Hello World" - body := HTMLBody{ + body := stanza.HTMLBody{ InnerXML: htmlBody, } - html := HTML{Body: body} + html := stanza.HTML{Body: body} msg.Extensions = append(msg.Extensions, html) result := msg.XMPPFormat() @@ -21,7 +23,7 @@ func TestHTMLGen(t *testing.T) { t.Errorf("incorrect serialize message:\n%s", result) } - parsedMessage := Message{} + parsedMessage := stanza.Message{} if err := xml.Unmarshal([]byte(str), &parsedMessage); err != nil { t.Errorf("message HTML unmarshall error: %v", err) return @@ -31,7 +33,7 @@ func TestHTMLGen(t *testing.T) { t.Errorf("incorrect parsed body: '%s'", parsedMessage.Body) } - var h HTML + var h stanza.HTML if ok := parsedMessage.Get(&h); !ok { t.Error("could not extract HTML body") } diff --git a/stanza/msg_receipts_test.go b/stanza/msg_receipts_test.go index 4b9971c..bf379a1 100644 --- a/stanza/msg_receipts_test.go +++ b/stanza/msg_receipts_test.go @@ -3,6 +3,8 @@ package stanza_test import ( "encoding/xml" "testing" + + "gosrc.io/xmpp/stanza" ) func TestDecodeRequest(t *testing.T) { @@ -13,7 +15,7 @@ func TestDecodeRequest(t *testing.T) { My lord, dispatch; read o'er these articles. ` - parsedMessage := Message{} + parsedMessage := stanza.Message{} if err := xml.Unmarshal([]byte(str), &parsedMessage); err != nil { t.Errorf("message receipt unmarshall error: %v", err) return @@ -29,7 +31,7 @@ func TestDecodeRequest(t *testing.T) { } switch ext := parsedMessage.Extensions[0].(type) { - case *ReceiptRequest: + case *stanza.ReceiptRequest: if ext.XMLName.Local != "request" { t.Errorf("unexpected extension: %s:%s", ext.XMLName.Space, ext.XMLName.Local) } diff --git a/stanza/pres_muc_test.go b/stanza/pres_muc_test.go index 6ea2ab6..78fe29f 100644 --- a/stanza/pres_muc_test.go +++ b/stanza/pres_muc_test.go @@ -3,6 +3,8 @@ package stanza_test import ( "encoding/xml" "testing" + + "gosrc.io/xmpp/stanza" ) // https://xmpp.org/extensions/xep-0045.html#example-27 @@ -16,12 +18,12 @@ func TestMucPassword(t *testing.T) { ` - var parsedPresence Presence + var parsedPresence stanza.Presence if err := xml.Unmarshal([]byte(str), &parsedPresence); err != nil { t.Errorf("Unmarshal(%s) returned error", str) } - var muc MucPresence + var muc stanza.MucPresence if ok := parsedPresence.Get(&muc); !ok { t.Error("muc presence extension was not found") } @@ -42,12 +44,12 @@ func TestMucHistory(t *testing.T) { ` - var parsedPresence Presence + var parsedPresence stanza.Presence if err := xml.Unmarshal([]byte(str), &parsedPresence); err != nil { t.Errorf("Unmarshal(%s) returned error", str) } - var muc MucPresence + var muc stanza.MucPresence if ok := parsedPresence.Get(&muc); !ok { t.Error("muc presence extension was not found") } diff --git a/stanza/presence_test.go b/stanza/presence_test.go index 0433857..94431d8 100644 --- a/stanza/presence_test.go +++ b/stanza/presence_test.go @@ -5,18 +5,19 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "gosrc.io/xmpp/stanza" ) func TestGeneratePresence(t *testing.T) { - presence := NewPresence(Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"}) - presence.Show = PresenceShowChat + presence := stanza.NewPresence(stanza.Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"}) + presence.Show = stanza.PresenceShowChat data, err := xml.Marshal(presence) if err != nil { t.Errorf("cannot marshal xml structure") } - var parsedPresence Presence + var parsedPresence stanza.Presence if err = xml.Unmarshal(data, &parsedPresence); err != nil { t.Errorf("Unmarshal(%s) returned error", data) } @@ -30,13 +31,13 @@ func TestPresenceSubElt(t *testing.T) { // Test structure to ensure that show, status and priority are correctly defined as presence // package sub-elements type pres struct { - Show PresenceShow `xml:"show"` - Status string `xml:"status"` - Priority int8 `xml:"priority"` + Show stanza.PresenceShow `xml:"show"` + Status string `xml:"status"` + Priority int8 `xml:"priority"` } - presence := NewPresence(Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"}) - presence.Show = PresenceShowXA + presence := stanza.NewPresence(stanza.Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"}) + presence.Show = stanza.PresenceShowXA presence.Status = "Coding" presence.Priority = 10