diff --git a/testlib/resources.go b/testlib/resources.go index 681e6607df..39645104a3 100644 --- a/testlib/resources.go +++ b/testlib/resources.go @@ -36,17 +36,26 @@ type testResourceDetails struct { action int8 } -// commonBaseSearchPaths is a custom version of what fileutils exposes. At some point, consolidate. -var commonBaseSearchPaths = []string{ - ".", - "..", - "../..", - "../../..", - "../../../..", +// getCommonBaseSearchPaths() is a custom version of what fileutils exposes. At some point, consolidate. +func getCommonBaseSearchPaths() []string { + paths := []string{ + ".", + "..", + "../..", + "../../..", + "../../../..", + } + + // this enables the server to be used in tests from a different repository + if mmPath := os.Getenv("MM_SERVER_PATH"); mmPath != "" { + paths = append(paths, mmPath) + } + + return paths } func findFile(path string) string { - return fileutils.FindPath(path, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool { + return fileutils.FindPath(path, getCommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool { return !fileInfo.IsDir() }) } @@ -61,7 +70,7 @@ func findDir(dir string) (string, bool) { return path.Dir(srcPath), true } - found := fileutils.FindPath(dir, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool { + found := fileutils.FindPath(dir, getCommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool { return fileInfo.IsDir() }) if found == "" { diff --git a/utils/i18n.go b/utils/i18n.go index 6668da5059..43ef776123 100644 --- a/utils/i18n.go +++ b/utils/i18n.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os" "path/filepath" "strings" @@ -32,7 +33,13 @@ func TranslationsPreInit() error { // segfault trying to handle the error, and the untranslated IDs are strictly better. T = TfuncWithFallback("en") TDefault = TfuncWithFallback("en") - return InitTranslationsWithDir("i18n") + + translationsDir := "i18n" + if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" { + translationsDir = filepath.Join(mattermostPath, "i18n") + } + + return InitTranslationsWithDir(translationsDir) } func InitTranslations(localizationSettings model.LocalizationSettings) error { @@ -46,7 +53,7 @@ func InitTranslations(localizationSettings model.LocalizationSettings) error { func InitTranslationsWithDir(dir string) error { i18nDirectory, found := fileutils.FindDirRelBinary(dir) if !found { - return fmt.Errorf("Unable to find i18n directory") + return fmt.Errorf(fmt.Sprintf("Unable to find i18n directory at %q", dir)) } files, _ := ioutil.ReadDir(i18nDirectory)