Skip to content

Commit c8c0aca

Browse files
committed
Use global for name of test image
- Moved logic from common_test.go to testing_common.go . That was legacy naming.
1 parent 128e17c commit c8c0aca

6 files changed

+52
-100
lines changed

common_test.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

exif_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"os"
7-
"path"
87
"reflect"
98
"testing"
109

@@ -26,8 +25,7 @@ func TestVisit(t *testing.T) {
2625

2726
// Open the file.
2827

29-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
30-
f, err := os.Open(filepath)
28+
f, err := os.Open(testImageFilepath)
3129
log.PanicIf(err)
3230

3331
defer f.Close()
@@ -189,11 +187,9 @@ func TestVisit(t *testing.T) {
189187
}
190188

191189
func TestSearchFileAndExtractExif(t *testing.T) {
192-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
193-
194190
// Returns a slice starting with the EXIF data and going to the end of the
195191
// image.
196-
rawExif, err := SearchFileAndExtractExif(filepath)
192+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
197193
log.PanicIf(err)
198194

199195
if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 {
@@ -202,9 +198,7 @@ func TestSearchFileAndExtractExif(t *testing.T) {
202198
}
203199

204200
func TestSearchAndExtractExif(t *testing.T) {
205-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
206-
207-
imageData, err := ioutil.ReadFile(filepath)
201+
imageData, err := ioutil.ReadFile(testImageFilepath)
208202
log.PanicIf(err)
209203

210204
rawExif, err := SearchAndExtractExif(imageData)
@@ -223,9 +217,7 @@ func TestCollect(t *testing.T) {
223217
}
224218
}()
225219

226-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
227-
228-
rawExif, err := SearchFileAndExtractExif(filepath)
220+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
229221
log.PanicIf(err)
230222

231223
im := NewIfdMapping()

ifd_builder_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package exif
33
import (
44
"bytes"
55
"fmt"
6-
"path"
76
"reflect"
87
"strings"
98
"testing"
@@ -1292,9 +1291,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
12921291
}
12931292
}()
12941293

1295-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
1296-
1297-
rawExif, err := SearchFileAndExtractExif(filepath)
1294+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
12981295
log.PanicIf(err)
12991296

13001297
im := NewIfdMapping()
@@ -1387,9 +1384,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
13871384
// TODO(dustin): !! Test with an actual GPS-attached image.
13881385

13891386
func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
1390-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
1391-
1392-
rawExif, err := SearchFileAndExtractExif(filepath)
1387+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
13931388
log.PanicIf(err)
13941389

13951390
// Decode from binary.
@@ -1505,9 +1500,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
15051500
}
15061501

15071502
// func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *testing.T) {
1508-
// filepath := path.Join(assetsPath, "NDM_8901.jpg")
1509-
1510-
// rawExif, err := SearchFileAndExtractExif(filepath)
1503+
// rawExif, err := SearchFileAndExtractExif(testImageFilepath)
15111504
// log.PanicIf(err)
15121505

15131506
// // Decode from binary.
@@ -1644,9 +1637,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
16441637
// }
16451638

16461639
func ExampleIfd_Thumbnail() {
1647-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
1648-
1649-
rawExif, err := SearchFileAndExtractExif(filepath)
1640+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
16501641
log.PanicIf(err)
16511642

16521643
im := NewIfdMapping()
@@ -1667,9 +1658,7 @@ func ExampleIfd_Thumbnail() {
16671658
}
16681659

16691660
func ExampleBuilderTag_SetValue() {
1670-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
1671-
1672-
rawExif, err := SearchFileAndExtractExif(filepath)
1661+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
16731662
log.PanicIf(err)
16741663

16751664
im := NewIfdMapping()
@@ -1722,9 +1711,7 @@ func ExampleBuilderTag_SetValue() {
17221711
// encodes down to a new EXIF block, reparses, and validates that the value for
17231712
// that tag is what we set it to.
17241713
func ExampleIfdBuilder_SetStandardWithName() {
1725-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
1726-
1727-
rawExif, err := SearchFileAndExtractExif(filepath)
1714+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
17281715
log.PanicIf(err)
17291716

17301717
// Boilerplate.

ifd_enumerate_test.go

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
4848
}
4949
}()
5050

51-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
52-
53-
rawExif, err := SearchFileAndExtractExif(filepath)
51+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
5452
log.PanicIf(err)
5553

5654
im := NewIfdMapping()
@@ -90,9 +88,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) {
9088
}
9189

9290
func TestIfd_FindTagWithId_Hit(t *testing.T) {
93-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
94-
95-
rawExif, err := SearchFileAndExtractExif(filepath)
91+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
9692
log.PanicIf(err)
9793

9894
im := NewIfdMapping()
@@ -116,9 +112,7 @@ func TestIfd_FindTagWithId_Hit(t *testing.T) {
116112
}
117113

118114
func TestIfd_FindTagWithId_Miss(t *testing.T) {
119-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
120-
121-
rawExif, err := SearchFileAndExtractExif(filepath)
115+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
122116
log.PanicIf(err)
123117

124118
im := NewIfdMapping()
@@ -142,9 +136,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) {
142136
}
143137

144138
func TestIfd_FindTagWithName_Hit(t *testing.T) {
145-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
146-
147-
rawExif, err := SearchFileAndExtractExif(filepath)
139+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
148140
log.PanicIf(err)
149141

150142
im := NewIfdMapping()
@@ -168,9 +160,7 @@ func TestIfd_FindTagWithName_Hit(t *testing.T) {
168160
}
169161

170162
func TestIfd_FindTagWithName_Miss(t *testing.T) {
171-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
172-
173-
rawExif, err := SearchFileAndExtractExif(filepath)
163+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
174164
log.PanicIf(err)
175165

176166
im := NewIfdMapping()
@@ -194,9 +184,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) {
194184
}
195185

196186
func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
197-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
198-
199-
rawExif, err := SearchFileAndExtractExif(filepath)
187+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
200188
log.PanicIf(err)
201189

202190
im := NewIfdMapping()
@@ -220,9 +208,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) {
220208
}
221209

222210
func TestIfd_Thumbnail(t *testing.T) {
223-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
224-
225-
rawExif, err := SearchFileAndExtractExif(filepath)
211+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
226212
log.PanicIf(err)
227213

228214
im := NewIfdMapping()
@@ -298,9 +284,7 @@ func TestIfd_GpsInfo(t *testing.T) {
298284
}
299285

300286
func TestIfd_EnumerateTagsRecursively(t *testing.T) {
301-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
302-
303-
rawExif, err := SearchFileAndExtractExif(filepath)
287+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
304288
log.PanicIf(err)
305289

306290
im := NewIfdMapping()
@@ -456,9 +440,7 @@ func TestIfd_EnumerateTagsRecursively(t *testing.T) {
456440
}
457441

458442
func ExampleIfd_EnumerateTagsRecursively() {
459-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
460-
461-
rawExif, err := SearchFileAndExtractExif(filepath)
443+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
462444
log.PanicIf(err)
463445

464446
im := NewIfdMapping()
@@ -513,9 +495,7 @@ func ExampleIfd_GpsInfo() {
513495
}
514496

515497
func ExampleIfd_FindTagWithName() {
516-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
517-
518-
rawExif, err := SearchFileAndExtractExif(filepath)
498+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
519499
log.PanicIf(err)
520500

521501
im := NewIfdMapping()

testing_common.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package exif
22

33
import (
4+
"os"
5+
"path"
46
"reflect"
57
"testing"
68

9+
"io/ioutil"
10+
711
"github.com/dsoprea/go-logging"
812
)
913

14+
var (
15+
assetsPath = ""
16+
testImageFilepath = ""
17+
18+
testExifData = make([]byte, 0)
19+
)
20+
1021
func getExifSimpleTestIb() *IfdBuilder {
1122
defer func() {
1223
if state := recover(); state != nil {
@@ -147,3 +158,22 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) {
147158
}
148159
}
149160
}
161+
162+
func init() {
163+
goPath := os.Getenv("GOPATH")
164+
if goPath == "" {
165+
log.Panicf("GOPATH is empty")
166+
}
167+
168+
assetsPath = path.Join(goPath, "src", "github.com", "dsoprea", "go-exif", "assets")
169+
170+
testImageFilepath = path.Join(assetsPath, "NDM_8901.jpg")
171+
172+
// Load test EXIF data.
173+
174+
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
175+
176+
var err error
177+
testExifData, err = ioutil.ReadFile(filepath)
178+
log.PanicIf(err)
179+
}

value_context_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package exif
22

33
import (
44
"bytes"
5-
"path"
65
"testing"
76

87
"github.com/dsoprea/go-logging"
@@ -16,9 +15,7 @@ func TestValueContext_ReadAscii(t *testing.T) {
1615
}
1716
}()
1817

19-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
20-
21-
rawExif, err := SearchFileAndExtractExif(filepath)
18+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
2219
log.PanicIf(err)
2320

2421
im := NewIfdMapping()
@@ -67,9 +64,7 @@ func TestValueContext_Undefined(t *testing.T) {
6764
}
6865
}()
6966

70-
filepath := path.Join(assetsPath, "NDM_8901.jpg")
71-
72-
rawExif, err := SearchFileAndExtractExif(filepath)
67+
rawExif, err := SearchFileAndExtractExif(testImageFilepath)
7368
log.PanicIf(err)
7469

7570
im := NewIfdMapping()

0 commit comments

Comments
 (0)