~samwhited/xmpp

xmpp/stanza/delay_test.go -rw-r--r-- 1.7 KiB
e9b0a2deSam Whited docs: do a quick editing pass over the docs an hour 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2021 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package stanza_test

import (
	"testing"
	"time"

	"mellium.im/xmpp/internal/xmpptest"
	"mellium.im/xmpp/jid"
	"mellium.im/xmpp/stanza"
)

var marshalDelayTestCases = []xmpptest.EncodingTestCase{
	0: {
		Value:       &stanza.Delay{},
		XML:         `<delay xmlns="urn:xmpp:delay" from="" stamp="0001-01-01T00:00:00Z"></delay>`,
		NoUnmarshal: true,
	},
	1: {
		Value: &stanza.Delay{
			From: jid.MustParse("example.net"),
		},
		XML: `<delay xmlns="urn:xmpp:delay" from="example.net" stamp="0001-01-01T00:00:00Z"></delay>`,
	},
	2: {
		Value: &stanza.Delay{
			From:  jid.MustParse("me@example.net"),
			Stamp: time.Unix(10000, 0).UTC(),
		},
		XML: `<delay xmlns="urn:xmpp:delay" from="me@example.net" stamp="1970-01-01T02:46:40Z"></delay>`,
	},
	3: {
		Value: &stanza.Delay{
			From:  jid.MustParse("me@example.net"),
			Stamp: time.Unix(10000, 0),
		},
		XML:         `<delay xmlns="urn:xmpp:delay" from="me@example.net" stamp="1970-01-01T02:46:40Z"></delay>`,
		NoUnmarshal: true,
	},
	4: {
		Value: &stanza.Delay{
			From:  jid.MustParse("me@example.net"),
			Stamp: time.Unix(10000, 0).UTC(),
		},
		XML:       `<delay xmlns="urn:xmpp:delay" from="me@example.net" stamp="1970-01-01T02:46:40Z"><foo/></delay>`,
		NoMarshal: true,
	},
	5: {
		Value: &stanza.Delay{
			From:   jid.MustParse("me@example.net"),
			Stamp:  time.Unix(10000, 0).UTC(),
			Reason: "test",
		},
		XML: `<delay xmlns="urn:xmpp:delay" from="me@example.net" stamp="1970-01-01T02:46:40Z">test</delay>`,
	},
}

func TestMarshalDelay(t *testing.T) {
	xmpptest.RunEncodingTests(t, marshalDelayTestCases)
}