yay/pkg/settings/dirs_test.go
Jo 888fb4b1d0
Fix minor question and locale issues (#1786)
* add missing locales

* use t.Setenv instead of os.Setenv for tests

* locale: present y/n if localisation is not latin. Always accept y/n in every case

* question: use operation info for question

* edge case where localised n is equal to default y

* add tests for basic locales
2022-08-13 22:56:23 +00:00

29 lines
675 B
Go

package settings
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// 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()
require.NoError(t, os.Unsetenv("XDG_CACHE_HOME"))
require.NoError(t, os.Unsetenv("HOME"))
t.Setenv("SUDO_USER", "test")
t.Setenv("TMPDIR", dir)
got, err := getCacheHome()
require.NoError(t, err)
assert.Equal(t, filepath.Join(dir, "yay"), got)
require.NoError(t, os.Unsetenv("TMPDIR"))
require.NoError(t, os.Unsetenv("SUDO_USER"))
}