]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Replace Exif with Meta in tests
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 2 Mar 2026 09:51:18 +0000 (10:51 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 4 Mar 2026 10:38:28 +0000 (11:38 +0100)
resources/image_test.go
resources/testhelpers_test.go

index b4153f8341deb6230cd6f2d9764cfe224cbfbd8b..401bc30202da25e8f8222fad3d4ff16db49ff7e1 100644 (file)
@@ -386,7 +386,7 @@ func TestImageResize8BitPNG(t *testing.T) {
        c.Assert(image.MediaType().Type, qt.Equals, "image/png")
        c.Assert(image.RelPermalink(), qt.Equals, "/a/gohugoio.png")
        c.Assert(image.ResourceType(), qt.Equals, "image")
-       c.Assert(image.Exif(), qt.IsNotNil)
+       c.Assert(image.Meta(), qt.IsNotNil)
 
        resized, err := image.Resize("800x")
        c.Assert(err, qt.IsNil)
@@ -414,14 +414,17 @@ func TestSVGImageContent(t *testing.T) {
        c.Assert(content.(string), qt.Contains, `<svg height="100" width="100">`)
 }
 
-func TestImageExif(t *testing.T) {
+func TestImageMeta(t *testing.T) {
        c := qt.New(t)
        fs := afero.NewMemMapFs()
-       spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
+       meta := map[string]any{
+               "fields": []string{"*{Date,Lens,GPS}*"},
+       }
+       spec := newTestResourceSpec(specDescriptor{fs: fs, c: c, imagingMeta: meta})
        image := fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
 
-       getAndCheckExif := func(c *qt.C, image images.ImageResource) {
-               x := image.Exif()
+       getAndCheckMeta := func(c *qt.C, image images.ImageResource) {
+               x := image.Meta()
                c.Assert(x, qt.Not(qt.IsNil))
 
                c.Assert(x.Date.Format("2006-01-02"), qt.Equals, "2017-10-27")
@@ -430,21 +433,21 @@ func TestImageExif(t *testing.T) {
                c.Assert(x.Lat, qt.Equals, float64(36.59744166666667))
                c.Assert(x.Long, qt.Equals, float64(-4.50846))
 
-               v, found := x.Tags["LensModel"]
+               v, found := x.Exif["LensModel"]
                c.Assert(found, qt.Equals, true)
                lensModel, ok := v.(string)
                c.Assert(ok, qt.Equals, true)
                c.Assert(lensModel, qt.Equals, "smc PENTAX-DA* 16-50mm F2.8 ED AL [IF] SDM")
                resized, _ := image.Resize("300x200")
-               x2 := resized.Exif()
+               x2 := resized.Meta()
 
                c.Assert(x2, eq, x)
        }
 
-       getAndCheckExif(c, image)
+       getAndCheckMeta(c, image)
        image = fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
        // This will read from file cache.
-       getAndCheckExif(c, image)
+       getAndCheckMeta(c, image)
 }
 
 func TestImageColorsLuminance(t *testing.T) {
@@ -465,14 +468,17 @@ func TestImageColorsLuminance(t *testing.T) {
        }
 }
 
-func BenchmarkImageExif(b *testing.B) {
-       getImage := func(i int, c *qt.C, b *testing.B, fs afero.Fs) images.ImageResource {
-               spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
+func BenchmarkImageMeta(b *testing.B) {
+       getImage := func(i int, c *qt.C, fs afero.Fs) images.ImageResource {
+               meta := map[string]any{
+                       "fields": []string{"*{Date,Lens,GPS}*"},
+               }
+               spec := newTestResourceSpec(specDescriptor{fs: fs, c: c, imagingMeta: meta})
                return fetchResourceForSpec(spec, c, "sunset.jpg", strconv.Itoa(i)).(images.ImageResource)
        }
 
-       getAndCheckExif := func(c *qt.C, image images.ImageResource) {
-               x := image.Exif()
+       getAndCheckMeta := func(c *qt.C, image images.ImageResource) {
+               x := image.Meta()
                c.Assert(x, qt.Not(qt.IsNil))
                c.Assert(x.Long, qt.Equals, float64(-4.50846))
        }
@@ -482,9 +488,9 @@ func BenchmarkImageExif(b *testing.B) {
                fs := afero.NewMemMapFs()
                for i := 0; b.Loop(); i++ {
                        b.StopTimer()
-                       image := getImage(i, c, b, fs)
+                       image := getImage(i, c, fs)
                        b.StartTimer()
-                       getAndCheckExif(c, image)
+                       getAndCheckMeta(c, image)
                }
        })
 
@@ -493,10 +499,10 @@ func BenchmarkImageExif(b *testing.B) {
                fs := afero.NewMemMapFs()
                for i := 0; b.Loop(); i++ {
                        b.StopTimer()
-                       image := getImage(i, c, b, fs)
+                       image := getImage(i, c, fs)
                        b.StartTimer()
                        for range 10 {
-                               getAndCheckExif(c, image)
+                               getAndCheckMeta(c, image)
                        }
                }
        })
@@ -506,17 +512,17 @@ func BenchmarkImageExif(b *testing.B) {
                fs := afero.NewMemMapFs()
                // Prime the cache
                for i := 0; i < b.N; i++ {
-                       image := getImage(i, c, b, fs)
-                       getAndCheckExif(c, image)
+                       image := getImage(i, c, fs)
+                       getAndCheckMeta(c, image)
                }
 
                // Start the real benchmark,
                b.ResetTimer()
                for i := 0; i < b.N; i++ {
                        b.StopTimer()
-                       image := getImage(i, c, b, fs)
+                       image := getImage(i, c, fs)
                        b.StartTimer()
-                       getAndCheckExif(c, image)
+                       getAndCheckMeta(c, image)
                }
        })
 }
index 7ba71f21de1114349101b3751156e5c71cf4eccc..f6b15d63ea68ab714455923a3f72c8f67598bf59 100644 (file)
@@ -22,9 +22,10 @@ import (
 )
 
 type specDescriptor struct {
-       baseURL string
-       c       *qt.C
-       fs      afero.Fs
+       baseURL     string
+       c           *qt.C
+       fs          afero.Fs
+       imagingMeta map[string]any
 }
 
 func newTestResourceSpec(desc specDescriptor) *resources.Spec {
@@ -56,6 +57,10 @@ func newTestResourceSpec(desc specDescriptor) *resources.Spec {
                "anchor":         "left",
        }
 
+       if desc.imagingMeta != nil {
+               imagingCfg["meta"] = desc.imagingMeta
+       }
+
        cfg.Set("imaging", imagingCfg)
        d := testconfig.GetTestDeps(
                afs, cfg,