Skip to content

Commit

Permalink
expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k3rn31 committed Aug 9, 2022
1 parent cb29618 commit 4e27c98
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestConfigPaths(t *testing.T) {
var want []string

// First global
if runtime.GOOS != "windows" {
if runtime.GOOS != windowsOs {
want = append(want, "/etc/gremlins")
}

Expand All @@ -163,6 +163,36 @@ func TestConfigPaths(t *testing.T) {
}
})

t.Run("no module root if not in go module", func(t *testing.T) {
oldDir, _ := os.Getwd()
_ = os.Chdir(t.TempDir())
defer func(dir string) {
_ = os.Chdir(dir)
}(oldDir)

var want []string

// First global
if runtime.GOOS != windowsOs {
want = append(want, "/etc/gremlins")
}

// Then $XDG_CONFIG_HOME and $HOME
want = append(want,
filepath.Join(home, ".config", "gremlins", "gremlins"),
filepath.Join(home, ".gremlins"),
)

// Last current folder
want = append(want, ".")

got := defaultConfigPaths()

if !cmp.Equal(got, want) {
t.Errorf(cmp.Diff(got, want))
}
})

t.Run("when XDG_CONFIG_HOME is set, it lookups in that locations", func(t *testing.T) {
oldDir, _ := os.Getwd()
_ = os.Chdir("testdata/config1")
Expand All @@ -176,7 +206,7 @@ func TestConfigPaths(t *testing.T) {
var want []string

// First global
if runtime.GOOS != "windows" {
if runtime.GOOS != windowsOs {
want = append(want, "/etc/gremlins")
}

Expand Down Expand Up @@ -259,3 +289,15 @@ func TestViperSynchronisedAccess(t *testing.T) {
})
}
}

func TestReset(t *testing.T) {
Set("test.key", true)

Reset()

got := Get[bool]("test.key")

if got != false {
t.Errorf("expected config to be reset")
}
}

0 comments on commit 4e27c98

Please sign in to comment.