Skip to content

Commit

Permalink
chore: enable test shuffle and fix TestXDGConfigDirNoFile
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored and chavacava committed Nov 7, 2024
1 parent 2ae6829 commit 78c3a6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Run tests
run: go test -race ./...
run: go test -race -shuffle=on ./...
9 changes: 7 additions & 2 deletions cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import (
"os"
"testing"

"github.com/mitchellh/go-homedir"
"github.com/spf13/afero"
)

func TestMain(m *testing.M) {
os.Unsetenv("HOME")
os.Unsetenv("XDG_CONFIG_HOME")
AppFs = afero.NewMemMapFs()
homedir.DisableCache = true
os.Exit(m.Run())
}

func TestXDGConfigDirIsPrefferedFirst(t *testing.T) {
func TestXDGConfigDirIsPreferredFirst(t *testing.T) {
t.Cleanup(func() {
// reset fs after test
AppFs = afero.NewMemMapFs()
Expand All @@ -40,6 +42,7 @@ func TestXDGConfigDirIsPrefferedFirst(t *testing.T) {
}

func TestHomeConfigDir(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
homeDirPath := "/tmp-iofs/home/tester"
AppFs.MkdirAll(homeDirPath, 0755)

Expand All @@ -55,6 +58,7 @@ func TestHomeConfigDir(t *testing.T) {
}

func TestXDGConfigDir(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
xdgDirPath := "/tmp-iofs/xdg/config"
AppFs.MkdirAll(xdgDirPath, 0755)

Expand All @@ -70,11 +74,12 @@ func TestXDGConfigDir(t *testing.T) {
}

func TestXDGConfigDirNoFile(t *testing.T) {
t.Cleanup(func() { AppFs = afero.NewMemMapFs() })
xdgDirPath := "/tmp-iofs/xdg/config"
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

got := buildDefaultConfigPath()
want := xdgDirPath + "/revive.toml"
want := ""

if got != want {
t.Errorf("got %q, wanted %q", got, want)
Expand Down

0 comments on commit 78c3a6c

Please sign in to comment.