Unset pinniped debug environment variable at end of integration test

Also log when setting the debug log level fails
This commit is contained in:
Margo Crawford 2021-04-08 10:14:29 -07:00
parent 6a21499ed3
commit 45e4695444
3 changed files with 16 additions and 4 deletions

View File

@ -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:

View File

@ -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")

View File

@ -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(