-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathjson_test.go
87 lines (78 loc) · 2.52 KB
/
json_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package schema
import (
"strings"
"testing"
)
func TestNewSchemaHandlerFromJSON(t *testing.T) {
var jsonSchema string = `
{
"Tag": "name=parquet-go-root, repetitiontype=REQUIRED",
"Fields": [
{"Tag": "name=name, inname=Name, type=BYTE_ARRAY, convertedtype=UTF8, repetitiontype=REQUIRED"},
{"Tag": "name=age, inname=Age, type=INT32, repetitiontype=REQUIRED"}
]
}
`
handler, err := NewSchemaHandlerFromJSON(jsonSchema)
if err != nil {
t.Errorf("error in creating handler from json schema :%v", err.Error())
}
expectedElems := 1 + 2 //goroot +2
if len(handler.SchemaElements) != expectedElems {
t.Errorf("expected %v elements from json schema string, got %v", expectedElems, len(handler.SchemaElements))
}
}
func TestNewSchemaHandlerFromImproperJSON(t *testing.T) {
var improperJsonSchema string = `
{
"Tag": "name=parquet-go-root, repetitiontype=REQUIRED",
"Fields": [
{"Tag": "name=name, inname=Name, type=BYTE_ARRAY, convertedtype=UTF8, repetitiontype=REQUIRED"},
{"Tag": "name=age, inname=Age, type=INT32, repetitiontype=REQUIRED"}
,,
]
}
`
_, err := NewSchemaHandlerFromJSON(improperJsonSchema)
if err == nil {
t.Errorf("failing test, expected error as we provided an improperly formatted json string, but got no error!")
}
}
func TestNewSchemaHandlerFromImproperJSON_MAP(t *testing.T) {
var improperJsonSchema string = `
{
"Tag": "name=parquet-go-root, repetitiontype=REQUIRED",
"Fields": [
{
"Tag": "name=name, inname=Name, type=MAP, repetitiontype=REQUIRED",
"Fields": []
}
]
}
`
_, err := NewSchemaHandlerFromJSON(improperJsonSchema)
if err == nil {
t.Errorf("failing test, expected error as we provided an improperly formatted json string, but got no error!")
} else if !strings.Contains(err.Error(), "MAP needs exact 2 fields") {
t.Errorf(`failing test, expect error like "MAP needs exact 2 fields" but got "%s"`, err.Error())
}
}
func TestNewSchemaHandlerFromImproperJSON_LIST(t *testing.T) {
var improperJsonSchema string = `
{
"Tag": "name=parquet-go-root, repetitiontype=REQUIRED",
"Fields": [
{
"Tag": "name=name, inname=Name, type=LIST, repetitiontype=REQUIRED",
"Fields": []
}
]
}
`
_, err := NewSchemaHandlerFromJSON(improperJsonSchema)
if err == nil {
t.Errorf("failing test, expected error as we provided an improperly formatted json string, but got no error!")
} else if !strings.Contains(err.Error(), "LIST needs exact 1 field") {
t.Errorf(`failing test, expect error like "LIST needs exact 1 field" but got "%s"`, err.Error())
}
}