-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add support for writing to ptys #3591
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -49,6 +49,7 @@ type GenericCommand struct { | |||||||
stdin io.Reader | ||||||||
async bool | ||||||||
pty bool | ||||||||
ptyWriters []func(*os.File) error | ||||||||
timeout time.Duration | ||||||||
workingDir string | ||||||||
|
||||||||
|
@@ -69,8 +70,9 @@ func (gc *GenericCommand) WithWrapper(binary string, args ...string) { | |||||||
gc.helperArgs = args | ||||||||
} | ||||||||
|
||||||||
func (gc *GenericCommand) WithPseudoTTY() { | ||||||||
func (gc *GenericCommand) WithPseudoTTY(writers ...func(*os.File) error) { | ||||||||
gc.pty = true | ||||||||
gc.ptyWriters = writers | ||||||||
} | ||||||||
|
||||||||
func (gc *GenericCommand) WithStdin(r io.Reader) { | ||||||||
|
@@ -105,8 +107,18 @@ func (gc *GenericCommand) Run(expect *Expected) { | |||||||
iCmdCmd.Stdin = tty | ||||||||
iCmdCmd.Stdout = tty | ||||||||
iCmdCmd.Stderr = tty | ||||||||
defer pty.Close() | ||||||||
defer tty.Close() | ||||||||
|
||||||||
for _, writer := range gc.ptyWriters { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we use errgroup to wait for the routines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes indeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverting to draft for the time being - being abroad I may not have time to look into this immediately. Thanks @AkihiroSuda . |
||||||||
go func() { | ||||||||
err := writer(pty) | ||||||||
assert.NilError(gc.t, err) | ||||||||
}() | ||||||||
} | ||||||||
|
||||||||
defer func() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this may help when debugging issues ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review @fahedouch this is not ready though - I left it half assed a little while back, but will get it proper soon! |
||||||||
_ = tty.Close() | ||||||||
_ = pty.Close() | ||||||||
}() | ||||||||
} | ||||||||
|
||||||||
// Run it | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't move
defer tty.Close()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not mandatory but you can just defer closing the tty before the goroutines loop