invokeCommandWithContext executes the command with a context and returns the captured output.
(ctx context.Context, args []string)
| 95 | |
| 96 | // invokeCommandWithContext executes the command with a context and returns the captured output. |
| 97 | func invokeCommandWithContext(ctx context.Context, args []string) (*cobra.Command, *internal.ToolboxOptions, string, error) { |
| 98 | buf := new(bytes.Buffer) |
| 99 | opts := internal.NewToolboxOptions(internal.WithIOStreams(buf, buf)) |
| 100 | c := NewCommand(opts) |
| 101 | |
| 102 | // Capture output using a buffer |
| 103 | c.SetArgs(args) |
| 104 | c.SilenceUsage = true |
| 105 | c.SilenceErrors = true |
| 106 | c.SetContext(ctx) |
| 107 | |
| 108 | err := c.Execute() |
| 109 | return c, opts, buf.String(), err |
| 110 | } |
| 111 | |
| 112 | func TestVersion(t *testing.T) { |
| 113 | data, err := os.ReadFile("version.txt") |
no test coverage detected