@@ -42,7 +42,9 @@ type Test struct {
4242 AccessToken string
4343 dataDir string
4444 platformUrl string
45- output * bytes.Buffer
45+ input string
46+ stdout * bytes.Buffer
47+ stdin * bytes.Reader
4648 t * testing.T
4749}
4850
@@ -124,10 +126,12 @@ func runTest(t *testing.T, testSpec TestDefinition) {
124126 AccessToken : accessToken ,
125127 dataDir : homeDir ,
126128 platformUrl : platformUrl ,
129+ input : testSpec .Input ,
127130 }
128131
129132 if testSpec .Input != "" {
130- common .SetCliIn (bytes .NewReader ([]byte (testSpec .Input )))
133+ it .stdin = bytes .NewReader ([]byte (testSpec .Input ))
134+ common .SetCliIn (it .stdin )
131135 t .Cleanup (func () {
132136 common .SetCliIn (os .Stdin )
133137 })
@@ -139,7 +143,7 @@ func runTest(t *testing.T, testSpec TestDefinition) {
139143 t .Cleanup (func () {
140144 common .SetCliOut (os .Stdout )
141145 })
142- it .output = & newOutput
146+ it .stdout = & newOutput
143147 }
144148
145149 testSpec .Test (it )
@@ -187,6 +191,7 @@ func (it *Test) RetryCommand(args []string, backoff time.Duration, timeout time.
187191
188192 for shouldRetryCommandOnError (err , onErrorContaining ) && elapsed < timeout {
189193 time .Sleep (waitDuration )
194+ it .ResetIO ()
190195 err = runPlugin ()
191196 elapsed = time .Since (start )
192197 }
@@ -209,8 +214,8 @@ func shouldRetryCommandOnError(err error, onErrorContaining []string) bool {
209214}
210215
211216func (it * Test ) CapturedOutput () []byte {
212- if it .output != nil {
213- return it .output .Bytes ()
217+ if it .stdout != nil {
218+ return it .stdout .Bytes ()
214219 }
215220 return nil
216221}
@@ -271,9 +276,12 @@ func (it *Test) DeleteWorker(workerKey string) {
271276 }
272277}
273278
274- func (it * Test ) ResetOutput () {
275- if it .output != nil {
276- it .output .Reset ()
279+ func (it * Test ) ResetIO () {
280+ if it .stdin != nil {
281+ it .stdin .Reset ([]byte (it .input ))
282+ }
283+ if it .stdout != nil {
284+ it .stdout .Reset ()
277285 }
278286}
279287
@@ -347,7 +355,7 @@ func (it *Test) Helper() {
347355
348356func (it * Test ) Run (name string , f func (t * Test )) bool {
349357 return it .t .Run (name , func (t * testing.T ) {
350- f (& Test {t : t , ServerId : it .ServerId , AccessToken : it .AccessToken , dataDir : it .dataDir , output : it .output })
358+ f (& Test {t : t , ServerId : it .ServerId , AccessToken : it .AccessToken , dataDir : it .dataDir , stdout : it .stdout , stdin : it . stdin , input : it . input })
351359 })
352360}
353361
0 commit comments