yay/pkg/settings/dirs_test.go
Eng Zer Jun 83a257b16b
test: use T.TempDir to create temporary test directory (#1709)
The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-02-11 09:30:54 +01:00

24 lines
506 B
Go

package settings
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
// GIVEN no user directories and sudo user
// WHEN cache home is selected
// THEN the selected cache home should be in the tmp dir
func Test_getCacheHome(t *testing.T) {
dir := t.TempDir()
os.Unsetenv("XDG_CACHE_HOME")
os.Unsetenv("HOME")
os.Setenv("SUDO_USER", "test")
os.Setenv("TMPDIR", dir)
got, err := getCacheHome()
assert.NoError(t, err)
assert.Equal(t, filepath.Join(dir, "yay"), got)
}