tests/clientcmd/virtctl.go: Add NewRepeatableVirtctlCommandWithOut
This can be used to run a virtctl cmd and get its output.
package clientcmd
import (
+ "bytes"
"flag"
"github.com/spf13/cobra"
@@ -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
+ }
+}
