Skip to content

Commit

Permalink
fix: eliminate the impact of env vars on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ggicci committed Sep 22, 2024
1 parent 18b3308 commit 9bb62a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions appdirs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package appdirs

import (
"os"
"testing"

"github.com/ggicci/appdirs/internal"
Expand All @@ -10,6 +11,10 @@ import (

const TestAppName = "testapp"

func init() {
os.Clearenv() // clear all env vars in case it affects the tests
}

func TestNewWithSpec(t *testing.T) {
app := createTestApp(t)
assert.Equal(t, TestAppName, app.App)
Expand Down Expand Up @@ -76,6 +81,7 @@ func TestRuntimeFile(t *testing.T) {
func createTestApp(t *testing.T) *AppDirs {
user := internal.FakeUser("ggicci")
spec, err := xdg.NewXDGWithUser(user)

assert.NoError(t, err)
assert.NotNil(t, spec)

Expand Down
4 changes: 4 additions & 0 deletions xdg/xdg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/stretchr/testify/assert"
)

func init() {
os.Clearenv() // clear all env vars in case it affects the tests
}

func TestNewXDG(t *testing.T) {
currentUser, err := user.Current()

Expand Down

0 comments on commit 9bb62a4

Please sign in to comment.