- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrors_test.go
More file actions
Latest commit
66 lines (54 loc) · 2.07 KB
/
Copy patherrors_test.go
File metadata and controls
66 lines (54 loc) · 2.07 KB
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
package jmap
import (
"encoding/json"
"testing"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
)
constrequestErr=`{
"type": "urn:ietf:params:jmap:error:unknownCapability",
"status": 400,
"detail": "The request object used capability 'https://example.com/apis/foobar', which is not supported by this server."
}`
constrequestLimitErr=`{
"type": "urn:ietf:params:jmap:error:limit",
"limit": "maxSizeRequest",
"status": 400,
"detail": "The request is larger than the server is willing to process."
}`
funcTestRequestErrorUnmarshal(t*testing.T) {
errObj:=RequestError{}
err:=json.Unmarshal([]byte(requestErr), &errObj)
assert.NilError(t, err, "json.Unmarshal")
assert.Check(t, cmp.Equal(400, errObj.Status))
assert.Check(t, cmp.Equal(ProblemPrefix+CodeUnknownCapability, errObj.Type))
t.Run("properties", func(t*testing.T) {
errObj:=RequestError{}
err:=json.Unmarshal([]byte(requestLimitErr), &errObj)
assert.NilError(t, err, "json.Unmarshal")
assert.Check(t, cmp.Equal(400, errObj.Status))
assert.Check(t, cmp.Equal(ProblemPrefix+"limit", errObj.Type))
assert.Check(t, cmp.Equal(errObj.Properties["limit"], "maxSizeRequest"))
})
}
funcTestRequestErrorMarshal(t*testing.T) {
errObj:=RequestError{}
errObj.Type=ProblemPrefix+CodeUnknownCapability
errObj.Status=400
errObj.Detail="something is broken, yay!"
blob, err:=json.Marshal(errObj)
assert.NilError(t, err, "json.Marshal")
assert.Check(t, cmp.Equal(`{"detail":"something is broken, yay!","status":400,"type":"urn:ietf:params:jmap:error:unknownCapability"}`, string(blob)))
t.Run("properties", func(t*testing.T) {
errObj:=RequestError{}
errObj.Type=ProblemPrefix+"limit"
errObj.Status=400
errObj.Detail="something is broken, yay!"
errObj.Properties=map[string]interface{}{
"limit": "maxSizeRequest",
}
blob, err:=json.Marshal(errObj)
assert.NilError(t, err, "json.Marshal")
assert.Check(t, cmp.Equal(`{"detail":"something is broken, yay!","limit":"maxSizeRequest","status":400,"type":"urn:ietf:params:jmap:error:limit"}`, string(blob)))
})
}