go-exif/test_common.go
Dustin Oprea 1d7239382b testing: Moved common testing code to test_common.
- Tweaked comments to be more concise.
2018-06-06 05:11:07 -04:00

41 lines
938 B
Go

package exif
import (
"os"
"path"
"encoding/binary"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
var (
TestDefaultByteOrder = binary.BigEndian
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")
exifData, err := ioutil.ReadFile(filepath)
log.PanicIf(err)
// TODO(dustin): !! We're currently built to expect the JPEG EXIF header-prefix, but our test-data doesn't have that.So, artificially prefix it, for now.
testExifData = make([]byte, len(exifData) + len(ExifHeaderPrefixBytes))
copy(testExifData[0:], ExifHeaderPrefixBytes)
copy(testExifData[len(ExifHeaderPrefixBytes):], exifData)
}