-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjson_codec_test.go
64 lines (38 loc) · 1.13 KB
/
json_codec_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
package json
import (
"github.com/stretchr/codecs"
"github.com/stretchr/codecs/constants"
"github.com/stretchr/testify/assert"
"testing"
)
var codec JsonCodec
func TestInterface(t *testing.T) {
assert.Implements(t, (*codecs.Codec)(nil), new(JsonCodec), "JsonCodec")
}
func TestMarshal(t *testing.T) {
obj := make(map[string]string)
obj["name"] = "Mat"
jsonString, jsonError := codec.Marshal(obj, nil)
if jsonError != nil {
t.Errorf("Shouldn't return error: %s", jsonError)
}
assert.Equal(t, string(jsonString), `{"name":"Mat"}`)
}
func TestUnmarshal(t *testing.T) {
jsonString := `{"name":"Mat"}`
var object map[string]interface{}
err := codec.Unmarshal([]byte(jsonString), &object)
if err != nil {
t.Errorf("Shouldn't return error: %s", err)
}
assert.Equal(t, "Mat", object["name"])
}
func TestResponseContentType(t *testing.T) {
assert.Equal(t, codec.ContentType(), constants.ContentTypeJSON)
}
func TestFileExtension(t *testing.T) {
assert.Equal(t, constants.FileExtensionJSON, codec.FileExtension())
}
func TestCanMarshalWithCallback(t *testing.T) {
assert.False(t, codec.CanMarshalWithCallback())
}