forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option_test.go
41 lines (35 loc) · 1.04 KB
/
option_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
package importer
import (
"testing"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
var testDataOption = map[string][]byte{
"normal": []byte(`{
"autoMatching": true,
"chunkSize":200,
"mappingPreview": "always",
"dataPreview": "never"
}`),
"defaults": []byte(`{}`),
"failure": []byte(`""`),
}
func TestOptionUnmarshalJSON(t *testing.T) {
var normal Option
err := jsoniter.Unmarshal(testDataOption["normal"], &normal)
assert.Nil(t, err)
assert.Equal(t, true, normal.UseTemplate)
assert.Equal(t, 200, normal.ChunkSize)
assert.Equal(t, "always", normal.MappingPreview)
assert.Equal(t, "never", normal.DataPreview)
var defaults Option
err = jsoniter.Unmarshal(testDataOption["defaults"], &defaults)
assert.Nil(t, err)
assert.Equal(t, true, defaults.UseTemplate)
assert.Equal(t, 500, defaults.ChunkSize)
assert.Equal(t, "auto", defaults.MappingPreview)
assert.Equal(t, "auto", defaults.DataPreview)
var failure Option
err = jsoniter.Unmarshal(testDataOption["failure"], &failure)
assert.NotNil(t, err)
}