mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
memdb: testing schema validation
This commit is contained in:
@@ -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",
|
||||
|
||||
41
nomad/memdb/schema_test.go
Normal file
41
nomad/memdb/schema_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user