forked from hashicorp/go-memdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_test.go
97 lines (86 loc) · 1.84 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
92
93
94
95
96
97
package memdb
import "testing"
func testValidSchema() *DBSchema {
return &DBSchema{
Tables: map[string]*TableSchema{
"main": &TableSchema{
Name: "main",
Indexes: map[string]*IndexSchema{
"id": &IndexSchema{
Name: "id",
Unique: true,
Indexer: &StringFieldIndex{Field: "ID"},
},
"foo": &IndexSchema{
Name: "foo",
Indexer: &StringFieldIndex{Field: "Foo"},
},
},
},
},
}
}
func TestDBSchema_Validate(t *testing.T) {
s := &DBSchema{}
err := s.Validate()
if err == nil {
t.Fatalf("should not validate, empty")
}
s.Tables = map[string]*TableSchema{
"foo": &TableSchema{Name: "foo"},
}
err = s.Validate()
if err == nil {
t.Fatalf("should not validate, no indexes")
}
valid := testValidSchema()
err = valid.Validate()
if err != nil {
t.Fatalf("should validate: %v", err)
}
}
func TestTableSchema_Validate(t *testing.T) {
s := &TableSchema{}
err := s.Validate()
if err == nil {
t.Fatalf("should not validate, empty")
}
s.Indexes = map[string]*IndexSchema{
"foo": &IndexSchema{Name: "foo"},
}
err = s.Validate()
if err == nil {
t.Fatalf("should not validate, no indexes")
}
valid := &TableSchema{
Name: "main",
Indexes: map[string]*IndexSchema{
"id": &IndexSchema{
Name: "id",
Unique: true,
Indexer: &StringFieldIndex{Field: "ID", Lowercase: true},
},
},
}
err = valid.Validate()
if err != nil {
t.Fatalf("should validate: %v", err)
}
}
func TestIndexSchema_Validate(t *testing.T) {
s := &IndexSchema{}
err := s.Validate()
if err == nil {
t.Fatalf("should not validate, empty")
}
s.Name = "foo"
err = s.Validate()
if err == nil {
t.Fatalf("should not validate, no indexer")
}
s.Indexer = &StringFieldIndex{Field: "Foo", Lowercase: false}
err = s.Validate()
if err != nil {
t.Fatalf("should validate: %v", err)
}
}