Add some test debug logging when running the CLI.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2021-03-23 12:07:34 -05:00
parent ce5b05f912
commit c0d32f10b2
No known key found for this signature in database
GPG Key ID: EAE88AD172C5AE2D
2 changed files with 7 additions and 1 deletions

View File

@ -107,12 +107,14 @@ func TestCLIGetKubeconfigStaticToken(t *testing.T) {
func runPinnipedCLI(t *testing.T, envVars []string, pinnipedExe string, args ...string) (string, string) {
t.Helper()
start := time.Now()
var stdout, stderr bytes.Buffer
cmd := exec.Command(pinnipedExe, args...)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = envVars
require.NoErrorf(t, cmd.Run(), "stderr:\n%s\n\nstdout:\n%s\n\n", stderr.String(), stdout.String())
t.Logf("ran %q in %s", library.MaskTokens("pinniped "+strings.Join(args, " ")), time.Since(start).Round(time.Millisecond))
return stdout.String(), stderr.String()
}

View File

@ -1,4 +1,4 @@
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package library
@ -43,6 +43,10 @@ func MaskTokens(in string) string {
if strings.Count(t, ".") >= 4 {
return t
}
// Another heuristic, things that start with "--" are probably CLI flags.
if strings.HasPrefix(t, "--") {
return t
}
return fmt.Sprintf("[...%d bytes...]", len(t))
})
}