added admin console command tests

This commit is contained in:
Gani Georgiev
2023-04-20 23:39:48 +03:00
parent 4d94673839
commit faa0a9f7dc
5 changed files with 266 additions and 43 deletions
+11 -7
View File
@@ -17,7 +17,6 @@ package migratecmd
import (
"fmt"
"log"
"os"
"path"
"path/filepath"
@@ -129,9 +128,12 @@ func (p *plugin) createCommand() *cobra.Command {
command := &cobra.Command{
Use: "migrate",
Short: "Executes app DB migration scripts",
ValidArgs: []string{"up", "down", "create", "collections"},
Long: cmdDesc,
Run: func(command *cobra.Command, args []string) {
ValidArgs: []string{"up", "down", "create", "collections"},
// prevents printing the error log twice
SilenceErrors: true,
SilenceUsage: true,
RunE: func(command *cobra.Command, args []string) error {
cmd := ""
if len(args) > 0 {
cmd = args[0]
@@ -140,22 +142,24 @@ func (p *plugin) createCommand() *cobra.Command {
switch cmd {
case "create":
if err := p.migrateCreateHandler("", args[1:], true); err != nil {
log.Fatal(err)
return err
}
case "collections":
if err := p.migrateCollectionsHandler(args[1:], true); err != nil {
log.Fatal(err)
return err
}
default:
runner, err := migrate.NewRunner(p.app.DB(), migrations.AppMigrations)
if err != nil {
log.Fatal(err)
return err
}
if err := runner.Run(args...); err != nil {
log.Fatal(err)
return err
}
}
return nil
},
}