mirror of https://github.com/dsoprea/go-exif.git
Use global for name of test image
- Moved logic from common_test.go to testing_common.go . That was legacy naming.pull/28/head
parent
128e17cf5b
commit
c8c0acaebc
|
@ -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)
|
|
||||||
}
|
|
16
exif_test.go
16
exif_test.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -26,8 +25,7 @@ func TestVisit(t *testing.T) {
|
||||||
|
|
||||||
// Open the file.
|
// Open the file.
|
||||||
|
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
f, err := os.Open(testImageFilepath)
|
||||||
f, err := os.Open(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
@ -189,11 +187,9 @@ func TestVisit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchFileAndExtractExif(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
|
// Returns a slice starting with the EXIF data and going to the end of the
|
||||||
// image.
|
// image.
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 {
|
if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 {
|
||||||
|
@ -202,9 +198,7 @@ func TestSearchFileAndExtractExif(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchAndExtractExif(t *testing.T) {
|
func TestSearchAndExtractExif(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
imageData, err := ioutil.ReadFile(testImageFilepath)
|
||||||
|
|
||||||
imageData, err := ioutil.ReadFile(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
rawExif, err := SearchAndExtractExif(imageData)
|
rawExif, err := SearchAndExtractExif(imageData)
|
||||||
|
@ -223,9 +217,7 @@ func TestCollect(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
|
|
@ -3,7 +3,6 @@ package exif
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -1292,9 +1291,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -1387,9 +1384,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
|
||||||
// TODO(dustin): !! Test with an actual GPS-attached image.
|
// TODO(dustin): !! Test with an actual GPS-attached image.
|
||||||
|
|
||||||
func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
// Decode from binary.
|
// Decode from binary.
|
||||||
|
@ -1505,9 +1500,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *testing.T) {
|
// func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *testing.T) {
|
||||||
// filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
// rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
// rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
// log.PanicIf(err)
|
// log.PanicIf(err)
|
||||||
|
|
||||||
// // Decode from binary.
|
// // Decode from binary.
|
||||||
|
@ -1644,9 +1637,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func ExampleIfd_Thumbnail() {
|
func ExampleIfd_Thumbnail() {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -1667,9 +1658,7 @@ func ExampleIfd_Thumbnail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleBuilderTag_SetValue() {
|
func ExampleBuilderTag_SetValue() {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -1722,9 +1711,7 @@ func ExampleBuilderTag_SetValue() {
|
||||||
// encodes down to a new EXIF block, reparses, and validates that the value for
|
// encodes down to a new EXIF block, reparses, and validates that the value for
|
||||||
// that tag is what we set it to.
|
// that tag is what we set it to.
|
||||||
func ExampleIfdBuilder_SetStandardWithName() {
|
func ExampleIfdBuilder_SetStandardWithName() {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
// Boilerplate.
|
// Boilerplate.
|
||||||
|
|
|
@ -48,9 +48,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -90,9 +88,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_FindTagWithId_Hit(t *testing.T) {
|
func TestIfd_FindTagWithId_Hit(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -116,9 +112,7 @@ func TestIfd_FindTagWithId_Hit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_FindTagWithId_Miss(t *testing.T) {
|
func TestIfd_FindTagWithId_Miss(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -142,9 +136,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_FindTagWithName_Hit(t *testing.T) {
|
func TestIfd_FindTagWithName_Hit(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -168,9 +160,7 @@ func TestIfd_FindTagWithName_Hit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_FindTagWithName_Miss(t *testing.T) {
|
func TestIfd_FindTagWithName_Miss(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -194,9 +184,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
|
func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -220,9 +208,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_Thumbnail(t *testing.T) {
|
func TestIfd_Thumbnail(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -298,9 +284,7 @@ func TestIfd_GpsInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfd_EnumerateTagsRecursively(t *testing.T) {
|
func TestIfd_EnumerateTagsRecursively(t *testing.T) {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -456,9 +440,7 @@ func TestIfd_EnumerateTagsRecursively(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleIfd_EnumerateTagsRecursively() {
|
func ExampleIfd_EnumerateTagsRecursively() {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -513,9 +495,7 @@ func ExampleIfd_GpsInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleIfd_FindTagWithName() {
|
func ExampleIfd_FindTagWithName() {
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
|
|
@ -1,12 +1,23 @@
|
||||||
package exif
|
package exif
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/dsoprea/go-logging"
|
"github.com/dsoprea/go-logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
assetsPath = ""
|
||||||
|
testImageFilepath = ""
|
||||||
|
|
||||||
|
testExifData = make([]byte, 0)
|
||||||
|
)
|
||||||
|
|
||||||
func getExifSimpleTestIb() *IfdBuilder {
|
func getExifSimpleTestIb() *IfdBuilder {
|
||||||
defer func() {
|
defer func() {
|
||||||
if state := recover(); state != nil {
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package exif
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"path"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/dsoprea/go-logging"
|
"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(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
@ -67,9 +64,7 @@ func TestValueContext_Undefined(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
|
||||||
|
|
||||||
rawExif, err := SearchFileAndExtractExif(filepath)
|
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
im := NewIfdMapping()
|
im := NewIfdMapping()
|
||||||
|
|
Loading…
Reference in New Issue