mirror of https://github.com/databricks/cli.git
Add NoLog option on testcli.Runner (#2183)
## Changes Setting Verbose=false on testcli.Runner disables all logging related to running process (stdout, stderr, error, args). I'm using this in #2184 where I'm using testcli runner to run acceptance tests and seeing all output is not useful. ## Tests Manually inspecting test output in #2184
This commit is contained in:
parent
26f527ef64
commit
64fc1c8fe7
|
@ -39,6 +39,8 @@ type Runner struct {
|
|||
StderrLines <-chan string
|
||||
|
||||
errch <-chan error
|
||||
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
func consumeLines(ctx context.Context, wg *sync.WaitGroup, r io.Reader) <-chan string {
|
||||
|
@ -139,7 +141,9 @@ func (r *Runner) RunBackground() {
|
|||
go func() {
|
||||
err := root.Execute(ctx, cli)
|
||||
if err != nil {
|
||||
r.Logf("Error running command: %s", err)
|
||||
if r.Verbose {
|
||||
r.Logf("Error running command: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Close pipes to signal EOF.
|
||||
|
@ -154,7 +158,9 @@ func (r *Runner) RunBackground() {
|
|||
// Make a copy of the buffer such that it remains "unread".
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(r.stdout.Bytes()))
|
||||
for scanner.Scan() {
|
||||
r.Logf("[databricks stdout]: %s", scanner.Text())
|
||||
if r.Verbose {
|
||||
r.Logf("[databricks stdout]: %s", scanner.Text())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +168,9 @@ func (r *Runner) RunBackground() {
|
|||
// Make a copy of the buffer such that it remains "unread".
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(r.stderr.Bytes()))
|
||||
for scanner.Scan() {
|
||||
r.Logf("[databricks stderr]: %s", scanner.Text())
|
||||
if r.Verbose {
|
||||
r.Logf("[databricks stderr]: %s", scanner.Text())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,18 +204,24 @@ func (r *Runner) Run() (bytes.Buffer, bytes.Buffer, error) {
|
|||
cli.SetErr(&stderr)
|
||||
cli.SetArgs(r.args)
|
||||
|
||||
r.Logf(" args: %s", strings.Join(r.args, ", "))
|
||||
if r.Verbose {
|
||||
r.Logf(" args: %s", strings.Join(r.args, ", "))
|
||||
}
|
||||
|
||||
err := root.Execute(ctx, cli)
|
||||
if err != nil {
|
||||
r.Logf(" error: %s", err)
|
||||
if r.Verbose {
|
||||
r.Logf(" error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if stdout.Len() > 0 {
|
||||
// Make a copy of the buffer such that it remains "unread".
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(stdout.Bytes()))
|
||||
for scanner.Scan() {
|
||||
r.Logf("stdout: %s", scanner.Text())
|
||||
if r.Verbose {
|
||||
r.Logf("stdout: %s", scanner.Text())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,7 +229,9 @@ func (r *Runner) Run() (bytes.Buffer, bytes.Buffer, error) {
|
|||
// Make a copy of the buffer such that it remains "unread".
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(stderr.Bytes()))
|
||||
for scanner.Scan() {
|
||||
r.Logf("stderr: %s", scanner.Text())
|
||||
if r.Verbose {
|
||||
r.Logf("stderr: %s", scanner.Text())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,8 +291,9 @@ func NewRunner(t testutil.TestingT, ctx context.Context, args ...string) *Runner
|
|||
return &Runner{
|
||||
TestingT: t,
|
||||
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
Verbose: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue