memdb: testing schema validation

This commit is contained in:
Armon Dadgar
2015-06-07 13:07:55 -07:00
parent e7bd70ddd2
commit 7a9dd5804b
2 changed files with 43 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package memdb
import "testing"
type TestObject struct {
ID string
Foo string
Bar int
Baz string
@@ -11,6 +12,7 @@ type TestObject struct {
func testObj() *TestObject {
obj := &TestObject{
ID: "my-cool-obj",
Foo: "Testing",
Bar: 42,
Baz: "yep",

View File

@@ -0,0 +1,41 @@
package memdb
import "testing"
func testValidSchema() *DBSchema {
return &DBSchema{
Tables: []*TableSchema{
&TableSchema{
Name: "main",
Indexes: []*IndexSchema{
&IndexSchema{
Name: "id",
Indexer: StringFieldIndex("ID", false),
},
},
},
},
}
}
func TestDBSchema_Validate(t *testing.T) {
s := &DBSchema{}
err := s.Validate()
if err == nil {
t.Fatalf("should not validate, empty")
}
s.Tables = []*TableSchema{
&TableSchema{},
}
err = s.Validate()
if err == nil {
t.Fatalf("should not validate, no table name")
}
valid := testValidSchema()
err = valid.Validate()
if err != nil {
t.Fatalf("should validate: %v", err)
}
}