From 46f997e8ba49c3a0a9e99036bdcccd4270127d81 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Tue, 9 Jul 2019 12:46:43 +0200 Subject: [PATCH] Add tests for invalid thumbnail type and invalid image format for thumbnail function --- internal/photoprism/thumbnails_test.go | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/internal/photoprism/thumbnails_test.go b/internal/photoprism/thumbnails_test.go index 2c2723e3a..47359243f 100644 --- a/internal/photoprism/thumbnails_test.go +++ b/internal/photoprism/thumbnails_test.go @@ -22,14 +22,34 @@ func TestMediaFile_Thumbnail(t *testing.T) { defer os.RemoveAll(thumbsPath) - image, err := NewMediaFile(conf.ExamplesPath() + "/elephants.jpg") - assert.Nil(t, err) + t.Run("/elephants.jpg", func(t *testing.T) { + image, err := NewMediaFile(conf.ExamplesPath() + "/elephants.jpg") + assert.Nil(t, err) - thumbnail, err := image.Thumbnail(thumbsPath, "tile_500") + thumbnail, err := image.Thumbnail(thumbsPath, "tile_500") - assert.Empty(t, err) + assert.Empty(t, err) - assert.FileExists(t, thumbnail) + assert.FileExists(t, thumbnail) + }) + t.Run("invalid image format", func(t *testing.T) { + image, err := NewMediaFile(conf.ExamplesPath() + "/canon_eos_6d.xmp") + assert.Nil(t, err) + + thumbnail, err := image.Thumbnail(thumbsPath, "tile_500") + + assert.Equal(t, "could not create thumbnail: image: unknown format", err.Error()) + t.Log(thumbnail) + }) + t.Run("invalid thumbnail type", func(t *testing.T) { + image, err := NewMediaFile(conf.ExamplesPath() + "/elephants.jpg") + assert.Nil(t, err) + + thumbnail, err := image.Thumbnail(thumbsPath, "invalid_500") + + assert.Equal(t, "invalid type: invalid_500", err.Error()) + t.Log(thumbnail) + }) } func TestCreateThumbnailsFromOriginals(t *testing.T) {