dirs_test.go 723 B

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