MCPcopy Index your code
hub / github.com/rilldata/rill / RunWithInput

Method RunWithInput

cli/testcli/testcli.go:54–81  ·  view source on GitHub ↗

RunWithInput executes the CLI with the given input and arguments and captures the output.

(t *testing.T, input string, args ...string)

Source from the content-addressed store, hash-verified

52
53// RunWithInput executes the CLI with the given input and arguments and captures the output.
54func (f *Fixture) RunWithInput(t *testing.T, input string, args ...string) Result {
55 // Buffer for capturing output
56 var out bytes.Buffer
57
58 // Create a new command helper configured for testing
59 ch, err := cmdutil.NewHelper(version.Version{}, f.HomeDir)
60 require.NoError(t, err)
61 ch.Printer.OverrideDataOutput(&out)
62 ch.Printer.OverrideHumanOutput(&out)
63
64 // Configure the root command for testing
65 root := cmd.RootCmd(ch)
66 root.SetOut(&out)
67 root.SetErr(&out)
68 if input != "" {
69 root.SetIn(bytes.NewBufferString(input + "\n"))
70 }
71 root.SetArgs(args)
72
73 // Execute the command (mirrors the logic in cli/cmd.Run)
74 err = root.ExecuteContext(t.Context())
75 code := cmd.HandleExecuteError(ch, err)
76
77 return Result{
78 ExitCode: code,
79 Output: out.String(),
80 }
81}

Callers 1

RunMethod · 0.95

Calls 7

NewHelperFunction · 0.92
RootCmdFunction · 0.92
HandleExecuteErrorFunction · 0.92
OverrideDataOutputMethod · 0.80
OverrideHumanOutputMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected