-
Notifications
You must be signed in to change notification settings - Fork 888
feat: capture cli logs in tests #10669
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
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ import ( | |
"testing" | ||
"unicode" | ||
|
||
"cdr.dev/slog" | ||
|
||
"github.com/spf13/pflag" | ||
"golang.org/x/exp/slices" | ||
"golang.org/x/xerrors" | ||
|
@@ -170,6 +172,7 @@ func (c *Cmd) Invoke(args ...string) *Invocation { | |
Stdout: io.Discard, | ||
Stderr: io.Discard, | ||
Stdin: strings.NewReader(""), | ||
Logger: slog.Make(), | ||
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. At least for tests, this could be a named logger based on the command being run? Might help when there are multiple commands being run. 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. Right now, it's just called "cli" for any Invocations created by |
||
} | ||
} | ||
|
||
|
@@ -185,6 +188,7 @@ type Invocation struct { | |
Stdout io.Writer | ||
Stderr io.Writer | ||
Stdin io.Reader | ||
Logger slog.Logger | ||
|
||
// testing | ||
signalNotifyContext func(parent context.Context, signals ...os.Signal) (ctx context.Context, stop context.CancelFunc) | ||
|
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.
attaching a PTY to agent invocation results in logging twice to the test log: once via our logger and a second time via stderr. I modified the test to not need the PTY at all.