gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

testing_common.go (1422B)


      1 package iptc
      2 
      3 import (
      4 	"os"
      5 	"path"
      6 
      7 	"github.com/dsoprea/go-logging"
      8 )
      9 
     10 var (
     11 	testDataRelFilepath = "iptc.data"
     12 )
     13 
     14 var (
     15 	moduleRootPath = ""
     16 	assetsPath     = ""
     17 )
     18 
     19 // GetModuleRootPath returns the root-path of the module.
     20 func GetModuleRootPath() string {
     21 	if moduleRootPath == "" {
     22 		moduleRootPath = os.Getenv("IPTC_MODULE_ROOT_PATH")
     23 		if moduleRootPath != "" {
     24 			return moduleRootPath
     25 		}
     26 
     27 		currentWd, err := os.Getwd()
     28 		log.PanicIf(err)
     29 
     30 		currentPath := currentWd
     31 		visited := make([]string, 0)
     32 
     33 		for {
     34 			tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
     35 
     36 			_, err := os.Stat(tryStampFilepath)
     37 			if err != nil && os.IsNotExist(err) != true {
     38 				log.Panic(err)
     39 			} else if err == nil {
     40 				break
     41 			}
     42 
     43 			visited = append(visited, tryStampFilepath)
     44 
     45 			currentPath = path.Dir(currentPath)
     46 			if currentPath == "/" {
     47 				log.Panicf("could not find module-root: %v", visited)
     48 			}
     49 		}
     50 
     51 		moduleRootPath = currentPath
     52 	}
     53 
     54 	return moduleRootPath
     55 }
     56 
     57 // GetTestAssetsPath returns the path of the test-assets.
     58 func GetTestAssetsPath() string {
     59 	if assetsPath == "" {
     60 		moduleRootPath := GetModuleRootPath()
     61 		assetsPath = path.Join(moduleRootPath, "assets")
     62 	}
     63 
     64 	return assetsPath
     65 }
     66 
     67 // GetTestDataFilepath returns the file-path of the common test-data.
     68 func GetTestDataFilepath() string {
     69 	assetsPath := GetTestAssetsPath()
     70 	filepath := path.Join(assetsPath, testDataRelFilepath)
     71 
     72 	return filepath
     73 }