Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-18 12:21:27 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-26 16:00:44 +0300
commitf9978ed16476ca6d233a89669c62c798cdf9db9d (patch)
tree02edb31008b997a3e77055060a34971fe9e8c5a4 /resources/testhelpers_test.go
parent58d4c0a8be8beefbd7437b17bf7a9a381164d09b (diff)
Image resource refactor
This commit pulls most of the image related logic into its own package, to make it easier to reason about and extend. This is also a rewrite of the transformation logic used in Hugo Pipes, mostly to allow constructs like the one below: {{ ($myimg | fingerprint ).Width }} Fixes #5903 Fixes #6234 Fixes #6266
Diffstat (limited to 'resources/testhelpers_test.go')
-rw-r--r--resources/testhelpers_test.go44
1 files changed, 31 insertions, 13 deletions
diff --git a/resources/testhelpers_test.go b/resources/testhelpers_test.go
index 55664535c..adf752ecc 100644
--- a/resources/testhelpers_test.go
+++ b/resources/testhelpers_test.go
@@ -4,8 +4,6 @@ import (
"path/filepath"
"testing"
- "github.com/gohugoio/hugo/htesting/hqt"
-
"image"
"io"
"io/ioutil"
@@ -28,8 +26,10 @@ import (
"github.com/spf13/viper"
)
-func newTestResourceSpec(c *qt.C) *Spec {
- return newTestResourceSpecForBaseURL(c, "https://example.com/")
+type specDescriptor struct {
+ baseURL string
+ c *qt.C
+ fs afero.Fs
}
func createTestCfg() *viper.Viper {
@@ -54,7 +54,20 @@ func createTestCfg() *viper.Viper {
}
-func newTestResourceSpecForBaseURL(c *qt.C, baseURL string) *Spec {
+func newTestResourceSpec(desc specDescriptor) *Spec {
+
+ baseURL := desc.baseURL
+ if baseURL == "" {
+ baseURL = "https://example.com/"
+ }
+
+ afs := desc.fs
+ if afs == nil {
+ afs = afero.NewMemMapFs()
+ }
+
+ c := desc.c
+
cfg := createTestCfg()
cfg.Set("baseURL", baseURL)
@@ -66,7 +79,8 @@ func newTestResourceSpecForBaseURL(c *qt.C, baseURL string) *Spec {
cfg.Set("imaging", imagingCfg)
- fs := hugofs.NewMem(cfg)
+ fs := hugofs.NewFrom(afs, cfg)
+ fs.Destination = hugofs.NewCreateCountingFs(fs.Destination)
s, err := helpers.NewPathSpec(fs, cfg, nil)
c.Assert(err, qt.IsNil)
@@ -117,19 +131,23 @@ func newTestResourceOsFs(c *qt.C) *Spec {
}
-func fetchSunset(c *qt.C) *Image {
+func fetchSunset(c *qt.C) resource.Image {
return fetchImage(c, "sunset.jpg")
}
-func fetchImage(c *qt.C, name string) *Image {
- spec := newTestResourceSpec(c)
+func fetchImage(c *qt.C, name string) resource.Image {
+ spec := newTestResourceSpec(specDescriptor{c: c})
return fetchImageForSpec(spec, c, name)
}
-
-func fetchImageForSpec(spec *Spec, c *qt.C, name string) *Image {
+func fetchImageForSpec(spec *Spec, c *qt.C, name string) resource.Image {
r := fetchResourceForSpec(spec, c, name)
- c.Assert(r, hqt.IsSameType, &Image{})
- return r.(*Image)
+
+ img := r.(resource.Image)
+
+ c.Assert(img, qt.Not(qt.IsNil))
+ c.Assert(img.(specProvider).getSpec(), qt.Not(qt.IsNil))
+
+ return img
}
func fetchResourceForSpec(spec *Spec, c *qt.C, name string) resource.ContentResource {