From 7a9dd5804b04bc2cfd4c70dc21774e41565deba5 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 7 Jun 2015 13:07:55 -0700 Subject: [PATCH] memdb: testing schema validation --- nomad/memdb/index_test.go | 2 ++ nomad/memdb/schema_test.go | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 nomad/memdb/schema_test.go diff --git a/nomad/memdb/index_test.go b/nomad/memdb/index_test.go index f2daac63f..24d825a4b 100644 --- a/nomad/memdb/index_test.go +++ b/nomad/memdb/index_test.go @@ -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", diff --git a/nomad/memdb/schema_test.go b/nomad/memdb/schema_test.go new file mode 100644 index 000000000..d33a74141 --- /dev/null +++ b/nomad/memdb/schema_test.go @@ -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) + } +}