dirs_test.go 506 B

1234567891011121314151617181920212223
  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 := t.TempDir()
  13. os.Unsetenv("XDG_CACHE_HOME")
  14. os.Unsetenv("HOME")
  15. os.Setenv("SUDO_USER", "test")
  16. os.Setenv("TMPDIR", dir)
  17. got, err := getCacheHome()
  18. assert.NoError(t, err)
  19. assert.Equal(t, filepath.Join(dir, "yay"), got)
  20. }