@@ -25,7 +25,6 @@ import (
25
25
"runtime"
26
26
"strconv"
27
27
"strings"
28
- "sync"
29
28
"sync/atomic"
30
29
"testing"
31
30
"time"
@@ -253,10 +252,8 @@ func TestServer(t *testing.T) {
253
252
"--access-url" , "http://localhost:3000/" ,
254
253
"--cache-dir" , t .TempDir (),
255
254
)
256
- stdoutRW := syncReaderWriter {}
257
- stderrRW := syncReaderWriter {}
258
- inv .Stdout = io .MultiWriter (os .Stdout , & stdoutRW )
259
- inv .Stderr = io .MultiWriter (os .Stderr , & stderrRW )
255
+ pty := ptytest .New (t ).Attach (inv )
256
+ require .NoError (t , pty .Resize (20 , 80 ))
260
257
clitest .Start (t , inv )
261
258
262
259
// Wait for startup
@@ -270,8 +267,9 @@ func TestServer(t *testing.T) {
270
267
// normally shown to the user, so we'll ignore them.
271
268
ignoreLines := []string {
272
269
"isn't externally reachable" ,
273
- "install.sh will be unavailable " ,
270
+ "open install.sh: file does not exist " ,
274
271
"telemetry disabled, unable to notify of security issues" ,
272
+ "installed terraform version newer than expected" ,
275
273
}
276
274
277
275
countLines := func (fullOutput string ) int {
@@ -282,9 +280,11 @@ func TestServer(t *testing.T) {
282
280
for _ , line := range linesByNewline {
283
281
for _ , ignoreLine := range ignoreLines {
284
282
if strings .Contains (line , ignoreLine ) {
283
+ t .Logf ("Ignoring: %q" , line )
285
284
continue lineLoop
286
285
}
287
286
}
287
+ t .Logf ("Counting: %q" , line )
288
288
if line == "" {
289
289
// Empty lines take up one line.
290
290
countByWidth ++
@@ -295,17 +295,10 @@ func TestServer(t *testing.T) {
295
295
return countByWidth
296
296
}
297
297
298
- stdout , err := io .ReadAll (& stdoutRW )
299
- if err != nil {
300
- t .Fatalf ("failed to read stdout: %v" , err )
301
- }
302
- stderr , err := io .ReadAll (& stderrRW )
303
- if err != nil {
304
- t .Fatalf ("failed to read stderr: %v" , err )
305
- }
306
-
307
- numLines := countLines (string (stdout )) + countLines (string (stderr ))
308
- require .Less (t , numLines , 20 )
298
+ out := pty .ReadAll ()
299
+ numLines := countLines (string (out ))
300
+ t .Logf ("numLines: %d" , numLines )
301
+ require .Less (t , numLines , 12 , "expected less than 12 lines of output (terminal width 80), got %d" , numLines )
309
302
})
310
303
311
304
t .Run ("OAuth2GitHubDefaultProvider" , func (t * testing.T ) {
@@ -2355,22 +2348,3 @@ func mockTelemetryServer(t *testing.T) (*url.URL, chan *telemetry.Deployment, ch
2355
2348
2356
2349
return serverURL , deployment , snapshot
2357
2350
}
2358
-
2359
- // syncWriter provides a thread-safe io.ReadWriter implementation
2360
- type syncReaderWriter struct {
2361
- buf bytes.Buffer
2362
- mu sync.Mutex
2363
- }
2364
-
2365
- func (w * syncReaderWriter ) Write (p []byte ) (n int , err error ) {
2366
- w .mu .Lock ()
2367
- defer w .mu .Unlock ()
2368
- return w .buf .Write (p )
2369
- }
2370
-
2371
- func (w * syncReaderWriter ) Read (p []byte ) (n int , err error ) {
2372
- w .mu .Lock ()
2373
- defer w .mu .Unlock ()
2374
-
2375
- return w .buf .Read (p )
2376
- }
0 commit comments