Skip to content

Commit

Permalink
Merge pull request #103 from juju/add-test-helper
Browse files Browse the repository at this point in the history
#103

Move a method from the juju/juju repo to the upstream command repo where it is better suited to be.
The method is a helper used to tests to run a command with a specified context.
  • Loading branch information
jujubot authored Aug 6, 2023
2 parents 838ea76 + 059f9de commit a0647fc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmdtesting/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ func runCommand(ctx *cmd.Context, com cmd.Command, args []string) (*cmd.Context,
return ctx, com.Run(ctx)
}

// RunCommandWithContext runs the command asynchronously with
// the specified context and returns a channel which providers
// the command's errors.
func RunCommandWithContext(ctx *cmd.Context, com cmd.Command, args ...string) chan error {
if ctx == nil {
panic("ctx == nil")
}
errc := make(chan error, 1)
go func() {
if err := InitCommand(com, args); err != nil {
errc <- err
return
}
errc <- com.Run(ctx)
}()
return errc
}

// TestInit checks that a command initialises correctly with the given set of
// arguments.
func TestInit(c *gc.C, com cmd.Command, args []string, errPat string) {
Expand Down

0 comments on commit a0647fc

Please sign in to comment.