Tests: Add unit tests #3658
This commit is contained in:
parent
7cb1dcbd22
commit
311288312e
3 changed files with 77 additions and 0 deletions
|
@ -16,4 +16,16 @@ func TestRandomAngle(t *testing.T) {
|
|||
assert.GreaterOrEqual(t, a, -1*e)
|
||||
}
|
||||
})
|
||||
t.Run("max<0", func(t *testing.T) {
|
||||
e := float64(-35)
|
||||
a := RandomAngle(e)
|
||||
assert.GreaterOrEqual(t, a, e)
|
||||
assert.LessOrEqual(t, a, -1*e)
|
||||
})
|
||||
t.Run("max>180", func(t *testing.T) {
|
||||
e := float64(200)
|
||||
a := RandomAngle(e)
|
||||
assert.LessOrEqual(t, a, e)
|
||||
assert.GreaterOrEqual(t, a, -1*e)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -59,4 +59,49 @@ func TestCollage(t *testing.T) {
|
|||
|
||||
_ = os.Remove(saveName)
|
||||
})
|
||||
|
||||
t.Run("No images", func(t *testing.T) {
|
||||
var images []image.Image
|
||||
|
||||
saveName := "testdata/test-no-images-collage.jpg"
|
||||
preview, err := Collage(Polaroid, images)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = imaging.Save(preview, saveName)
|
||||
|
||||
assert.NoError(t, err)
|
||||
mimeType := fs.MimeType(saveName)
|
||||
assert.Equal(t, fs.MimeTypeJPEG, mimeType)
|
||||
|
||||
_ = os.Remove(saveName)
|
||||
})
|
||||
|
||||
t.Run("Unknown collage type", func(t *testing.T) {
|
||||
var images []image.Image
|
||||
|
||||
img, err := imaging.Open("testdata/500x500.jpg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i := 0; i <= 5; i++ {
|
||||
images = append(images, img)
|
||||
}
|
||||
|
||||
saveName := "testdata/test-unknown-type-collage.jpg"
|
||||
|
||||
preview, err := Collage("Unknown", images)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "unknown collage type Unknown", err.Error())
|
||||
|
||||
err = imaging.Save(preview, saveName)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
mimeType := fs.MimeType(saveName)
|
||||
assert.Equal(t, fs.MimeTypeJPEG, mimeType)
|
||||
|
||||
_ = os.Remove(saveName)
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,4 +29,24 @@ func TestImage(t *testing.T) {
|
|||
|
||||
_ = os.Remove(saveName)
|
||||
})
|
||||
|
||||
t.Run("Unknown type", func(t *testing.T) {
|
||||
img, err := imaging.Open("testdata/500x500.jpg")
|
||||
assert.NoError(t, err)
|
||||
|
||||
saveName := "testdata/test-image.png"
|
||||
|
||||
out, err := Image("unknown", img, RandomAngle(30))
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "unknown collage type unknown", err.Error())
|
||||
|
||||
err = imaging.Save(out, saveName)
|
||||
|
||||
assert.NoError(t, err)
|
||||
mimeType := fs.MimeType(saveName)
|
||||
assert.Equal(t, fs.MimeTypePNG, mimeType)
|
||||
|
||||
_ = os.Remove(saveName)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue