fix: journal:fix-headings runs from the application CLI
The command opens the database with lookupDB, as journal:image-variants does: without a published database it opens database.dsn, and without a DSN it names SUMMER_DATABASE__DSN.
This commit is contained in:
@@ -97,3 +97,50 @@ func TestImageVariantsCommandCLI(t *testing.T) {
|
||||
t.Fatalf("the CLI's WebP %s is not in the bucket: %v", variants[1].WebPKey, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFixHeadingsCommandCLI pins L1 WR-01 (D-50): journal:fix-headings in
|
||||
// the generated CLI, where no database is published: without a DSN it
|
||||
// names the setting, with one it opens database.dsn and prints the dry run.
|
||||
func TestFixHeadingsCommandCLI(t *testing.T) {
|
||||
if testShort() {
|
||||
t.Skip("Postgres")
|
||||
}
|
||||
env := newPostsEnv(t)
|
||||
var name string
|
||||
if err := env.gdb.Raw(`SELECT current_database()`).Scan(&name).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
u, err := url.Parse(adminDSN)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
u.Path = "/" + name
|
||||
post := models.Post{Title: "Cli heading", Slug: "cli-heading", Content: "<h1>A</h1><p>x</p>", ContentHTML: "<h1>A</h1><p>x</p>"}
|
||||
if err := env.gdb.Create(&post).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := func(environ ...string) (int, string) {
|
||||
t.Helper()
|
||||
cfg, err := compass.Open(compass.Options{Dir: t.TempDir(), Environ: append([]string{"SUMMER_ENV=development"}, environ...)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app := backpack.New(cfg)
|
||||
var buf strings.Builder
|
||||
root, err := bonfire.NewRootIO("summer", []bonfire.Command{console.FixHeadings(app)}, strings.NewReader(""), &buf, &buf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return bonfire.Execute(context.Background(), root, []string{"journal:fix-headings"}), buf.String()
|
||||
}
|
||||
if code, out := run(); code == 0 || !strings.Contains(out, "database is not configured (set SUMMER_DATABASE__DSN)") {
|
||||
t.Fatalf("without a DSN: %d\n%s", code, out)
|
||||
}
|
||||
code, out := run("SUMMER_DATABASE__DSN="+u.String(), "SUMMER_APP__KEY="+base64.StdEncoding.EncodeToString(bytes.Repeat([]byte("k"), 32)))
|
||||
if code != 0 || !strings.Contains(out, "Would convert 1 H1 headings in 1 posts and 0 categories. Run with --apply to save.") {
|
||||
t.Fatalf("journal:fix-headings from the CLI: %d\n%s", code, out)
|
||||
}
|
||||
if p := storedPost(t, env, post.ID); p.Content != "<h1>A</h1><p>x</p>" {
|
||||
t.Fatalf("the dry run wrote %q", p.Content)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user