test: refactor CLI create tests not to use PTY (#25807)

<!--

If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting.

-->Part of https://github.com/coder/internal/issues/1400  
  
Refactors CLI tests of the `create` command as the first batch of tests refactored to take a PTY out of the loop.

One interesting difference I noticed between PTY and a direct pipe to standard in is that on the PTY we write `\r` to enter some input, but the kernel actually sends `\n` (or maybe `\r\n`) to the process, at least on Unix. (On windows we sent `\r\n` into the PTY).  This is reflected in the implementation of the `Writer` , otherwise mostly inspired by the PTYTest equivalents.
This commit is contained in:
Spike Curtis
2026-05-28 17:50:37 -04:00
committed by GitHub
parent a16de96611
commit ee4126e913
4 changed files with 262 additions and 192 deletions
+3 -14
View File
@@ -72,15 +72,10 @@ func (p *PTY) Close() error {
if pErr != nil {
p.Logf("PTY: Close failed: %v", pErr)
}
eErr := p.Expecter.Close("PTY close")
if eErr != nil {
p.Logf("PTY: close expecter failed: %v", eErr)
}
p.Expecter.Close("PTY close")
if pErr != nil {
p.closeErr = pErr
return
}
p.closeErr = eErr
})
return p.closeErr
}
@@ -135,12 +130,6 @@ func (p *PTYCmd) Close() error {
if pErr != nil {
p.Logf("PTYCmd: Close failed: %v", pErr)
}
eErr := p.Expecter.Close("PTYCmd close")
if eErr != nil {
p.Logf("PTYCmd: close expecter failed: %v", eErr)
}
if pErr != nil {
return pErr
}
return eErr
p.Expecter.Close("PTYCmd close")
return pErr
}