package index
import "testing"
// seedCheckin writes a check-in the way a fold does, so a ghost waiting
// under its hash is adopted and an existing row keeps its id.
func seedCheckin(t testing.TB, q rowQueryer, hash, date, user, comment, branch string) int64 {
t.Helper()
id, _, err := upsertCheckin(q, hash, date, user, comment)
if err != nil {
t.Fatal(err)
}
if branch != "" {
if _, err := q.Exec(`UPDATE checkin SET branch = ? WHERE id = ?`, branch, id); err != nil {
t.Fatal(err)
}
}
return id
}
// seedEdge records that parent is child's ord-th parent.
func seedEdge(t testing.TB, q rowQueryer, child, parent string, ord int) {
t.Helper()
cid, err := checkinID(q, child)
if err != nil {
t.Fatal(err)
}
pid, err := checkinID(q, parent)
if err != nil {
t.Fatal(err)
}
if _, err := q.Exec(`INSERT OR REPLACE INTO checkin_parent (child, parent, ord)
VALUES (?, ?, ?)`, cid, pid, ord); err != nil {
t.Fatal(err)
}
}
// seedSym records that a check-in wears a symbolic name.
func seedSym(t testing.TB, q rowQueryer, hash, name string) {
t.Helper()
id, err := checkinID(q, hash)
if err != nil {
t.Fatal(err)
}
if _, err := q.Exec(`INSERT INTO checkin_sym (ci, name) VALUES (?, ?)`, id, name); err != nil {
t.Fatal(err)
}
}
// seedFile records that a check-in changed path (dir 1 for a directory row).
func seedFile(t testing.TB, q rowQueryer, hash, date, path string, dir int) {
t.Helper()
id, err := checkinID(q, hash)
if err != nil {
t.Fatal(err)
}
if _, err := q.Exec(`INSERT INTO filechange (path, date, ci, dir) VALUES (?, ?, ?, ?)`,
path, date, id, dir); err != nil {
t.Fatal(err)
}
}