Tests: Add tests for internal/thumb
This commit is contained in:
parent
3f68c2f6e4
commit
a01288a5ac
|
@ -233,6 +233,24 @@ func TestFromFile(t *testing.T) {
|
|||
assert.FileExists(t, dst)
|
||||
})
|
||||
|
||||
t.Run("orientation >1 ", func(t *testing.T) {
|
||||
colorThumb := Types["colors"]
|
||||
src := "testdata/example.gif"
|
||||
dst := "testdata/1/2/3/123456789098765432_3x3_resize.png"
|
||||
|
||||
assert.FileExists(t, src)
|
||||
|
||||
fileName, err := FromFile(src, "123456789098765432", "testdata", colorThumb.Width, colorThumb.Height, 3, colorThumb.Options...)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, dst, fileName)
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
})
|
||||
|
||||
t.Run("missing file", func(t *testing.T) {
|
||||
colorThumb := Types["colors"]
|
||||
src := "testdata/example.xxx"
|
||||
|
@ -349,6 +367,43 @@ func TestCreate(t *testing.T) {
|
|||
assert.Equal(t, 500, boundsNew.Max.X)
|
||||
assert.Equal(t, 500, boundsNew.Max.Y)
|
||||
})
|
||||
t.Run("width & height <= 150", func(t *testing.T) {
|
||||
tile500 := Types["tile_500"]
|
||||
src := "testdata/example.jpg"
|
||||
dst := "testdata/example.tile_500.jpg"
|
||||
|
||||
assert.FileExists(t, src)
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := imaging.Open(src, imaging.AutoOrientation(true))
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bounds := img.Bounds()
|
||||
|
||||
assert.Equal(t, 750, bounds.Max.X)
|
||||
assert.Equal(t, 500, bounds.Max.Y)
|
||||
|
||||
resized, err := Create(img, dst, 150, 150, tile500.Options...)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
imgNew := resized
|
||||
boundsNew := imgNew.Bounds()
|
||||
|
||||
assert.Equal(t, 150, boundsNew.Max.X)
|
||||
assert.Equal(t, 150, boundsNew.Max.Y)
|
||||
})
|
||||
t.Run("invalid width", func(t *testing.T) {
|
||||
tile500 := Types["tile_500"]
|
||||
src := "testdata/example.jpg"
|
||||
|
|
|
@ -30,6 +30,204 @@ func TestJpeg(t *testing.T) {
|
|||
assert.Equal(t, 67, bounds.Max.X)
|
||||
assert.Equal(t, 100, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationFlipH", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationFlipH)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationFlipV", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationFlipV)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationRotate90", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationRotate90)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 67, bounds.Max.X)
|
||||
assert.Equal(t, 100, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationRotate180", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationRotate180)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationTranspose", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationTranspose)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 67, bounds.Max.X)
|
||||
assert.Equal(t, 100, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationTransverse", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationTransverse)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 67, bounds.Max.X)
|
||||
assert.Equal(t, 100, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationUnspecified", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationUnspecified)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("OrientationNormal", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, OrientationNormal)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
t.Run("invalid orientation", func(t *testing.T) {
|
||||
src := "testdata/example." + ext
|
||||
dst := "testdata/example." + ext + fs.JpegExt
|
||||
|
||||
assert.NoFileExists(t, dst)
|
||||
|
||||
img, err := Jpeg(src, dst, 500)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.FileExists(t, dst)
|
||||
|
||||
bounds := img.Bounds()
|
||||
assert.Equal(t, 100, bounds.Max.X)
|
||||
assert.Equal(t, 67, bounds.Max.Y)
|
||||
|
||||
if err := os.Remove(dst); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue