MM-16506: conditionally build go.mod for plugins (#11430)

* MM-16506: conditionally build go.mod for plugins

Unless `GO111MODULE=off`, generate a `go.mod` that points at the local copy of `mattermost-server` to ensure plugin tests that compile source code on demand always test with the local copy of mattermost-server.  This also fixes an issue with early adopters of `GO111MODULE=on` on the server failing to find the right version of go-i18n dependencies.

* plugin: enable testlib resource management

* customize fileutils.Find* for testlib
Этот коммит содержится в:
Jesse Hallam
2019-07-05 12:34:49 -03:00
коммит произвёл GitHub
родитель 11f1accac6
Коммит 25f3bf4a2b
3 изменённых файлов: 68 добавлений и 5 удалений

Просмотреть файл

@@ -34,11 +34,38 @@ type testResourceDetails struct {
action int8
}
// commonBaseSearchPaths is a custom version of what fileutils exposes. At some point, consolidate.
var commonBaseSearchPaths = []string{
".",
"..",
"../..",
"../../..",
"../../../..",
}
func findFile(path string) string {
return fileutils.FindPath(path, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool {
return !fileInfo.IsDir()
})
}
func findDir(dir string) (string, bool) {
found := fileutils.FindPath(dir, commonBaseSearchPaths, func(fileInfo os.FileInfo) bool {
return fileInfo.IsDir()
})
if found == "" {
return "./", false
}
return found, true
}
func getTestResourcesToSetup() []testResourceDetails {
var srcPath string
var found bool
var testResourcesToSetup = []testResourceDetails{
{"mattermost-server", "mattermost-server", resourceTypeFolder, actionSymlink},
{"i18n", "i18n", resourceTypeFolder, actionSymlink},
{"templates", "templates", resourceTypeFolder, actionSymlink},
{"tests", "tests", resourceTypeFolder, actionSymlink},
@@ -49,14 +76,14 @@ func getTestResourcesToSetup() []testResourceDetails {
// Finding resources and setting full path to source to be used for further processing
for i, testResource := range testResourcesToSetup {
if testResource.resType == resourceTypeFile {
srcPath = fileutils.FindFile(testResource.src)
srcPath = findFile(testResource.src)
if srcPath == "" {
panic(fmt.Sprintf("Failed to find file %s", testResource.src))
}
testResourcesToSetup[i].src = srcPath
} else if testResource.resType == resourceTypeFolder {
srcPath, found = fileutils.FindDir(testResource.src)
srcPath, found = findDir(testResource.src)
if found == false {
panic(fmt.Sprintf("Failed to find folder %s", testResource.src))
}