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:
parent
515070d513
commit
4576d0f802
2 changed files with 17 additions and 0 deletions
|
@ -22,7 +22,9 @@ const (
|
||||||
CONSTRAINT "parent_fk" FOREIGN KEY ("parent_id") REFERENCES "entity" ("id"),
|
CONSTRAINT "parent_fk" FOREIGN KEY ("parent_id") REFERENCES "entity" ("id"),
|
||||||
CONSTRAINT "entity_fk" FOREIGN KEY ("entity_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);
|
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 {
|
if _, err := conn.Exec(createEdgeTable); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if _, err := conn.Exec(createEdgeIndices); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
rollback := func() {
|
rollback := func() {
|
||||||
conn.Exec("ROLLBACK")
|
conn.Exec("ROLLBACK")
|
||||||
|
|
|
@ -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) {
|
func TestCreateChild(t *testing.T) {
|
||||||
db := newTestDb(t)
|
db := newTestDb(t)
|
||||||
defer destroyTestDb(db)
|
defer destroyTestDb(db)
|
||||||
|
|
Loading…
Add table
Reference in a new issue