From 22af796950ba71854be64cc9edd1a6f4b24d5d1c Mon Sep 17 00:00:00 2001 From: mehran-prs Date: Thu, 16 May 2024 19:44:02 +0330 Subject: [PATCH] reset config --- config_test.go | 8 ++++---- finder_test.go | 2 ++ main_test.go | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config_test.go b/config_test.go index ae568e3..3b46450 100644 --- a/config_test.go +++ b/config_test.go @@ -19,12 +19,12 @@ func setEnv(t *testing.T, key, value string) { }) } -func resetConfigOnce() { +func resetConfig() { cfgOnce = sync.Once{} } func TestLoadDefaultConfig(t *testing.T) { - defer resetConfigOnce() + defer resetConfig() setEnv(t, "EDITOR", "abc") // Default Values homeDir, err := os.UserHomeDir() @@ -42,7 +42,7 @@ func TestLoadDefaultConfig(t *testing.T) { } func TestLoadConfig(t *testing.T) { - defer resetConfigOnce() + defer resetConfig() // Default Values setEnv(t, "TEST_DIR", "/ab/c") setEnv(t, "TEST_FILE_VIEWER_CMD", "touch a") @@ -66,7 +66,7 @@ func TestLoadConfig(t *testing.T) { } func TestLoadConfigInheritance(t *testing.T) { - defer resetConfigOnce() + defer resetConfig() setEnv(t, "TEST_DIR", "/ab/c") setEnv(t, "SNIP_DIR", "/ab/d") setEnv(t, "SNIP_GIT", "abc") diff --git a/finder_test.go b/finder_test.go index 78b8695..7a24f84 100644 --- a/finder_test.go +++ b/finder_test.go @@ -33,6 +33,8 @@ func TestBasename(t *testing.T) { } func TestFindFiles(t *testing.T) { + defer resetConfig() + Cfg = &Config{Verbose: false} searchDir := t.TempDir() paths := []string{ diff --git a/main_test.go b/main_test.go index 8a1960d..296ffc7 100644 --- a/main_test.go +++ b/main_test.go @@ -9,7 +9,7 @@ import ( ) func TestBoot(t *testing.T) { - defer resetConfigOnce() + defer resetConfig() cmd := &cobra.Command{} setEnv(t, prefix+"DIR", "/a/b/c") @@ -18,7 +18,7 @@ func TestBoot(t *testing.T) { } func TestBootAndShutdown(t *testing.T) { - defer resetConfigOnce() + defer resetConfig() f, err := os.CreateTemp("", "abc") assertEqual(t, err, nil) defer func() { @@ -44,6 +44,8 @@ func TestBootAndShutdown(t *testing.T) { } func TestCobraAutocompleteFilename(t *testing.T) { + defer resetConfig() + searchDir := t.TempDir() Cfg = &Config{Dir: searchDir, Exclude: []string{".git"}}