2021-10-15 19:55:38 +02:00
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-08-05 22:55:54 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-10-15 19:55:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
2022-02-11 09:30:54 +01:00
|
|
|
dir := t.TempDir()
|
2022-08-05 22:55:54 +02:00
|
|
|
require.NoError(t, os.Unsetenv("XDG_CACHE_HOME"))
|
|
|
|
require.NoError(t, os.Unsetenv("HOME"))
|
2022-08-14 00:56:23 +02:00
|
|
|
t.Setenv("SUDO_USER", "test")
|
|
|
|
t.Setenv("TMPDIR", dir)
|
2022-08-05 22:55:54 +02:00
|
|
|
|
2021-10-15 19:55:38 +02:00
|
|
|
got, err := getCacheHome()
|
2022-08-05 22:55:54 +02:00
|
|
|
require.NoError(t, err)
|
2021-10-15 19:55:38 +02:00
|
|
|
assert.Equal(t, filepath.Join(dir, "yay"), got)
|
2022-08-05 22:55:54 +02:00
|
|
|
|
|
|
|
require.NoError(t, os.Unsetenv("TMPDIR"))
|
|
|
|
require.NoError(t, os.Unsetenv("SUDO_USER"))
|
2021-10-15 19:55:38 +02:00
|
|
|
}
|