summaryrefslogtreecommitdiffstats
path: root/client/go/cmd/command_tester.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/cmd/command_tester.go')
-rw-r--r--client/go/cmd/command_tester.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/client/go/cmd/command_tester.go b/client/go/cmd/command_tester.go
index 6929b59decb..8eaf6be2c22 100644
--- a/client/go/cmd/command_tester.go
+++ b/client/go/cmd/command_tester.go
@@ -27,6 +27,18 @@ type command struct {
moreArgs []string
}
+func resetFlag(f *pflag.Flag) {
+ switch v := f.Value.(type) {
+ case pflag.SliceValue:
+ _ = v.Replace([]string{})
+ default:
+ switch v.Type() {
+ case "bool", "string", "int":
+ _ = v.Set(f.DefValue)
+ }
+ }
+}
+
func execute(cmd command, t *testing.T, client *mockHttpClient) (string, string) {
if client != nil {
util.ActiveHttpClient = client
@@ -44,17 +56,8 @@ func execute(cmd command, t *testing.T, client *mockHttpClient) (string, string)
os.Setenv("VESPA_CLI_CACHE_DIR", cmd.cacheDir)
// Reset flags to their default value - persistent flags in Cobra persists over tests
- rootCmd.Flags().VisitAll(func(f *pflag.Flag) {
- switch v := f.Value.(type) {
- case pflag.SliceValue:
- _ = v.Replace([]string{})
- default:
- switch v.Type() {
- case "bool", "string", "int":
- _ = v.Set(f.DefValue)
- }
- }
- })
+ rootCmd.Flags().VisitAll(resetFlag)
+ documentCmd.Flags().VisitAll(resetFlag)
// Do not exit in tests
exitFunc = func(code int) {}