MCPcopy
hub / github.com/larksuite/cli / newTestRuntimeWithStdin

Function newTestRuntimeWithStdin

shortcuts/common/runner_input_test.go:17–34  ·  view source on GitHub ↗

newTestRuntimeWithStdin creates a RuntimeContext with string flags and a fake stdin.

(flags map[string]string, stdin string)

Source from the content-addressed store, hash-verified

15
16// newTestRuntimeWithStdin creates a RuntimeContext with string flags and a fake stdin.
17func newTestRuntimeWithStdin(flags map[string]string, stdin string) *RuntimeContext {
18 cmd := &cobra.Command{Use: "test"}
19 for name := range flags {
20 cmd.Flags().String(name, "", "")
21 }
22 cmd.ParseFlags(nil)
23 for name, val := range flags {
24 cmd.Flags().Set(name, val)
25 }
26 return &RuntimeContext{
27 Cmd: cmd,
28 Factory: &cmdutil.Factory{
29 IOStreams: &cmdutil.IOStreams{
30 In: strings.NewReader(stdin),
31 },
32 },
33 }
34}
35
36func TestResolveInputFlags_DirectValue(t *testing.T) {
37 rctx := newTestRuntimeWithStdin(map[string]string{"markdown": "hello world"}, "")

Calls 2

SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected