(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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(` |
| 134 | tests: |
| 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 | |
| 163 | func Test_TestCommand_StdIn_Err(t *testing.T) { |
| 164 | // set stdin to nil |
nothing calls this directly
no test coverage detected