-
Notifications
You must be signed in to change notification settings - Fork 85
/
types_test.go
42 lines (34 loc) · 911 Bytes
/
types_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
package meilisearch
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestRawType_UnmarshalJSON(t *testing.T) {
var r RawType
data := []byte(`"example"`)
err := r.UnmarshalJSON(data)
assert.NoError(t, err)
assert.Equal(t, RawType(`"example"`), r)
data = []byte(`""`)
err = r.UnmarshalJSON(data)
assert.NoError(t, err)
assert.Equal(t, RawType(`""`), r)
data = []byte(`{invalid}`)
err = r.UnmarshalJSON(data)
assert.NoError(t, err)
assert.Equal(t, RawType(`{invalid}`), r)
}
func TestRawType_MarshalJSON(t *testing.T) {
r := RawType(`"example"`)
data, err := r.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, []byte(`"example"`), data)
r = RawType(`""`)
data, err = r.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, []byte(`""`), data)
r = RawType(`{random}`)
data, err = r.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, []byte(`{random}`), data)
}