Minor sensible testing refactors

dustin/master
Dustin Oprea 2020-06-03 22:06:15 -04:00
parent a350bacdac
commit ca8584a0e1
3 changed files with 57 additions and 77 deletions

View File

@ -11,11 +11,10 @@ import (
)
var (
assetsPath = ""
testImageFilepath = ""
testExifData = make([]byte, 0)
moduleRootPath = ""
testExifData []byte = nil
// EncodeDefaultByteOrder is the default byte-order for encoding operations.
EncodeDefaultByteOrder = binary.BigEndian
@ -24,10 +23,7 @@ var (
)
func GetModuleRootPath() string {
if moduleRootPath != "" {
return moduleRootPath
}
if moduleRootPath == "" {
moduleRootPath := os.Getenv("EXIF_MODULE_ROOT_PATH")
if moduleRootPath != "" {
return moduleRootPath
@ -57,35 +53,35 @@ func GetModuleRootPath() string {
}
}
return currentPath
moduleRootPath = currentPath
}
func getTestAssetsPath() string {
if assetsPath == "" {
moduleRootPath := GetModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets")
return moduleRootPath
}
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()
if testExifData == nil {
assetsPath := GetTestAssetsPath()
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
var err error
testExifData, err = ioutil.ReadFile(filepath)
log.PanicIf(err)
}
return testExifData
}

View File

@ -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)

View File

@ -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()
if testExifData == nil {
assetsPath := exifcommon.GetTestAssetsPath()
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
var err error
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
}