dirs_test.go 568 B

123456789101112131415161718192021222324
  1. package settings
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. // GIVEN no user directories and sudo user
  9. // WHEN cache home is selected
  10. // THEN the selected cache home should be in the tmp dir
  11. func Test_getCacheHome(t *testing.T) {
  12. dir, err := os.MkdirTemp(os.TempDir(), "yay-cache-home")
  13. assert.NoError(t, err)
  14. os.Unsetenv("XDG_CACHE_HOME")
  15. os.Unsetenv("HOME")
  16. os.Setenv("SUDO_USER", "test")
  17. os.Setenv("TMPDIR", dir)
  18. got, err := getCacheHome()
  19. assert.NoError(t, err)
  20. assert.Equal(t, filepath.Join(dir, "yay"), got)
  21. }