-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_response_test.go
54 lines (48 loc) · 938 Bytes
/
api_response_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
package zulip
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAPIResponseMarshalling(t *testing.T) {
cases := []struct {
name string
input string
}{
{
name: "Normal response",
input: `{
"code": "INVALID_API_KEY",
"msg": "Invalid API key",
"result": "error"
}`,
},
{
name: "Extra fields (1)",
input: `{
"code": "REQUEST_VARIABLE_MISSING",
"msg": "Missing 'content' argument",
"result": "error",
"var_name": "content"
}`,
},
{
name: "Extra fields (2)",
input: `{
"ignored_parameters_unsupported": [
"invalid_param_1",
"invalid_param_2"
],
"msg": "",
"result": "success"
}`,
},
}
for _, c := range cases {
er := APIResponseBase{}
assert.NoError(t, json.Unmarshal([]byte(c.input), &er))
erJSON, err := json.Marshal(er)
assert.NoError(t, err)
assert.JSONEq(t, c.input, string(erJSON))
}
}