Reorganized to not require GOPATH unless testing.

This commit is contained in:
Dustin Oprea 2018-06-16 09:49:14 -04:00
parent 7a8e5b005e
commit dfbe003c0e
4 changed files with 358 additions and 380 deletions

32
common_test.go Normal file
View File

@ -0,0 +1,32 @@
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)
}

11
exif.go
View File

@ -1,13 +1,13 @@
package exif
import (
"os"
"errors"
"bytes"
"errors"
"fmt"
"os"
"io/ioutil"
"encoding/binary"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
@ -32,6 +32,9 @@ var (
// EncodeDefaultByteOrder is the default byte-order for encoding operations.
EncodeDefaultByteOrder = binary.BigEndian
// Default byte order for tests.
TestDefaultByteOrder = binary.BigEndian
BigEndianBoBytes = [2]byte{'M', 'M'}
LittleEndianBoBytes = [2]byte{'I', 'I'}
@ -56,7 +59,6 @@ var (
ErrExifHeaderError = errors.New("exif header error")
)
// SearchAndExtractExif returns a slice from the beginning of the EXIF data the
// end of the file (it's not practical to try and calculate where the data
// actually ends).
@ -115,7 +117,6 @@ func SearchFileAndExtractExif(filepath string) (rawExif []byte, err error) {
return rawExif, nil
}
type ExifHeader struct {
ByteOrder binary.ByteOrder
FirstIfdOffset uint32

21
tags.go
View File

@ -1,12 +1,10 @@
package exif
import (
"os"
"path"
"fmt"
"gopkg.in/yaml.v2"
"github.com/dsoprea/go-logging"
"gopkg.in/yaml.v2"
)
const (
@ -32,8 +30,6 @@ const (
)
var (
tagDataFilepath = ""
// tagsWithoutAlignment is a tag-lookup for tags whose value size won't
// necessarily be a multiple of its tag-type.
tagsWithoutAlignment = map[uint16]struct{}{
@ -49,7 +45,6 @@ var (
tagsLogger = log.NewLogger("exif.tags")
)
// File structures.
type encodedTag struct {
@ -60,7 +55,6 @@ type encodedTag struct {
TypeName string `yaml:"type_name"`
}
// Indexing structures.
type IndexedTag struct {
@ -104,7 +98,6 @@ func (ti *TagIndex) load() (err error) {
return nil
}
// Read static data.
encodedIfds := make(map[string][]encodedTag)
@ -112,7 +105,6 @@ func (ti *TagIndex) load() (err error) {
err = yaml.Unmarshal([]byte(tagsYaml), encodedIfds)
log.PanicIf(err)
// Load structure.
tagsByIfd := make(map[string]map[uint16]*IndexedTag)
@ -143,7 +135,6 @@ if tagTypeName == "SSHORT" || tagTypeName == "FLOAT" || tagTypeName == "DOUBLE"
Type: tagTypeId,
}
// Store by ID.
family, found := tagsByIfd[ifdName]
@ -158,7 +149,6 @@ if tagTypeName == "SSHORT" || tagTypeName == "FLOAT" || tagTypeName == "DOUBLE"
family[tagId] = tag
// Store by name.
familyR, found := tagsByIfdR[ifdName]
@ -228,7 +218,6 @@ func (ti *TagIndex) GetWithName(ii IfdIdentity, name string) (it *IndexedTag, er
return it, nil
}
// IfdTagWithId returns true if the given tag points to a child IFD block.
func IfdTagNameWithIdOrFail(parentIfdName string, tagId uint16) string {
name, found := IfdTagNameWithId(parentIfdName, tagId)
@ -319,13 +308,5 @@ func IfdId(parentIfdName, ifdName string) (ii IfdIdentity, id int) {
}
func init() {
goPath := os.Getenv("GOPATH")
if goPath == "" {
log.Panicf("GOPATH is empty")
}
assetsPath := path.Join(goPath, "src", "github.com", "dsoprea", "go-exif", "assets")
tagDataFilepath = path.Join(assetsPath, "tags.yaml")
tagIndex = NewTagIndex()
}

View File

@ -1,36 +0,0 @@
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")
var err error
testExifData, err = ioutil.ReadFile(filepath)
log.PanicIf(err)
}