-
Notifications
You must be signed in to change notification settings - Fork 3
/
schema_test.go
91 lines (87 loc) · 1.94 KB
/
schema_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
88
89
90
91
package filetypes
import (
"testing"
"github.com/cloudquery/codegen/jsonschema"
"github.com/stretchr/testify/require"
)
func TestFileSpec_JSONSchemaExtend(t *testing.T) {
schema, err := jsonschema.Generate(FileSpec{}, FileSpec{}.JSONSchemaOptions()...)
require.NoError(t, err)
jsonschema.TestJSONSchema(t, string(schema), []jsonschema.TestCase{
{
Name: "empty",
Err: true, // missing format
Spec: `{}`,
},
{
Name: "empty format",
Err: true,
Spec: `{"format":""}`,
},
{
Name: "null format",
Err: true,
Spec: `{"format":null}`,
},
{
Name: "bad format",
Err: true,
Spec: `{"format":123}`,
},
{
Name: "bad format value",
Err: true,
Spec: `{"format":"abc"}`,
},
{
Name: "csv format",
Spec: `{"format":"csv"}`,
},
{
Name: "csv format + empty format_spec",
Spec: `{"format":"csv","format_spec":{}}`,
},
{
Name: "csv format + null format_spec",
Spec: `{"format":"csv","format_spec":null}`,
},
{
Name: "csv format + csv format_spec",
Spec: `{"format":"csv","format_spec":{"skip_header": true, "delimiter":","}}`,
},
{
Name: "json format",
Spec: `{"format":"json"}`,
},
{
Name: "json format + empty format_spec",
Spec: `{"format":"json","format_spec":{}}`,
},
{
Name: "json format + null format_spec",
Spec: `{"format":"json","format_spec":null}`,
},
{
Name: "json format + csv format_spec",
Err: true,
Spec: `{"format":"json","format_spec":{"skip_header": true, "delimiter":","}}`,
},
{
Name: "parquet format",
Spec: `{"format":"parquet"}`,
},
{
Name: "parquet format + empty format_spec",
Spec: `{"format":"parquet","format_spec":{}}`,
},
{
Name: "parquet format + null format_spec",
Spec: `{"format":"parquet","format_spec":null}`,
},
{
Name: "parquet format + csv format_spec",
Err: true,
Spec: `{"format":"parquet","format_spec":{"skip_header": true, "delimiter":","}}`,
},
})
}