-
Notifications
You must be signed in to change notification settings - Fork 5
/
session_test.go
92 lines (83 loc) · 2.57 KB
/
session_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package jmap
import (
"encoding/json"
"testing"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
)
var sessionBlob = `{
"capabilities": {
"urn:ietf:params:jmap:core": {
"maxSizeUpload": 50000000,
"maxConcurrentUpload": 8,
"maxSizeRequest": 10000000,
"maxConcurrentRequest": 8,
"maxCallsInRequest": 32,
"maxObjectsInGet": 256,
"maxObjectsInSet": 128,
"collationAlgorithms": [
"i;ascii-numeric",
"i;ascii-casemap",
"i;unicode-casemap"
]
},
"urn:ietf:params:jmap:mail": {},
"urn:ietf:params:jmap:contacts": {},
"https://example.com/apis/foobar": {
"maxFoosFinangled": 42
}
},
"accounts": {
"A13824": {
"name": "[email protected]",
"isPersonal": true,
"isReadOnly": false,
"accountCapabilities": {
"urn:ietf:params:jmap:mail": {
"maxMailboxesPerEmail": null,
"maxMailboxDepth": 10
},
"urn:ietf:params:jmap:contacts": {
}
}
},
"A97813": {
"name": "[email protected]",
"isPersonal": false,
"isReadOnly": true,
"accountCapabilities": {
"urn:ietf:params:jmap:mail": {
"maxMailboxesPerEmail": 1,
"maxMailboxDepth": 10
}
}
}
},
"primaryAccounts": {
"urn:ietf:params:jmap:mail": "A13824",
"urn:ietf:params:jmap:contacts": "A13824"
},
"username": "[email protected]",
"apiUrl": "https://jmap.example.com/api/",
"downloadUrl": "https://jmap.example.com/download/{accountId}/{blobId}/{name}?accept={type}",
"uploadUrl": "https://jmap.example.com/upload/{accountId}/",
"eventSourceUrl": "https://jmap.example.com/eventsource/?types={types}&closeafter={closeafter}&ping={ping}",
"state": "75128aab4b1b"
}`
func TestSessionUnmarshal(t *testing.T) {
s := Session{}
assert.NilError(t, json.Unmarshal([]byte(sessionBlob), &s), "json.Unmarshal")
assert.Check(t, cmp.Equal(UnsignedInt(50000000), s.CoreCapability.MaxSizeUpload))
assert.Check(t, cmp.Equal("[email protected]", s.Accounts["A13824"].Name))
}
func TestSessionMarshal(t *testing.T) {
s := Session{}
assert.NilError(t, json.Unmarshal([]byte(sessionBlob), &s), "json.Unmarshal")
blob, err := json.MarshalIndent(s, "", " ")
assert.NilError(t, err, "json.Marshal")
// We can't just compare []byte because order of fields may be different.
var original, remarshaled map[string]interface{}
assert.NilError(t, json.Unmarshal([]byte(sessionBlob), &original))
assert.NilError(t, json.Unmarshal(blob, &remarshaled))
assert.Check(t, cmp.DeepEqual(original, remarshaled))
}