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") } 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) } }