mirror of https://github.com/perkeep/perkeep.git
osutil: fail if used during tests
Disabled by default for now. Will fix cases and set by default, to proactively catch future testing mistakes. Change-Id: If292ccd105e214ee888bcad98efb4e49f052e4fd
This commit is contained in:
parent
b099f5b101
commit
8bbe100bbc
|
@ -21,13 +21,17 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"camlistore.org/pkg/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HomeDir returns the path to the user's home directory.
|
// HomeDir returns the path to the user's home directory.
|
||||||
// It returns the empty string if the value isn't known.
|
// It returns the empty string if the value isn't known.
|
||||||
func HomeDir() string {
|
func HomeDir() string {
|
||||||
|
failInTests()
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||||
}
|
}
|
||||||
|
@ -54,6 +58,7 @@ func cacheDir() string {
|
||||||
if d := os.Getenv("CAMLI_CACHE_DIR"); d != "" {
|
if d := os.Getenv("CAMLI_CACHE_DIR"); d != "" {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
failInTests()
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return filepath.Join(HomeDir(), "Library", "Caches", "Camlistore")
|
return filepath.Join(HomeDir(), "Library", "Caches", "Camlistore")
|
||||||
|
@ -82,6 +87,7 @@ func makeCacheDir() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CamliVarDir() string {
|
func CamliVarDir() string {
|
||||||
|
failInTests()
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
return filepath.Join(os.Getenv("APPDATA"), "Camlistore")
|
return filepath.Join(os.Getenv("APPDATA"), "Camlistore")
|
||||||
|
@ -92,6 +98,7 @@ func CamliVarDir() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CamliBlobRoot() string {
|
func CamliBlobRoot() string {
|
||||||
|
failInTests()
|
||||||
return filepath.Join(CamliVarDir(), "blobs")
|
return filepath.Join(CamliVarDir(), "blobs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +106,7 @@ func CamliConfigDir() string {
|
||||||
if p := os.Getenv("CAMLI_CONFIG_DIR"); p != "" {
|
if p := os.Getenv("CAMLI_CONFIG_DIR"); p != "" {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
failInTests()
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return filepath.Join(os.Getenv("APPDATA"), "Camlistore")
|
return filepath.Join(os.Getenv("APPDATA"), "Camlistore")
|
||||||
}
|
}
|
||||||
|
@ -200,3 +208,10 @@ func GoPackagePath(pkg string) (path string, err error) {
|
||||||
}
|
}
|
||||||
return path, os.ErrNotExist
|
return path, os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func failInTests() {
|
||||||
|
strict, _ := strconv.ParseBool(os.Getenv("CAMLI_STRICT_PATHS")) // temporary; will soon be always true
|
||||||
|
if strict && buildinfo.TestingLinked() {
|
||||||
|
panic("Unexpected non-hermetic use of host configuration during testing. (alternatively: the 'testing' package got accidentally linked in)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue