Skip to content

Commit

Permalink
reset config
Browse files Browse the repository at this point in the history
  • Loading branch information
mehran-prs committed May 16, 2024
1 parent f4e6372 commit 22af796
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 4 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestBoot(t *testing.T) {
defer resetConfigOnce()
defer resetConfig()

cmd := &cobra.Command{}
setEnv(t, prefix+"DIR", "/a/b/c")
Expand All @@ -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() {
Expand All @@ -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"}}

Expand Down

0 comments on commit 22af796

Please sign in to comment.