mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
@@ -667,16 +667,13 @@ func TestImageConfig(t *testing.T) {
|
||||
f := newTestFuncsterWithViper(v)
|
||||
|
||||
for i, this := range []struct {
|
||||
resetCache bool
|
||||
path string
|
||||
input []byte
|
||||
expected image.Config
|
||||
path string
|
||||
input []byte
|
||||
expected image.Config
|
||||
}{
|
||||
// Make sure that the cache is initialized by default.
|
||||
{
|
||||
resetCache: false,
|
||||
path: "a.png",
|
||||
input: blankImage(10, 10),
|
||||
path: "a.png",
|
||||
input: blankImage(10, 10),
|
||||
expected: image.Config{
|
||||
Width: 10,
|
||||
Height: 10,
|
||||
@@ -684,9 +681,8 @@ func TestImageConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
resetCache: true,
|
||||
path: "a.png",
|
||||
input: blankImage(10, 10),
|
||||
path: "a.png",
|
||||
input: blankImage(10, 10),
|
||||
expected: image.Config{
|
||||
Width: 10,
|
||||
Height: 10,
|
||||
@@ -694,9 +690,8 @@ func TestImageConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
resetCache: false,
|
||||
path: "b.png",
|
||||
input: blankImage(20, 15),
|
||||
path: "b.png",
|
||||
input: blankImage(20, 15),
|
||||
expected: image.Config{
|
||||
Width: 20,
|
||||
Height: 15,
|
||||
@@ -704,33 +699,18 @@ func TestImageConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
resetCache: false,
|
||||
path: "a.png",
|
||||
input: blankImage(20, 15),
|
||||
path: "a.png",
|
||||
input: blankImage(20, 15),
|
||||
expected: image.Config{
|
||||
Width: 10,
|
||||
Height: 10,
|
||||
ColorModel: color.NRGBAModel,
|
||||
},
|
||||
},
|
||||
{
|
||||
resetCache: true,
|
||||
path: "a.png",
|
||||
input: blankImage(20, 15),
|
||||
expected: image.Config{
|
||||
Width: 20,
|
||||
Height: 15,
|
||||
ColorModel: color.NRGBAModel,
|
||||
},
|
||||
},
|
||||
} {
|
||||
afero.WriteFile(f.Fs.Source, filepath.Join(workingDir, this.path), this.input, 0755)
|
||||
|
||||
if this.resetCache {
|
||||
resetImageConfigCache()
|
||||
}
|
||||
|
||||
result, err := f.imageConfig(this.path)
|
||||
result, err := f.image.config(this.path)
|
||||
if err != nil {
|
||||
t.Errorf("imageConfig returned error: %s", err)
|
||||
}
|
||||
@@ -739,29 +719,23 @@ func TestImageConfig(t *testing.T) {
|
||||
t.Errorf("[%d] imageConfig: expected '%v', got '%v'", i, this.expected, result)
|
||||
}
|
||||
|
||||
if len(defaultImageConfigCache.config) == 0 {
|
||||
if len(f.image.imageConfigCache) == 0 {
|
||||
t.Error("defaultImageConfigCache should have at least 1 item")
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := f.imageConfig(t); err == nil {
|
||||
if _, err := f.image.config(t); err == nil {
|
||||
t.Error("Expected error from imageConfig when passed invalid path")
|
||||
}
|
||||
|
||||
if _, err := f.imageConfig("non-existent.png"); err == nil {
|
||||
if _, err := f.image.config("non-existent.png"); err == nil {
|
||||
t.Error("Expected error from imageConfig when passed non-existent file")
|
||||
}
|
||||
|
||||
if _, err := f.imageConfig(""); err == nil {
|
||||
if _, err := f.image.config(""); err == nil {
|
||||
t.Error("Expected error from imageConfig when passed empty path")
|
||||
}
|
||||
|
||||
// test cache clearing
|
||||
ResetCaches()
|
||||
|
||||
if len(defaultImageConfigCache.config) != 0 {
|
||||
t.Error("ResetCaches should have cleared defaultImageConfigCache")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIn(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user