Files
summercms/docs/examples/blog/console/publish_test.go
Jakub Zych 9d06a78f62 feat: Artisan checklist for application commands, hints and coverage gate
- migrate, migrate:rollback and deferred:purge gain --pretend and --force;
  they and queue:clear confirm only in production on an interactive
  terminal, so deploys over SSH proceed as before
- result lines: Applied N migrations, Rolled back <id> of <plugin>,
  Cleared N jobs from <queue>
- --json for migrate:status, key:generate, route:list, admin:token:create,
  admin:token:list, admin:token:scopes and websockets:health; -q keeps the
  key and the token
- hints for an empty DSN, an unreachable database, an invalid app.key, a
  missing uploads bucket and an application binary run below its root
- flare and websockets:health return bonfire.Reported after printing
- long help and examples for every application command, greeter:hello and
  blog:publish; cmd/summer TestCommandsDocumented fails on any gap
2026-10-21 13:16:21 +02:00

48 lines
1.3 KiB
Go

package console_test
import (
"bytes"
"context"
"errors"
"testing"
"git.golem15.com/golem15/summercms/docs/examples/blog/console"
"git.golem15.com/golem15/summercms/modules/bonfire"
"gorm.io/gorm"
)
func TestPublishCommandShape(t *testing.T) {
called := false
withDB := func(ctx context.Context, fn func(*gorm.DB) error) error {
called = true
return errors.New("no database in this test")
}
cmd := console.PublishCommand(withDB)
if cmd.Name != "blog:publish" {
t.Errorf("Name = %q, want blog:publish", cmd.Name)
}
if len(cmd.Args) != 1 || cmd.Args[0].Name != "slug" || !cmd.Args[0].Required {
t.Errorf("Args = %+v, want one required slug argument", cmd.Args)
}
if cmd.Description == "" {
t.Error("Description is empty")
}
for _, problem := range bonfire.CheckDocs([]bonfire.Command{cmd}) {
t.Error(problem)
}
cmds := []bonfire.Command{cmd}
var out bytes.Buffer
if err := bonfire.Call(context.Background(), cmds, "blog:publish", nil, &out); err == nil {
t.Error("blog:publish without a slug returned no error")
}
if called {
t.Error("blog:publish without a slug reached the database")
}
err := bonfire.Call(context.Background(), cmds, "blog:publish", []string{"hello-world"}, &out)
if err == nil || !called {
t.Errorf("blog:publish hello-world: err = %v, called = %v; want the withDB error", err, called)
}
}