Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: Improve TestSSH/ForwardGPG stability on macOS via pty.ReadRune#5739

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 3 commits intomainfrommafredri/test-fix-gpg-test
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionscli/ssh_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,6 +475,10 @@ Expire-Date: 0
// real error from being printed.
t.Cleanup(cancel)

// Wait for the prompt or any output really to indicate the command has
// started and accepting input on stdin.
_ = pty.ReadRune(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If the goal is to wait for output why not make a methodWaitForOutput instead or something, which has similar behavior but doesn't advance the reader (e.g. using Peek instead of Read)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's not a bad suggestion, I think both methods can be useful though. I'll add Peek and use that instead. 👍🏻


pty.WriteLine("echo hello 'world'")
pty.ExpectMatch("hello world")

Expand Down
41 changes: 41 additions & 0 deletionspty/ptytest/ptytest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,6 +182,47 @@ func (p *PTY) ExpectMatch(str string) string {
}
}

func (p *PTY) ReadRune(ctx context.Context) rune {
p.t.Helper()

// A timeout is mandatory, caller can decide by passing a context
// that times out.
if _, ok := ctx.Deadline(); !ok {
timeout := testutil.WaitMedium
p.logf("ReadRune ctx has no deadline, using %s", timeout)
var cancel context.CancelFunc
//nolint:gocritic // Rule guard doesn't detect that we're using testutil.Wait*.
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}

var r rune
match := make(chan error, 1)
go func() {
defer close(match)
var err error
r, _, err = p.runeReader.ReadRune()
match <- err
}()

select {
case err := <-match:
if err != nil {
p.fatalf("read error", "%v (wanted newline; got %q)", err, r)
return 0
}
p.logf("matched rune = %q", r)
return r
case <-ctx.Done():
// Ensure goroutine is cleaned up before test exit.
_ = p.close("read rune context done: " + ctx.Err().Error())
<-match

p.fatalf("read rune context done", "wanted rune; got nothing")
return 0
}
}

func (p *PTY) ReadLine() string {
p.t.Helper()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp