Fix module resolution with subpackages

exif-read-tool/main_test.go: Fix test broken by moving to V2.
for/master
Dustin Oprea 2020-01-11 17:33:16 -05:00
parent 41fd3ae870
commit 817d4b2856
4 changed files with 170 additions and 87 deletions

View File

@ -32,7 +32,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "1", "value": [
1
],
"value_string": "1" "value_string": "1"
}, },
{ {
@ -44,7 +46,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "72/1", "value": [
{
"Numerator": 72,
"Denominator": 1
}
],
"value_string": "72/1" "value_string": "72/1"
}, },
{ {
@ -56,7 +63,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "72/1", "value": [
{
"Numerator": 72,
"Denominator": 1
}
],
"value_string": "72/1" "value_string": "72/1"
}, },
{ {
@ -68,7 +80,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2", "value": [
2
],
"value_string": "2" "value_string": "2"
}, },
{ {
@ -104,7 +118,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2", "value": [
2
],
"value_string": "2" "value_string": "2"
}, },
{ {
@ -128,7 +144,9 @@
"tag_type_id": 4, "tag_type_id": 4,
"tag_type_name": "LONG", "tag_type_name": "LONG",
"unit_count": 1, "unit_count": 1,
"value": "360", "value": [
360
],
"value_string": "360" "value_string": "360"
}, },
{ {
@ -140,7 +158,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "1/640", "value": [
{
"Numerator": 1,
"Denominator": 640
}
],
"value_string": "1/640" "value_string": "1/640"
}, },
{ {
@ -152,7 +175,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "4/1", "value": [
{
"Numerator": 4,
"Denominator": 1
}
],
"value_string": "4/1" "value_string": "4/1"
}, },
{ {
@ -164,7 +192,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "4", "value": [
4
],
"value_string": "4" "value_string": "4"
}, },
{ {
@ -176,7 +206,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "1600", "value": [
1600
],
"value_string": "1600" "value_string": "1600"
}, },
{ {
@ -188,7 +220,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2", "value": [
2
],
"value_string": "2" "value_string": "2"
}, },
{ {
@ -200,7 +234,9 @@
"tag_type_id": 4, "tag_type_id": 4,
"tag_type_name": "LONG", "tag_type_name": "LONG",
"unit_count": 1, "unit_count": 1,
"value": "1600", "value": [
1600
],
"value_string": "1600" "value_string": "1600"
}, },
{ {
@ -212,7 +248,7 @@
"tag_type_id": 7, "tag_type_id": 7,
"tag_type_name": "UNDEFINED", "tag_type_name": "UNDEFINED",
"unit_count": 4, "unit_count": 4,
"value": "0230", "value": {},
"value_string": "0230" "value_string": "0230"
}, },
{ {
@ -252,7 +288,7 @@
"ConfigurationId": 2, "ConfigurationId": 2,
"ConfigurationBytes": "AQIDAA==" "ConfigurationBytes": "AQIDAA=="
}, },
"value_string": "ComponentsConfiguration\u003cID=[YCBCR] BYTES=[1 2 3 0]\u003e" "value_string": "Exif9101ComponentsConfiguration\u003cID=[YCBCR] BYTES=[1 2 3 0]\u003e"
}, },
{ {
"ifd_path": "IFD/Exif", "ifd_path": "IFD/Exif",
@ -263,7 +299,12 @@
"tag_type_id": 10, "tag_type_id": 10,
"tag_type_name": "SRATIONAL", "tag_type_name": "SRATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "614400/65536", "value": [
{
"Numerator": 614400,
"Denominator": 65536
}
],
"value_string": "614400/65536" "value_string": "614400/65536"
}, },
{ {
@ -275,7 +316,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "262144/65536", "value": [
{
"Numerator": 262144,
"Denominator": 65536
}
],
"value_string": "262144/65536" "value_string": "262144/65536"
}, },
{ {
@ -287,7 +333,12 @@
"tag_type_id": 10, "tag_type_id": 10,
"tag_type_name": "SRATIONAL", "tag_type_name": "SRATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "0/1", "value": [
{
"Numerator": 0,
"Denominator": 1
}
],
"value_string": "0/1" "value_string": "0/1"
}, },
{ {
@ -299,7 +350,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "5", "value": [
5
],
"value_string": "5" "value_string": "5"
}, },
{ {
@ -311,7 +364,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "16", "value": [
16
],
"value_string": "16" "value_string": "16"
}, },
{ {
@ -323,7 +378,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "16/1", "value": [
{
"Numerator": 16,
"Denominator": 1
}
],
"value_string": "16/1" "value_string": "16/1"
}, },
{ {
@ -401,7 +461,7 @@
"tag_type_id": 7, "tag_type_id": 7,
"tag_type_name": "UNDEFINED", "tag_type_name": "UNDEFINED",
"unit_count": 4, "unit_count": 4,
"value": "0100", "value": {},
"value_string": "0100" "value_string": "0100"
}, },
{ {
@ -413,7 +473,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "1", "value": [
1
],
"value_string": "1" "value_string": "1"
}, },
{ {
@ -425,7 +487,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "3840", "value": [
3840
],
"value_string": "3840" "value_string": "3840"
}, },
{ {
@ -437,7 +501,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2560", "value": [
2560
],
"value_string": "2560" "value_string": "2560"
}, },
{ {
@ -449,7 +515,9 @@
"tag_type_id": 4, "tag_type_id": 4,
"tag_type_name": "LONG", "tag_type_name": "LONG",
"unit_count": 1, "unit_count": 1,
"value": "9326", "value": [
9326
],
"value_string": "9326" "value_string": "9326"
}, },
{ {
@ -473,7 +541,7 @@
"tag_type_id": 7, "tag_type_id": 7,
"tag_type_name": "UNDEFINED", "tag_type_name": "UNDEFINED",
"unit_count": 4, "unit_count": 4,
"value": "0100", "value": {},
"value_string": "0100" "value_string": "0100"
}, },
{ {
@ -485,7 +553,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "3840000/1461", "value": [
{
"Numerator": 3840000,
"Denominator": 1461
}
],
"value_string": "3840000/1461" "value_string": "3840000/1461"
}, },
{ {
@ -497,7 +570,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "2560000/972", "value": [
{
"Numerator": 2560000,
"Denominator": 972
}
],
"value_string": "2560000/972" "value_string": "2560000/972"
}, },
{ {
@ -509,7 +587,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2", "value": [
2
],
"value_string": "2" "value_string": "2"
}, },
{ {
@ -521,7 +601,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "0", "value": [
0
],
"value_string": "0" "value_string": "0"
}, },
{ {
@ -533,7 +615,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "0", "value": [
0
],
"value_string": "0" "value_string": "0"
}, },
{ {
@ -545,7 +629,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "0", "value": [
0
],
"value_string": "0" "value_string": "0"
}, },
{ {
@ -557,7 +643,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "0", "value": [
0
],
"value_string": "0" "value_string": "0"
}, },
{ {
@ -593,7 +681,24 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 4, "unit_count": 4,
"value": "16/1...", "value": [
{
"Numerator": 16,
"Denominator": 1
},
{
"Numerator": 35,
"Denominator": 1
},
{
"Numerator": 0,
"Denominator": 1
},
{
"Numerator": 0,
"Denominator": 1
}
],
"value_string": "16/1..." "value_string": "16/1..."
}, },
{ {
@ -629,7 +734,9 @@
"tag_type_id": 4, "tag_type_id": 4,
"tag_type_name": "LONG", "tag_type_name": "LONG",
"unit_count": 1, "unit_count": 1,
"value": "9554", "value": [
9554
],
"value_string": "9554" "value_string": "9554"
}, },
{ {
@ -641,7 +748,7 @@
"tag_type_id": 1, "tag_type_id": 1,
"tag_type_name": "BYTE", "tag_type_name": "BYTE",
"unit_count": 4, "unit_count": 4,
"value": "02 03 00 00", "value": "AgMAAA==",
"value_string": "02 03 00 00" "value_string": "02 03 00 00"
}, },
{ {
@ -653,7 +760,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "6", "value": [
6
],
"value_string": "6" "value_string": "6"
}, },
{ {
@ -665,7 +774,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "72/1", "value": [
{
"Numerator": 72,
"Denominator": 1
}
],
"value_string": "72/1" "value_string": "72/1"
}, },
{ {
@ -677,7 +791,12 @@
"tag_type_id": 5, "tag_type_id": 5,
"tag_type_name": "RATIONAL", "tag_type_name": "RATIONAL",
"unit_count": 1, "unit_count": 1,
"value": "72/1", "value": [
{
"Numerator": 72,
"Denominator": 1
}
],
"value_string": "72/1" "value_string": "72/1"
}, },
{ {
@ -689,7 +808,9 @@
"tag_type_id": 3, "tag_type_id": 3,
"tag_type_name": "SHORT", "tag_type_name": "SHORT",
"unit_count": 1, "unit_count": 1,
"value": "2", "value": [
2
],
"value_string": "2" "value_string": "2"
} }
] ]

View File

@ -23,7 +23,7 @@ var (
TestDefaultByteOrder = binary.BigEndian TestDefaultByteOrder = binary.BigEndian
) )
func getModuleRootPath() string { func GetModuleRootPath() string {
currentWd, err := os.Getwd() currentWd, err := os.Getwd()
log.PanicIf(err) log.PanicIf(err)
@ -48,7 +48,7 @@ func getModuleRootPath() string {
} }
func init() { func init() {
moduleRootPath := getModuleRootPath() moduleRootPath := GetModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets") assetsPath = path.Join(moduleRootPath, "assets")
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg") testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"os"
"path" "path"
"reflect" "reflect"
"testing" "testing"
@ -13,6 +12,8 @@ import (
"os/exec" "os/exec"
"github.com/dsoprea/go-logging" "github.com/dsoprea/go-logging"
"github.com/dsoprea/go-exif/v2/common"
) )
var ( var (
@ -58,7 +59,7 @@ IFD-PATH=[IFD/Exif] ID=(0x8832) NAME=[RecommendedExposureIndex] COUNT=(1) TYPE=[
IFD-PATH=[IFD/Exif] ID=(0x9000) NAME=[ExifVersion] COUNT=(4) TYPE=[UNDEFINED] VALUE=[0230] IFD-PATH=[IFD/Exif] ID=(0x9000) NAME=[ExifVersion] COUNT=(4) TYPE=[UNDEFINED] VALUE=[0230]
IFD-PATH=[IFD/Exif] ID=(0x9003) NAME=[DateTimeOriginal] COUNT=(20) TYPE=[ASCII] VALUE=[2017:12:02 08:18:50] IFD-PATH=[IFD/Exif] ID=(0x9003) NAME=[DateTimeOriginal] COUNT=(20) TYPE=[ASCII] VALUE=[2017:12:02 08:18:50]
IFD-PATH=[IFD/Exif] ID=(0x9004) NAME=[DateTimeDigitized] COUNT=(20) TYPE=[ASCII] VALUE=[2017:12:02 08:18:50] IFD-PATH=[IFD/Exif] ID=(0x9004) NAME=[DateTimeDigitized] COUNT=(20) TYPE=[ASCII] VALUE=[2017:12:02 08:18:50]
IFD-PATH=[IFD/Exif] ID=(0x9101) NAME=[ComponentsConfiguration] COUNT=(4) TYPE=[UNDEFINED] VALUE=[ComponentsConfiguration<ID=[YCBCR] BYTES=[1 2 3 0]>] IFD-PATH=[IFD/Exif] ID=(0x9101) NAME=[ComponentsConfiguration] COUNT=(4) TYPE=[UNDEFINED] VALUE=[Exif9101ComponentsConfiguration<ID=[YCBCR] BYTES=[1 2 3 0]>]
IFD-PATH=[IFD/Exif] ID=(0x9201) NAME=[ShutterSpeedValue] COUNT=(1) TYPE=[SRATIONAL] VALUE=[614400/65536] IFD-PATH=[IFD/Exif] ID=(0x9201) NAME=[ShutterSpeedValue] COUNT=(1) TYPE=[SRATIONAL] VALUE=[614400/65536]
IFD-PATH=[IFD/Exif] ID=(0x9202) NAME=[ApertureValue] COUNT=(1) TYPE=[RATIONAL] VALUE=[262144/65536] IFD-PATH=[IFD/Exif] ID=(0x9202) NAME=[ApertureValue] COUNT=(1) TYPE=[RATIONAL] VALUE=[262144/65536]
IFD-PATH=[IFD/Exif] ID=(0x9204) NAME=[ExposureBiasValue] COUNT=(1) TYPE=[SRATIONAL] VALUE=[0/1] IFD-PATH=[IFD/Exif] ID=(0x9204) NAME=[ExposureBiasValue] COUNT=(1) TYPE=[SRATIONAL] VALUE=[0/1]
@ -145,22 +146,10 @@ func TestMainJson(t *testing.T) {
} }
func init() { func init() {
goPath := os.Getenv("GOPATH") moduleRootPath := exifcommon.GetModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets")
moduleRoot := "" appFilepath = path.Join(moduleRootPath, "exif-read-tool", "main.go")
if goPath != "" {
moduleRoot = path.Join(goPath, "src", "github.com", "dsoprea", "go-exif")
} else {
// Module-enabled context.
currentWd, err := os.Getwd()
log.PanicIf(err)
moduleRoot = path.Join(currentWd, "..")
}
assetsPath = path.Join(moduleRoot, "assets")
appFilepath = path.Join(moduleRoot, "exif-read-tool", "main.go")
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg") testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")
} }

View File

@ -1,7 +1,6 @@
package exif package exif
import ( import (
"os"
"path" "path"
"reflect" "reflect"
"testing" "testing"
@ -159,34 +158,8 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) {
} }
} }
func getModuleRootPath() string {
currentWd, err := os.Getwd()
log.PanicIf(err)
currentPath := currentWd
for {
tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
f, err := os.Open(tryStampFilepath)
if err != nil && err != os.ErrNotExist {
log.Panic(err)
} else if err == nil {
f.Close()
break
}
currentPath := path.Dir(currentPath)
if currentPath == "/" {
log.Panicf("could not find module-root")
}
}
return currentPath
}
func init() { func init() {
moduleRootPath := getModuleRootPath() moduleRootPath := exifcommon.GetModuleRootPath()
assetsPath = path.Join(moduleRootPath, "assets") assetsPath = path.Join(moduleRootPath, "assets")
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg") testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")