Improve tests for DB indexes

This commit is contained in:
Tobie Morgan Hitchcock 2018-04-04 19:16:32 +01:00
parent 82ffd9ef31
commit 86a911b4a8

View file

@ -518,6 +518,42 @@ func TestDefine(t *testing.T) {
})
Convey("Define an index on a table, and ensure it allows duplicate record values", t, func() {
setupDB()
txt := `
USE NS test DB test;
DEFINE INDEX test ON person COLUMNS account, email;
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:two SET account="demo", email="info@demo.com";
UPDATE person:tre SET account="demo", email="info@demo.com";
SELECT * FROM person ORDER BY meta.id;
`
res, err := Execute(setupKV(), txt, nil)
So(err, ShouldBeNil)
So(res, ShouldHaveLength, 8)
So(res[1].Status, ShouldEqual, "OK")
So(res[2].Result, ShouldHaveLength, 1)
So(res[2].Status, ShouldEqual, "OK")
So(res[3].Result, ShouldHaveLength, 1)
So(res[3].Status, ShouldEqual, "OK")
So(res[4].Result, ShouldHaveLength, 1)
So(res[4].Status, ShouldEqual, "OK")
So(res[5].Result, ShouldHaveLength, 1)
So(res[5].Status, ShouldEqual, "OK")
So(res[6].Result, ShouldHaveLength, 1)
So(res[6].Status, ShouldEqual, "OK")
So(res[7].Result, ShouldHaveLength, 3)
So(data.Consume(res[7].Result[0]).Get("id").Data(), ShouldResemble, &sql.Thing{"person", "one"})
So(data.Consume(res[7].Result[1]).Get("id").Data(), ShouldResemble, &sql.Thing{"person", "tre"})
So(data.Consume(res[7].Result[2]).Get("id").Data(), ShouldResemble, &sql.Thing{"person", "two"})
})
Convey("Define a unique index on a table, and ensure it prevents duplicate record values", t, func() {
setupDB()
@ -526,23 +562,29 @@ func TestDefine(t *testing.T) {
USE NS test DB test;
DEFINE INDEX test ON person COLUMNS account, email UNIQUE;
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:two SET account="demo", email="info@demo.com";
UPDATE person:tre SET account="demo", email="info@demo.com";
SELECT * FROM person;
SELECT * FROM person ORDER BY meta.id;
`
res, err := Execute(setupKV(), txt, nil)
So(err, ShouldBeNil)
So(res, ShouldHaveLength, 6)
So(res, ShouldHaveLength, 8)
So(res[1].Status, ShouldEqual, "OK")
So(res[2].Result, ShouldHaveLength, 1)
So(res[2].Status, ShouldEqual, "OK")
So(res[3].Result, ShouldHaveLength, 0)
So(res[3].Status, ShouldEqual, "ERR_IX")
So(res[4].Result, ShouldHaveLength, 0)
So(res[4].Status, ShouldEqual, "ERR_IX")
So(res[5].Result, ShouldHaveLength, 1)
So(data.Consume(res[5].Result[0]).Get("id").Data(), ShouldResemble, &sql.Thing{"person", "one"})
So(res[3].Result, ShouldHaveLength, 1)
So(res[3].Status, ShouldEqual, "OK")
So(res[4].Result, ShouldHaveLength, 1)
So(res[4].Status, ShouldEqual, "OK")
So(res[5].Result, ShouldHaveLength, 0)
So(res[5].Status, ShouldEqual, "ERR_IX")
So(res[6].Result, ShouldHaveLength, 0)
So(res[6].Status, ShouldEqual, "ERR_IX")
So(res[7].Result, ShouldHaveLength, 1)
So(data.Consume(res[7].Result[0]).Get("id").Data(), ShouldResemble, &sql.Thing{"person", "one"})
})
@ -556,12 +598,12 @@ func TestDefine(t *testing.T) {
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:two SET account="demo", email="info@demo.com";
UPDATE person:tre SET account="demo", email="info@demo.com";
SELECT * FROM person;
SELECT * FROM person ORDER BY meta.id;
DEFINE INDEX test ON person COLUMNS account, email UNIQUE;
UPDATE person:one SET account="demo", email="info@demo.com";
UPDATE person:two SET account="demo", email="info@demo.com";
UPDATE person:tre SET account="demo", email="info@demo.com";
SELECT * FROM person;
SELECT * FROM person ORDER BY meta.id;
`
res, err := Execute(setupKV(), txt, nil)