Skip to content

Commit

Permalink
Reset environment after test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Jul 5, 2024
1 parent ce5f11e commit 58614ec
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions xdg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xdg_test
import (
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -18,6 +19,21 @@ type envSample struct {
}

func testDirs(t *testing.T, samples ...*envSample) {
// Reset environment after test execution.
environ := os.Environ()
defer func() {
os.Clearenv()
for _, env := range environ {
parts := strings.SplitN(env, "=", 2)
if len(parts) != 2 {
continue
}
os.Setenv(parts[0], parts[1])
}

xdg.Reload()
}()

// Test home directory.
require.NotEmpty(t, xdg.Home)
t.Logf("Home: %s", xdg.Home)
Expand Down

0 comments on commit 58614ec

Please sign in to comment.