From 78c3a6c363edb5757ca829c9befa25bf75ac8bfc Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 4 Nov 2024 16:36:18 +0200 Subject: [PATCH] chore: enable test shuffle and fix TestXDGConfigDirNoFile --- .github/workflows/test.yaml | 2 +- cli/main_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e47e6f332..a897ef7fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,4 +22,4 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Run tests - run: go test -race ./... + run: go test -race -shuffle=on ./... diff --git a/cli/main_test.go b/cli/main_test.go index be1f97dbf..c570efdcd 100644 --- a/cli/main_test.go +++ b/cli/main_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + "github.com/mitchellh/go-homedir" "github.com/spf13/afero" ) @@ -11,10 +12,11 @@ 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() @@ -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) @@ -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) @@ -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)