mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package resources
|
||||
package resources_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/resources"
|
||||
"github.com/gohugoio/hugo/resources/images/webp"
|
||||
|
||||
"github.com/gohugoio/hugo/common/paths"
|
||||
@@ -51,9 +52,6 @@ import (
|
||||
)
|
||||
|
||||
var eq = qt.CmpEquals(
|
||||
cmp.Comparer(func(p1, p2 *resourceAdapter) bool {
|
||||
return p1.resourceAdapterInner == p2.resourceAdapterInner
|
||||
}),
|
||||
cmp.Comparer(func(p1, p2 os.FileInfo) bool {
|
||||
return p1.Name() == p2.Name() && p1.Size() == p2.Size() && p1.IsDir() == p2.IsDir()
|
||||
}),
|
||||
@@ -65,9 +63,9 @@ var eq = qt.CmpEquals(
|
||||
}
|
||||
return p1.Name() == p2.Name() && p1.Size() == p2.Size() && p1.IsDir() == p2.IsDir()
|
||||
}),
|
||||
cmp.Comparer(func(p1, p2 *genericResource) bool { return p1 == p2 }),
|
||||
//cmp.Comparer(func(p1, p2 *genericResource) bool { return p1 == p2 }),
|
||||
cmp.Comparer(func(m1, m2 media.Type) bool {
|
||||
return m1.Type() == m2.Type()
|
||||
return m1.Type == m2.Type
|
||||
}),
|
||||
cmp.Comparer(
|
||||
func(v1, v2 *big.Rat) bool {
|
||||
@@ -82,9 +80,8 @@ var eq = qt.CmpEquals(
|
||||
func TestImageTransformBasic(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchSunset(c)
|
||||
|
||||
fileCache := image.(specProvider).getSpec().FileCaches.ImageCache().Fs
|
||||
spec, image := fetchSunset(c)
|
||||
fileCache := spec.FileCaches.ImageCache().Fs
|
||||
|
||||
assertWidthHeight := func(img images.ImageResource, w, h int) {
|
||||
c.Helper()
|
||||
@@ -150,7 +147,7 @@ func TestImageTransformBasic(t *testing.T) {
|
||||
// Check cache
|
||||
filledAgain, err := image.Fill("200x100 bottomLeft")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(filled, eq, filledAgain)
|
||||
c.Assert(filled, qt.Equals, filledAgain)
|
||||
|
||||
cropped, err := image.Crop("300x300 topRight")
|
||||
c.Assert(err, qt.IsNil)
|
||||
@@ -165,16 +162,15 @@ func TestImageTransformBasic(t *testing.T) {
|
||||
// Check cache
|
||||
croppedAgain, err := image.Crop("300x300 topRight")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(cropped, eq, croppedAgain)
|
||||
c.Assert(cropped, qt.Equals, croppedAgain)
|
||||
|
||||
}
|
||||
|
||||
func TestImageTransformFormat(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchSunset(c)
|
||||
|
||||
fileCache := image.(specProvider).getSpec().FileCaches.ImageCache().Fs
|
||||
spec, image := fetchSunset(c)
|
||||
fileCache := spec.FileCaches.ImageCache().Fs
|
||||
|
||||
assertExtWidthHeight := func(img images.ImageResource, ext string, w, h int) {
|
||||
c.Helper()
|
||||
@@ -259,7 +255,7 @@ func TestImageBugs(t *testing.T) {
|
||||
|
||||
// Issue #4261
|
||||
c.Run("Transform long filename", func(c *qt.C) {
|
||||
image := fetchImage(c, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
|
||||
_, image := fetchImage(c, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
|
||||
c.Assert(image, qt.Not(qt.IsNil))
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
@@ -277,7 +273,7 @@ func TestImageBugs(t *testing.T) {
|
||||
|
||||
// Issue #6137
|
||||
c.Run("Transform upper case extension", func(c *qt.C) {
|
||||
image := fetchImage(c, "sunrise.JPG")
|
||||
_, image := fetchImage(c, "sunrise.JPG")
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
@@ -288,7 +284,7 @@ func TestImageBugs(t *testing.T) {
|
||||
|
||||
// Issue #7955
|
||||
c.Run("Fill with smartcrop", func(c *qt.C) {
|
||||
sunset := fetchImage(c, "sunset.jpg")
|
||||
_, sunset := fetchImage(c, "sunset.jpg")
|
||||
|
||||
for _, test := range []struct {
|
||||
originalDimensions string
|
||||
@@ -363,7 +359,7 @@ func TestImageTransformConcurrent(t *testing.T) {
|
||||
func TestImageWithMetadata(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchSunset(c)
|
||||
_, image := fetchSunset(c)
|
||||
|
||||
meta := []map[string]any{
|
||||
{
|
||||
@@ -373,7 +369,7 @@ func TestImageWithMetadata(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
c.Assert(AssignMetadata(meta, image), qt.IsNil)
|
||||
c.Assert(resources.AssignMetadata(meta, image), qt.IsNil)
|
||||
c.Assert(image.Name(), qt.Equals, "Sunset #1")
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
@@ -384,16 +380,16 @@ func TestImageWithMetadata(t *testing.T) {
|
||||
func TestImageResize8BitPNG(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchImage(c, "gohugoio.png")
|
||||
_, image := fetchImage(c, "gohugoio.png")
|
||||
|
||||
c.Assert(image.MediaType().Type(), qt.Equals, "image/png")
|
||||
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.IsNil)
|
||||
|
||||
resized, err := image.Resize("800x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized.MediaType().Type(), qt.Equals, "image/png")
|
||||
c.Assert(resized.MediaType().Type, qt.Equals, "image/png")
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_800x0_resize_linear_3.png")
|
||||
c.Assert(resized.Width(), qt.Equals, 800)
|
||||
}
|
||||
@@ -401,35 +397,33 @@ func TestImageResize8BitPNG(t *testing.T) {
|
||||
func TestImageResizeInSubPath(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchImage(c, "sub/gohugoio2.png")
|
||||
spec, image := fetchImage(c, "sub/gohugoio2.png")
|
||||
|
||||
c.Assert(image.MediaType(), eq, media.PNGType)
|
||||
c.Assert(image.MediaType(), eq, media.Builtin.PNGType)
|
||||
c.Assert(image.RelPermalink(), qt.Equals, "/a/sub/gohugoio2.png")
|
||||
c.Assert(image.ResourceType(), qt.Equals, "image")
|
||||
c.Assert(image.Exif(), qt.IsNil)
|
||||
|
||||
resized, err := image.Resize("101x101")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized.MediaType().Type(), qt.Equals, "image/png")
|
||||
c.Assert(resized.MediaType().Type, qt.Equals, "image/png")
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_3.png")
|
||||
c.Assert(resized.Width(), qt.Equals, 101)
|
||||
c.Assert(resized.Exif(), qt.IsNil)
|
||||
|
||||
publishedImageFilename := filepath.Clean(resized.RelPermalink())
|
||||
|
||||
spec := image.(specProvider).getSpec()
|
||||
|
||||
assertImageFile(c, spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
|
||||
c.Assert(spec.BaseFs.PublishFs.Remove(publishedImageFilename), qt.IsNil)
|
||||
|
||||
// Clear mem cache to simulate reading from the file cache.
|
||||
spec.imageCache.clear()
|
||||
spec.ClearCaches()
|
||||
|
||||
resizedAgain, err := image.Resize("101x101")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resizedAgain.RelPermalink(), qt.Equals, "/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_3.png")
|
||||
c.Assert(resizedAgain.Width(), qt.Equals, 101)
|
||||
assertImageFile(c, image.(specProvider).getSpec().BaseFs.PublishFs, publishedImageFilename, 101, 101)
|
||||
assertImageFile(c, spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
|
||||
}
|
||||
|
||||
func TestSVGImage(t *testing.T) {
|
||||
@@ -840,7 +834,7 @@ func assetGoldenDirs(c *qt.C, dir1, dir2 string) {
|
||||
|
||||
func BenchmarkResizeParallel(b *testing.B) {
|
||||
c := qt.New(b)
|
||||
img := fetchSunset(c)
|
||||
_, img := fetchSunset(c)
|
||||
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
|
Reference in New Issue
Block a user