diff --git a/common_test.go b/common_test.go deleted file mode 100644 index c29cb34..0000000 --- a/common_test.go +++ /dev/null @@ -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) -} diff --git a/exif_test.go b/exif_test.go index 769f277..a67d472 100644 --- a/exif_test.go +++ b/exif_test.go @@ -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() diff --git a/ifd_builder_test.go b/ifd_builder_test.go index 02ea53e..c5059b6 100644 --- a/ifd_builder_test.go +++ b/ifd_builder_test.go @@ -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. diff --git a/ifd_enumerate_test.go b/ifd_enumerate_test.go index 020bc95..d8e81fd 100644 --- a/ifd_enumerate_test.go +++ b/ifd_enumerate_test.go @@ -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() diff --git a/testing_common.go b/testing_common.go index 25fd8ea..3550144 100644 --- a/testing_common.go +++ b/testing_common.go @@ -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) +} diff --git a/value_context_test.go b/value_context_test.go index 68b30ba..3d4df86 100644 --- a/value_context_test.go +++ b/value_context_test.go @@ -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()