mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 17:47:21 +01:00
83a257b16b
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>
24 lines
506 B
Go
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)
|
|
}
|