...

Source file src/github.com/dsoprea/go-png-image-structure/v2/testing_common.go

Documentation: github.com/dsoprea/go-png-image-structure/v2

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

View as plain text