Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 991d2f9

Browse files
committed
Replace Exif with Meta in tests
1 parent b29c2f7 commit 991d2f9

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

resources/image_test.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func TestImageResize8BitPNG(t *testing.T) {
386386
c.Assert(image.MediaType().Type, qt.Equals, "image/png")
387387
c.Assert(image.RelPermalink(), qt.Equals, "/a/gohugoio.png")
388388
c.Assert(image.ResourceType(), qt.Equals, "image")
389-
c.Assert(image.Exif(), qt.IsNotNil)
389+
c.Assert(image.Meta(), qt.IsNotNil)
390390

391391
resized, err := image.Resize("800x")
392392
c.Assert(err, qt.IsNil)
@@ -414,14 +414,17 @@ func TestSVGImageContent(t *testing.T) {
414414
c.Assert(content.(string), qt.Contains, `<svg height="100" width="100">`)
415415
}
416416

417-
func TestImageExif(t *testing.T) {
417+
func TestImageMeta(t *testing.T) {
418418
c := qt.New(t)
419419
fs := afero.NewMemMapFs()
420-
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
420+
meta := map[string]any{
421+
"fields": []string{"*{Date,Lens,GPS}*"},
422+
}
423+
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c, imagingMeta: meta})
421424
image := fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
422425

423-
getAndCheckExif := func(c *qt.C, image images.ImageResource) {
424-
x := image.Exif()
426+
getAndCheckMeta := func(c *qt.C, image images.ImageResource) {
427+
x := image.Meta()
425428
c.Assert(x, qt.Not(qt.IsNil))
426429

427430
c.Assert(x.Date.Format("2006-01-02"), qt.Equals, "2017-10-27")
@@ -430,21 +433,21 @@ func TestImageExif(t *testing.T) {
430433
c.Assert(x.Lat, qt.Equals, float64(36.59744166666667))
431434
c.Assert(x.Long, qt.Equals, float64(-4.50846))
432435

433-
v, found := x.Tags["LensModel"]
436+
v, found := x.Exif["LensModel"]
434437
c.Assert(found, qt.Equals, true)
435438
lensModel, ok := v.(string)
436439
c.Assert(ok, qt.Equals, true)
437440
c.Assert(lensModel, qt.Equals, "smc PENTAX-DA* 16-50mm F2.8 ED AL [IF] SDM")
438441
resized, _ := image.Resize("300x200")
439-
x2 := resized.Exif()
442+
x2 := resized.Meta()
440443

441444
c.Assert(x2, eq, x)
442445
}
443446

444-
getAndCheckExif(c, image)
447+
getAndCheckMeta(c, image)
445448
image = fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
446449
// This will read from file cache.
447-
getAndCheckExif(c, image)
450+
getAndCheckMeta(c, image)
448451
}
449452

450453
func TestImageColorsLuminance(t *testing.T) {
@@ -465,14 +468,17 @@ func TestImageColorsLuminance(t *testing.T) {
465468
}
466469
}
467470

468-
func BenchmarkImageExif(b *testing.B) {
469-
getImage := func(i int, c *qt.C, b *testing.B, fs afero.Fs) images.ImageResource {
470-
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
471+
func BenchmarkImageMeta(b *testing.B) {
472+
getImage := func(i int, c *qt.C, fs afero.Fs) images.ImageResource {
473+
meta := map[string]any{
474+
"fields": []string{"*{Date,Lens,GPS}*"},
475+
}
476+
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c, imagingMeta: meta})
471477
return fetchResourceForSpec(spec, c, "sunset.jpg", strconv.Itoa(i)).(images.ImageResource)
472478
}
473479

474-
getAndCheckExif := func(c *qt.C, image images.ImageResource) {
475-
x := image.Exif()
480+
getAndCheckMeta := func(c *qt.C, image images.ImageResource) {
481+
x := image.Meta()
476482
c.Assert(x, qt.Not(qt.IsNil))
477483
c.Assert(x.Long, qt.Equals, float64(-4.50846))
478484
}
@@ -482,9 +488,9 @@ func BenchmarkImageExif(b *testing.B) {
482488
fs := afero.NewMemMapFs()
483489
for i := 0; b.Loop(); i++ {
484490
b.StopTimer()
485-
image := getImage(i, c, b, fs)
491+
image := getImage(i, c, fs)
486492
b.StartTimer()
487-
getAndCheckExif(c, image)
493+
getAndCheckMeta(c, image)
488494
}
489495
})
490496

@@ -493,10 +499,10 @@ func BenchmarkImageExif(b *testing.B) {
493499
fs := afero.NewMemMapFs()
494500
for i := 0; b.Loop(); i++ {
495501
b.StopTimer()
496-
image := getImage(i, c, b, fs)
502+
image := getImage(i, c, fs)
497503
b.StartTimer()
498504
for range 10 {
499-
getAndCheckExif(c, image)
505+
getAndCheckMeta(c, image)
500506
}
501507
}
502508
})
@@ -506,17 +512,17 @@ func BenchmarkImageExif(b *testing.B) {
506512
fs := afero.NewMemMapFs()
507513
// Prime the cache
508514
for i := 0; i < b.N; i++ {
509-
image := getImage(i, c, b, fs)
510-
getAndCheckExif(c, image)
515+
image := getImage(i, c, fs)
516+
getAndCheckMeta(c, image)
511517
}
512518

513519
// Start the real benchmark,
514520
b.ResetTimer()
515521
for i := 0; i < b.N; i++ {
516522
b.StopTimer()
517-
image := getImage(i, c, b, fs)
523+
image := getImage(i, c, fs)
518524
b.StartTimer()
519-
getAndCheckExif(c, image)
525+
getAndCheckMeta(c, image)
520526
}
521527
})
522528
}

resources/testhelpers_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
)
2323

2424
type specDescriptor struct {
25-
baseURL string
26-
c *qt.C
27-
fs afero.Fs
25+
baseURL string
26+
c *qt.C
27+
fs afero.Fs
28+
imagingMeta map[string]any
2829
}
2930

3031
func newTestResourceSpec(desc specDescriptor) *resources.Spec {
@@ -56,6 +57,10 @@ func newTestResourceSpec(desc specDescriptor) *resources.Spec {
5657
"anchor": "left",
5758
}
5859

60+
if desc.imagingMeta != nil {
61+
imagingCfg["meta"] = desc.imagingMeta
62+
}
63+
5964
cfg.Set("imaging", imagingCfg)
6065
d := testconfig.GetTestDeps(
6166
afs, cfg,

0 commit comments

Comments
 (0)