@@ -3,6 +3,7 @@ package app
33import (
44 "bytes"
55 "io"
6+ "io/ioutil"
67 "log"
78 "os"
89 "runtime"
@@ -101,11 +102,55 @@ tests:
101102func Test_TestCommand_Http_Err (t * testing.T ) {
102103 err := TestCommand ("http://error/not/a/url" , TestCommandContext {Dir : false })
103104
104- if runtime .GOOS == "windows" {
105- assert .NotNil (t , err )
106- } else {
107- assert .NotNil (t , err )
105+ assert .NotNil (t , err )
106+ }
107+
108+ func Test_TestCommand_StdIn (t * testing.T ) {
109+ tmpfile , err := ioutil .TempFile ("" , "test" )
110+ if err != nil {
111+ log .Fatal (err )
112+ }
113+ defer os .Remove (tmpfile .Name ()) //clean up
114+
115+ content := []byte (`
116+ tests:
117+ echo hello:
118+ exit-code: 0
119+ ` )
120+
121+ if _ , err := tmpfile .Write (content ); err != nil {
122+ log .Fatal (err )
123+ }
124+
125+ if _ , err := tmpfile .Seek (0 , 0 ); err != nil {
126+ log .Fatal (err )
108127 }
128+
129+ // set stdin to tempfile
130+ oldStdin := os .Stdin
131+ defer func () { os .Stdin = oldStdin }() // Restore original Stdin
132+ os .Stdin = tmpfile
133+
134+ out := captureOutput (func () {
135+ TestCommand ("-" , TestCommandContext {Verbose : false })
136+ })
137+
138+ if err := tmpfile .Close (); err != nil {
139+ log .Fatal (err )
140+ }
141+
142+ assert .Contains (t , out , "✓ [local] echo hello" )
143+ }
144+
145+ func Test_TestCommand_StdIn_Err (t * testing.T ) {
146+ // set stdin to nil
147+ oldStdin := os .Stdin
148+ defer func () { os .Stdin = oldStdin }() // Restore original Stdin
149+ os .Stdin = nil
150+
151+ err := TestCommand ("-" , TestCommandContext {Verbose : false })
152+
153+ assert .NotNil (t , err )
109154}
110155
111156func Test_ConvergeResults (t * testing.T ) {
0 commit comments