2020-02-27 22:03:22 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DefaultDir should honor RESTIC_CACHE_DIR on all platforms.
|
|
|
|
func TestCacheDirEnv(t *testing.T) {
|
|
|
|
cachedir := os.Getenv("RESTIC_CACHE_DIR")
|
|
|
|
|
|
|
|
if cachedir == "" {
|
|
|
|
cachedir = "/doesnt/exist"
|
|
|
|
err := os.Setenv("RESTIC_CACHE_DIR", cachedir)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-01-30 18:35:46 +00:00
|
|
|
defer func() {
|
|
|
|
err := os.Unsetenv("RESTIC_CACHE_DIR")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2020-02-27 22:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir, err := DefaultDir()
|
|
|
|
rtest.Equals(t, cachedir, dir)
|
|
|
|
rtest.OK(t, err)
|
|
|
|
}
|