mirror of https://github.com/dsoprea/go-exif.git
Minor sensible testing refactors
parent
a350bacdac
commit
ca8584a0e1
|
@ -11,10 +11,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
assetsPath = ""
|
||||
testImageFilepath = ""
|
||||
testExifData = make([]byte, 0)
|
||||
moduleRootPath = ""
|
||||
moduleRootPath = ""
|
||||
|
||||
testExifData []byte = nil
|
||||
|
||||
// EncodeDefaultByteOrder is the default byte-order for encoding operations.
|
||||
EncodeDefaultByteOrder = binary.BigEndian
|
||||
|
@ -24,68 +23,65 @@ var (
|
|||
)
|
||||
|
||||
func GetModuleRootPath() string {
|
||||
if moduleRootPath != "" {
|
||||
return moduleRootPath
|
||||
}
|
||||
|
||||
moduleRootPath := os.Getenv("EXIF_MODULE_ROOT_PATH")
|
||||
if moduleRootPath != "" {
|
||||
return moduleRootPath
|
||||
}
|
||||
|
||||
currentWd, err := os.Getwd()
|
||||
log.PanicIf(err)
|
||||
|
||||
currentPath := currentWd
|
||||
visited := make([]string, 0)
|
||||
|
||||
for {
|
||||
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
|
||||
|
||||
_, err := os.Stat(tryStampFilepath)
|
||||
if err != nil && os.IsNotExist(err) != true {
|
||||
log.Panic(err)
|
||||
} else if err == nil {
|
||||
break
|
||||
if moduleRootPath == "" {
|
||||
moduleRootPath := os.Getenv("EXIF_MODULE_ROOT_PATH")
|
||||
if moduleRootPath != "" {
|
||||
return moduleRootPath
|
||||
}
|
||||
|
||||
visited = append(visited, tryStampFilepath)
|
||||
currentWd, err := os.Getwd()
|
||||
log.PanicIf(err)
|
||||
|
||||
currentPath = path.Dir(currentPath)
|
||||
if currentPath == "/" {
|
||||
log.Panicf("could not find module-root: %v", visited)
|
||||
currentPath := currentWd
|
||||
visited := make([]string, 0)
|
||||
|
||||
for {
|
||||
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
|
||||
|
||||
_, err := os.Stat(tryStampFilepath)
|
||||
if err != nil && os.IsNotExist(err) != true {
|
||||
log.Panic(err)
|
||||
} else if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
visited = append(visited, tryStampFilepath)
|
||||
|
||||
currentPath = path.Dir(currentPath)
|
||||
if currentPath == "/" {
|
||||
log.Panicf("could not find module-root: %v", visited)
|
||||
}
|
||||
}
|
||||
|
||||
moduleRootPath = currentPath
|
||||
}
|
||||
|
||||
return currentPath
|
||||
return moduleRootPath
|
||||
}
|
||||
|
||||
func getTestAssetsPath() string {
|
||||
if assetsPath == "" {
|
||||
moduleRootPath := GetModuleRootPath()
|
||||
assetsPath = path.Join(moduleRootPath, "assets")
|
||||
}
|
||||
func GetTestAssetsPath() string {
|
||||
moduleRootPath := GetModuleRootPath()
|
||||
assetsPath := path.Join(moduleRootPath, "assets")
|
||||
|
||||
return assetsPath
|
||||
}
|
||||
|
||||
func getTestImageFilepath() string {
|
||||
if testImageFilepath == "" {
|
||||
assetsPath := getTestAssetsPath()
|
||||
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")
|
||||
}
|
||||
|
||||
assetsPath := GetTestAssetsPath()
|
||||
testImageFilepath := path.Join(assetsPath, "NDM_8901.jpg")
|
||||
return testImageFilepath
|
||||
}
|
||||
|
||||
func getTestExifData() []byte {
|
||||
assetsPath := getTestAssetsPath()
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
|
||||
if testExifData == nil {
|
||||
assetsPath := GetTestAssetsPath()
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
|
||||
|
||||
var err error
|
||||
var err error
|
||||
|
||||
testExifData, err = ioutil.ReadFile(filepath)
|
||||
log.PanicIf(err)
|
||||
testExifData, err = ioutil.ReadFile(filepath)
|
||||
log.PanicIf(err)
|
||||
}
|
||||
|
||||
return testExifData
|
||||
}
|
||||
|
|
|
@ -217,6 +217,7 @@ func TestIfd_Thumbnail(t *testing.T) {
|
|||
actual, err := ifd.NextIfd.Thumbnail()
|
||||
log.PanicIf(err)
|
||||
|
||||
assetsPath := exifcommon.GetTestAssetsPath()
|
||||
expectedFilepath := path.Join(assetsPath, "NDM_8901.jpg.thumbnail")
|
||||
|
||||
expected, err := ioutil.ReadFile(expectedFilepath)
|
||||
|
@ -277,7 +278,7 @@ func TestIfd_GpsInfo__2_0_0_0(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
assetsPath := getTestAssetsPath()
|
||||
assetsPath := exifcommon.GetTestAssetsPath()
|
||||
filepath := path.Join(assetsPath, "gps-2000-scaled.jpg")
|
||||
|
||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
||||
|
|
|
@ -13,11 +13,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
assetsPath = ""
|
||||
testImageFilepath = ""
|
||||
testGpsImageFilepath = ""
|
||||
|
||||
testExifData = make([]byte, 0)
|
||||
testExifData []byte = nil
|
||||
)
|
||||
|
||||
func getExifSimpleTestIb() *IfdBuilder {
|
||||
|
@ -159,41 +155,28 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getTestAssetsPath() string {
|
||||
if assetsPath == "" {
|
||||
moduleRootPath := exifcommon.GetModuleRootPath()
|
||||
assetsPath = path.Join(moduleRootPath, "assets")
|
||||
}
|
||||
|
||||
return assetsPath
|
||||
}
|
||||
|
||||
func getTestImageFilepath() string {
|
||||
if testImageFilepath == "" {
|
||||
assetsPath := getTestAssetsPath()
|
||||
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")
|
||||
}
|
||||
|
||||
assetsPath := exifcommon.GetTestAssetsPath()
|
||||
testImageFilepath := path.Join(assetsPath, "NDM_8901.jpg")
|
||||
return testImageFilepath
|
||||
}
|
||||
|
||||
func getTestExifData() []byte {
|
||||
assetsPath := getTestAssetsPath()
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
|
||||
if testExifData == nil {
|
||||
assetsPath := exifcommon.GetTestAssetsPath()
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
|
||||
|
||||
var err error
|
||||
var err error
|
||||
|
||||
testExifData, err = ioutil.ReadFile(filepath)
|
||||
log.PanicIf(err)
|
||||
testExifData, err = ioutil.ReadFile(filepath)
|
||||
log.PanicIf(err)
|
||||
}
|
||||
|
||||
return testExifData
|
||||
}
|
||||
|
||||
func getTestGpsImageFilepath() string {
|
||||
if testGpsImageFilepath == "" {
|
||||
assetsPath := getTestAssetsPath()
|
||||
testGpsImageFilepath = path.Join(assetsPath, "gps.jpg")
|
||||
}
|
||||
|
||||
assetsPath := exifcommon.GetTestAssetsPath()
|
||||
testGpsImageFilepath := path.Join(assetsPath, "gps.jpg")
|
||||
return testGpsImageFilepath
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue