mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 22:49:08 +00:00
* Move scanner/test_data/* to a stand-alone directory. * Include real medias. * Rename testdata to test_data * Rename test_data/scanner -> test_data/library * Clean tests to avoid depneding env. * Rename: scanner/test_data -> scanner/test_media * Rename: test_data/bin -> test_data/mock_bin * Fix paths in tests.
50 lines
879 B
Go
50 lines
879 B
Go
package test_utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func SetPathWithCurrent(paths ...string) func() {
|
|
_, file, _, ok := runtime.Caller(1)
|
|
if !ok {
|
|
return func() {
|
|
// Return an empty function in case of error
|
|
}
|
|
}
|
|
|
|
base := filepath.Dir(file)
|
|
|
|
for i, path := range paths {
|
|
paths[i] = filepath.Join(base, path)
|
|
}
|
|
|
|
originalPath := os.Getenv("PATH")
|
|
os.Setenv("PATH", strings.Join(paths, ":"))
|
|
|
|
return func() {
|
|
os.Setenv("PATH", originalPath)
|
|
}
|
|
}
|
|
|
|
func SetEnv(key, value string) func() {
|
|
org := os.Getenv(key)
|
|
os.Setenv(key, value)
|
|
return func() {
|
|
os.Setenv(key, org)
|
|
}
|
|
}
|
|
|
|
func PathFromAPIRoot(rootRelatedPath string) string {
|
|
_, file, _, ok := runtime.Caller(0)
|
|
if !ok {
|
|
panic("Can't get the path of current function. It should not happen.")
|
|
}
|
|
|
|
base := filepath.Dir(file)
|
|
|
|
return filepath.Join(base, "..", rootRelatedPath)
|
|
}
|