MCPcopy Create free account
hub / github.com/commander-cli/commander / Test_TestCommand_StdIn

Function Test_TestCommand_StdIn

pkg/app/test_command_test.go:126–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func Test_TestCommand_StdIn(t *testing.T) {
127 tmpfile, err := ioutil.TempFile("", "test")
128 if err != nil {
129 log.Fatal(err)
130 }
131 defer os.Remove(tmpfile.Name()) //clean up
132
133 content := []byte(`
134tests:
135 echo hello:
136 exit-code: 0
137`)
138
139 if _, err := tmpfile.Write(content); err != nil {
140 log.Fatal(err)
141 }
142
143 if _, err := tmpfile.Seek(0, 0); err != nil {
144 log.Fatal(err)
145 }
146
147 // set stdin to tempfile
148 oldStdin := os.Stdin
149 defer func() { os.Stdin = oldStdin }() // Restore original Stdin
150 os.Stdin = tmpfile
151
152 out := captureOutput(func() {
153 TestCommand("-", TestCommandContext{Verbose: false})
154 })
155
156 if err := tmpfile.Close(); err != nil {
157 log.Fatal(err)
158 }
159
160 assert.Contains(t, out, "✓ [local] echo hello")
161}
162
163func Test_TestCommand_StdIn_Err(t *testing.T) {
164 // set stdin to nil

Callers

nothing calls this directly

Calls 2

captureOutputFunction · 0.85
TestCommandFunction · 0.85

Tested by

no test coverage detected