From 45e4695444157f9c6b96db349e046197159b706f Mon Sep 17 00:00:00 2001 From: Margo Crawford Date: Thu, 8 Apr 2021 10:14:29 -0700 Subject: [PATCH] Unset pinniped debug environment variable at end of integration test Also log when setting the debug log level fails --- cmd/pinniped/cmd/login_oidc.go | 13 ++++++++++--- cmd/pinniped/cmd/login_static.go | 5 ++++- test/integration/cli_test.go | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/pinniped/cmd/login_oidc.go b/cmd/pinniped/cmd/login_oidc.go index 88a5d36a..c7ad0594 100644 --- a/cmd/pinniped/cmd/login_oidc.go +++ b/cmd/pinniped/cmd/login_oidc.go @@ -112,7 +112,10 @@ func oidcLoginCommand(deps oidcLoginCommandDeps) *cobra.Command { } func runOIDCLogin(cmd *cobra.Command, deps oidcLoginCommandDeps, flags oidcLoginFlags) error { - SetLogLevel() + err := SetLogLevel() + if err != nil { + plog.WarningErr("Received error while setting log level", err) + } // Initialize the session cache. var sessionOptions []filesession.Option @@ -261,10 +264,14 @@ func tokenCredential(token *oidctypes.Token) *clientauthv1beta1.ExecCredential { return &cred } -func SetLogLevel() { +func SetLogLevel() error { if os.Getenv("PINNIPED_DEBUG") == "true" { - _ = plog.ValidateAndSetLogLevelGlobally(plog.LevelDebug) + err := plog.ValidateAndSetLogLevelGlobally(plog.LevelDebug) + if err != nil { + return err + } } + return nil } // mustGetConfigDir returns a directory that follows the XDG base directory convention: diff --git a/cmd/pinniped/cmd/login_static.go b/cmd/pinniped/cmd/login_static.go index 4a6b0513..dcdc8c4d 100644 --- a/cmd/pinniped/cmd/login_static.go +++ b/cmd/pinniped/cmd/login_static.go @@ -84,7 +84,10 @@ func staticLoginCommand(deps staticLoginDeps) *cobra.Command { } func runStaticLogin(out io.Writer, deps staticLoginDeps, flags staticLoginParams) error { - SetLogLevel() + err := SetLogLevel() + if err != nil { + plog.WarningErr("Received error while setting log level", err) + } if flags.staticToken == "" && flags.staticTokenEnvName == "" { return fmt.Errorf("one of --token or --token-env must be set") diff --git a/test/integration/cli_test.go b/test/integration/cli_test.go index 2181290a..622e9ba5 100644 --- a/test/integration/cli_test.go +++ b/test/integration/cli_test.go @@ -256,6 +256,8 @@ func TestCLILoginOIDC(t *testing.T) { require.Contains(t, cmd4StringOutput, "Found unexpired cached token") require.Contains(t, cmd4StringOutput, "No concierge configured, skipping token credential exchange") require.Contains(t, cmd4StringOutput, credOutput3.Status.Token) + err = os.Unsetenv("PINNIPED_DEBUG") + require.NoError(t, err) } func runPinnipedLoginOIDC(