package oltp
import (
"path/filepath"
"testing"
)
// Where a repository's new tickets land is the repository's own answer:
// one dogfooding the store wants them in the DAG, one with a public
// tracker wants them out of every clone until somebody promotes them
// (ticket 66925a7a).
func TestARepositoryChoosesWhereItsTicketsLand(t *testing.T) {
db, err := Open(filepath.Join(t.TempDir(), "o.db"))
if err != nil {
t.Fatal(err)
}
defer db.Close()
if err := db.AddRepo("alpha", "/tmp/alpha", "", "public"); err != nil {
t.Fatal(err)
}
// The forge's answer until the repository gives its own, and it is
// the safe one: nothing enters the permanent record by default.
if got := db.TicketTier("alpha"); got != "" {
t.Errorf("FAIL: a fresh repository starts at %q, not the forge default", got)
} else {
t.Log("ok: a fresh repository follows the forge, which keeps tickets local")
}
if err := db.SetTicketTier("alpha", "fossil"); err != nil {
t.Fatal(err)
}
if got := db.TicketTier("alpha"); got != "fossil" {
t.Errorf("FAIL: the repository's own answer did not stick: %q", got)
} else {
t.Log("ok: a repository can say it keeps its tracker in the code history")
}
// Anything else means the forge default, rather than an unknown
// word quietly becoming a third tier.
for _, junk := range []string{"dag", "DAG", "yes", "local", ""} {
if err := db.SetTicketTier("alpha", junk); err != nil {
t.Fatal(err)
}
if got := db.TicketTier("alpha"); got != "" {
t.Errorf("FAIL: %q was kept as %q", junk, got)
}
}
t.Log("ok: an unknown answer falls back to the forge rather than inventing a tier")
// A repository nobody has heard of reads as the default, not an error.
if got := db.TicketTier("nosuch"); got != "" {
t.Errorf("FAIL: an unknown repository reads %q", got)
} else {
t.Log("ok: an unknown repository reads as the forge default")
}
}