41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package runner
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// `project_db` is OPTIONAL to the engine, which defaults to `<book_id>.db` beside the file — and the
|
|
// operator's own template carries no such key. Refusing here read the bank as missing on every
|
|
// deployment that used the template as written.
|
|
//
|
|
// Mutation caught: requiring the key.
|
|
func TestTheProjectDatabaseDefaultsTheWayTheEngineDefaultsIt(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, ConfigFile), []byte("book_id: sample-zh\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := projectDB(dir)
|
|
if err != nil {
|
|
t.Fatalf("a configuration without project_db: %v", err)
|
|
}
|
|
if want := filepath.Join(dir, "sample-zh.db"); got != want {
|
|
t.Errorf("project database %q, want %q", got, want)
|
|
}
|
|
// Declared explicitly, it still wins.
|
|
if err := os.WriteFile(filepath.Join(dir, ConfigFile),
|
|
[]byte("book_id: sample-zh\nproject_db: other.db\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err = projectDB(dir); err != nil || got != filepath.Join(dir, "other.db") {
|
|
t.Errorf("a declared project_db answered %q (%v)", got, err)
|
|
}
|
|
// Neither key: there is nothing to derive from, and that IS a failure.
|
|
if err := os.WriteFile(filepath.Join(dir, ConfigFile), []byte("title: x\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := projectDB(dir); err == nil {
|
|
t.Error("a configuration naming neither key was accepted")
|
|
}
|
|
}
|