@@ -25,7 +25,6 @@ import (
2525"runtime"
2626"strconv"
2727"strings"
28- "sync"
2928"sync/atomic"
3029"testing"
3130"time"
@@ -253,10 +252,8 @@ func TestServer(t *testing.T) {
253252"--access-url" ,"http://localhost:3000/" ,
254253"--cache-dir" ,t .TempDir (),
255254)
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 ))
260257clitest .Start (t ,inv )
261258
262259// Wait for startup
@@ -270,8 +267,9 @@ func TestServer(t *testing.T) {
270267// normally shown to the user, so we'll ignore them.
271268ignoreLines := []string {
272269"isn't externally reachable" ,
273- "install.sh will be unavailable " ,
270+ "open install.sh: file does not exist " ,
274271"telemetry disabled, unable to notify of security issues" ,
272+ "installed terraform version newer than expected" ,
275273}
276274
277275countLines := func (fullOutput string )int {
@@ -282,9 +280,11 @@ func TestServer(t *testing.T) {
282280for _ ,line := range linesByNewline {
283281for _ ,ignoreLine := range ignoreLines {
284282if strings .Contains (line ,ignoreLine ) {
283+ t .Logf ("Ignoring: %q" ,line )
285284continue lineLoop
286285}
287286}
287+ t .Logf ("Counting: %q" ,line )
288288if line == "" {
289289// Empty lines take up one line.
290290countByWidth ++
@@ -295,17 +295,10 @@ func TestServer(t *testing.T) {
295295return countByWidth
296296}
297297
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 )
309302})
310303
311304t .Run ("OAuth2GitHubDefaultProvider" ,func (t * testing.T ) {
@@ -2355,22 +2348,3 @@ func mockTelemetryServer(t *testing.T) (*url.URL, chan *telemetry.Deployment, ch
23552348
23562349return serverURL ,deployment ,snapshot
23572350}
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- }