test: batch 06 of refactoring CLI tests not to use PTY (#25990)

Part of [coder/internal#1400](https://github.com/coder/internal/issues/1400)

Batch of refactored CLI tests to avoid creating PTYs.
This commit is contained in:
Spike Curtis
2026-06-02 15:44:36 -04:00
committed by GitHub
parent 38360518af
commit b49344519b
2 changed files with 57 additions and 79 deletions
+12
View File
@@ -85,6 +85,18 @@ func NewAttachedToInvocation(t *testing.T, invocation *serpent.Invocation) *Expe
return e
}
func NewPiped(t *testing.T) (*Expecter, io.Writer) {
r, w := io.Pipe()
e := New(t, r, "cmd")
t.Cleanup(func() {
// Close writer here at the end of the test to ensure we don't leak goroutines reading from the pipe.
_ = w.Close()
e.Close("test end")
})
return e, w
}
type Expecter struct {
t *testing.T
out *stdbuf