Skip to content

Commit

Permalink
tests/clientcmd/virtctl.go: Add NewRepeatableVirtctlCommandWithOut
Browse files Browse the repository at this point in the history
This can be used to run a virtctl cmd and get its output.

Signed-off-by: Felix Matouschek <[email protected]>
  • Loading branch information
0xFelix committed Jan 16, 2023
1 parent 05b8283 commit 3c25c86
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/clientcmd/virtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package clientcmd

import (
"bytes"
"flag"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -48,3 +49,13 @@ func NewRepeatableVirtctlCommand(args ...string) func() error {
return cmd.Execute()
}
}

func NewRepeatableVirtctlCommandWithOut(args ...string) func() ([]byte, error) {
return func() ([]byte, error) {
out := &bytes.Buffer{}
cmd := NewVirtctlCommand(args...)
cmd.SetOut(out)
err := cmd.Execute()
return out.Bytes(), err
}
}

0 comments on commit 3c25c86

Please sign in to comment.