From fb8a7e26e620ca265ec21350ed8a7a2feb717daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 4 Dec 2019 16:47:11 +0100 Subject: [PATCH] Reset bool flags so they don't leak between tests --- command/pr_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/command/pr_test.go b/command/pr_test.go index 9e0da8331..010957502 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -35,10 +35,15 @@ func RunCommand(cmd *cobra.Command, args string) (string, error) { outBuf := bytes.Buffer{} cmd.SetOut(&outBuf) - // Reset flag slice values so they don't leak between tests - cmd.Flags().Visit(func(f *pflag.Flag) { - if v, ok := f.Value.(pflag.SliceValue); ok { + // Reset flag values so they don't leak between tests + cmd.Flags().VisitAll(func(f *pflag.Flag) { + switch v := f.Value.(type) { + case pflag.SliceValue: v.Replace([]string{}) + default: + if v.Type() == "bool" { + v.Set(f.DefValue) + } } })