Use global for name of test image

- Moved logic from common_test.go to testing_common.go . That was legacy
  naming.
pull/28/head
Dustin Oprea 2020-01-01 10:05:56 -05:00
parent 128e17cf5b
commit c8c0acaebc
6 changed files with 52 additions and 100 deletions

View File

@ -1,32 +0,0 @@
package exif
import (
"os"
"path"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
var (
assetsPath = ""
testExifData = make([]byte, 0)
)
func init() {
goPath := os.Getenv("GOPATH")
if goPath == "" {
log.Panicf("GOPATH is empty")
}
assetsPath = path.Join(goPath, "src", "github.com", "dsoprea", "go-exif", "assets")
// Load test EXIF data.
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
var err error
testExifData, err = ioutil.ReadFile(filepath)
log.PanicIf(err)
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"os"
"path"
"reflect"
"testing"
@ -26,8 +25,7 @@ func TestVisit(t *testing.T) {
// Open the file.
filepath := path.Join(assetsPath, "NDM_8901.jpg")
f, err := os.Open(filepath)
f, err := os.Open(testImageFilepath)
log.PanicIf(err)
defer f.Close()
@ -189,11 +187,9 @@ func TestVisit(t *testing.T) {
}
func TestSearchFileAndExtractExif(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
// Returns a slice starting with the EXIF data and going to the end of the
// image.
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 {
@ -202,9 +198,7 @@ func TestSearchFileAndExtractExif(t *testing.T) {
}
func TestSearchAndExtractExif(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
imageData, err := ioutil.ReadFile(filepath)
imageData, err := ioutil.ReadFile(testImageFilepath)
log.PanicIf(err)
rawExif, err := SearchAndExtractExif(imageData)
@ -223,9 +217,7 @@ func TestCollect(t *testing.T) {
}
}()
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()

View File

@ -3,7 +3,6 @@ package exif
import (
"bytes"
"fmt"
"path"
"reflect"
"strings"
"testing"
@ -1292,9 +1291,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
}
}()
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -1387,9 +1384,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
// TODO(dustin): !! Test with an actual GPS-attached image.
func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
// Decode from binary.
@ -1505,9 +1500,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
}
// func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *testing.T) {
// filepath := path.Join(assetsPath, "NDM_8901.jpg")
// rawExif, err := SearchFileAndExtractExif(filepath)
// rawExif, err := SearchFileAndExtractExif(testImageFilepath)
// log.PanicIf(err)
// // Decode from binary.
@ -1644,9 +1637,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
// }
func ExampleIfd_Thumbnail() {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -1667,9 +1658,7 @@ func ExampleIfd_Thumbnail() {
}
func ExampleBuilderTag_SetValue() {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -1722,9 +1711,7 @@ func ExampleBuilderTag_SetValue() {
// encodes down to a new EXIF block, reparses, and validates that the value for
// that tag is what we set it to.
func ExampleIfdBuilder_SetStandardWithName() {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
// Boilerplate.

View File

@ -48,9 +48,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
}
}()
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -90,9 +88,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
}
func TestIfd_FindTagWithId_Hit(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -116,9 +112,7 @@ func TestIfd_FindTagWithId_Hit(t *testing.T) {
}
func TestIfd_FindTagWithId_Miss(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -142,9 +136,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) {
}
func TestIfd_FindTagWithName_Hit(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -168,9 +160,7 @@ func TestIfd_FindTagWithName_Hit(t *testing.T) {
}
func TestIfd_FindTagWithName_Miss(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -194,9 +184,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) {
}
func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -220,9 +208,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
}
func TestIfd_Thumbnail(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -298,9 +284,7 @@ func TestIfd_GpsInfo(t *testing.T) {
}
func TestIfd_EnumerateTagsRecursively(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -456,9 +440,7 @@ func TestIfd_EnumerateTagsRecursively(t *testing.T) {
}
func ExampleIfd_EnumerateTagsRecursively() {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -513,9 +495,7 @@ func ExampleIfd_GpsInfo() {
}
func ExampleIfd_FindTagWithName() {
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()

View File

@ -1,12 +1,23 @@
package exif
import (
"os"
"path"
"reflect"
"testing"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
var (
assetsPath = ""
testImageFilepath = ""
testExifData = make([]byte, 0)
)
func getExifSimpleTestIb() *IfdBuilder {
defer func() {
if state := recover(); state != nil {
@ -147,3 +158,22 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) {
}
}
}
func init() {
goPath := os.Getenv("GOPATH")
if goPath == "" {
log.Panicf("GOPATH is empty")
}
assetsPath = path.Join(goPath, "src", "github.com", "dsoprea", "go-exif", "assets")
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")
// Load test EXIF data.
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
var err error
testExifData, err = ioutil.ReadFile(filepath)
log.PanicIf(err)
}

View File

@ -2,7 +2,6 @@ package exif
import (
"bytes"
"path"
"testing"
"github.com/dsoprea/go-logging"
@ -16,9 +15,7 @@ func TestValueContext_ReadAscii(t *testing.T) {
}
}()
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()
@ -67,9 +64,7 @@ func TestValueContext_Undefined(t *testing.T) {
}
}()
filepath := path.Join(assetsPath, "NDM_8901.jpg")
rawExif, err := SearchFileAndExtractExif(filepath)
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
log.PanicIf(err)
im := NewIfdMapping()