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