-
Notifications
You must be signed in to change notification settings - Fork 72
/
schema_test.go
65 lines (58 loc) · 1.33 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
package kallax
import (
"testing"
"github.com/stretchr/testify/require"
)
var emptySchema = NewBaseSchema("", "", nil, nil, nil, false)
func TestBaseSchemaFieldQualifiedName(t *testing.T) {
var cases = []struct {
name string
field SchemaField
schema Schema
expected string
}{
{"non empty schema alias", f("foo"), ModelSchema, "__model.foo"},
{"empty schema alias", f("foo"), emptySchema, "foo"},
}
r := require.New(t)
for _, c := range cases {
r.Equal(c.expected, c.field.QualifiedName(c.schema), c.name)
}
}
func TestJSONSchemaKeyQualifiedName(t *testing.T) {
var cases = []struct {
name string
key *JSONSchemaKey
schema Schema
expected string
}{
{
"json text key",
NewJSONSchemaKey(JSONText, "foo", "bar", "baz"),
ModelSchema,
"__model.foo #>>'{bar,baz}'",
},
{
"json int key",
NewJSONSchemaKey(JSONInt, "foo", "bar", "baz"),
ModelSchema,
"CAST(__model.foo #>>'{bar,baz}' as bigint)",
},
{
"json any key",
NewJSONSchemaKey(JSONAny, "foo", "bar", "baz"),
ModelSchema,
"__model.foo #>'{bar,baz}'",
},
{
"json key with empty schema",
NewJSONSchemaKey(JSONBool, "foo", "bar", "baz"),
nil,
"CAST(foo #>>'{bar,baz}' as bool)",
},
}
r := require.New(t)
for _, c := range cases {
r.Equal(c.expected, c.key.QualifiedName(c.schema), c.name)
}
}