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) + } +}