MCPcopy Create free account
hub / github.com/bytebase/bytebase / executeActionCommand

Function executeActionCommand

backend/tests/action_test.go:488–534  ·  view source on GitHub ↗

executeActionCommand executes the bytebase-action cobra command with given arguments

(ctx context.Context, args ...string)

Source from the content-addressed store, hash-verified

486
487// executeActionCommand executes the bytebase-action cobra command with given arguments
488func executeActionCommand(ctx context.Context, args ...string) (*ActionResult, error) {
489 // Create new world instance for test isolation
490 w := world.NewWorld()
491 w.Platform = world.LocalPlatform
492
493 // Create new command instance using the factory function
494 cmd := command.NewRootCommand(w)
495
496 // Set up output buffers
497 stdout := new(bytes.Buffer)
498 stderr := new(bytes.Buffer)
499 cmd.SetOut(stdout)
500 cmd.SetErr(stderr)
501
502 // Set arguments
503 cmd.SetArgs(args)
504
505 // Execute command
506 err := cmd.ExecuteContext(ctx)
507
508 // Get output from world.OutputMap
509 outputJSON := make(map[string]any)
510 if j, err := json.Marshal(w.OutputMap); err == nil {
511 if err := json.Unmarshal(j, &outputJSON); err != nil {
512 return nil, err
513 }
514 }
515
516 // Also parse output file if specified
517 if w.Output != "" {
518 if data, readErr := os.ReadFile(w.Output); readErr == nil {
519 var fileOutput map[string]any
520 if json.Unmarshal(data, &fileOutput) == nil {
521 for k, v := range fileOutput {
522 outputJSON[k] = v
523 }
524 }
525 }
526 }
527
528 return &ActionResult{
529 Stdout: stdout.String(),
530 Stderr: stderr.String(),
531 Error: err,
532 OutputJSON: outputJSON,
533 }, err
534}
535
536// createTestDatabase creates a test SQLite database instance and database
537func (ctl *controller) createTestDatabase(ctx context.Context, t *testing.T) *v1pb.Database {

Callers 4

TestActionCheckCommandFunction · 0.85
TestActionRolloutCommandFunction · 0.85
TestActionErrorScenariosFunction · 0.85

Calls 4

NewWorldFunction · 0.92
NewRootCommandFunction · 0.92
UnmarshalMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected