1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

gograph: fix a bug which caused the unicity of (parent, name) to not be enforced

This commit is contained in:
Solomon Hykes 2013-10-09 19:44:31 -07:00 committed by Victor Vieux
parent 515070d513
commit 4576d0f802
2 changed files with 17 additions and 0 deletions

View file

@ -22,7 +22,9 @@ const (
CONSTRAINT "parent_fk" FOREIGN KEY ("parent_id") REFERENCES "entity" ("id"),
CONSTRAINT "entity_fk" FOREIGN KEY ("entity_id") REFERENCES "entity" ("id")
);
`
createEdgeIndices = `
CREATE UNIQUE INDEX "name_parent_ix" ON "edge" (parent_id, name);
`
)
@ -67,6 +69,9 @@ func NewDatabase(dbPath string) (*Database, error) {
if _, err := conn.Exec(createEdgeTable); err != nil {
return nil, err
}
if _, err := conn.Exec(createEdgeIndices); err != nil {
return nil, err
}
rollback := func() {
conn.Exec("ROLLBACK")

View file

@ -59,6 +59,18 @@ func TestSetEntityWithDifferentName(t *testing.T) {
}
}
func TestSetDuplicateEntity(t *testing.T) {
db := newTestDb(t)
defer destroyTestDb(db)
if _, err := db.Set("/foo", "42"); err != nil {
t.Fatal(err)
}
if _, err := db.Set("/foo", "43"); err == nil {
t.Fatalf("Creating an entry with a duplciate path did not cause an error")
}
}
func TestCreateChild(t *testing.T) {
db := newTestDb(t)
defer destroyTestDb(db)