From f380edc1bdc8c4e3b463c64e3be0695913f2afff Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Mon, 21 Aug 2017 08:44:01 -0400 Subject: [PATCH] Add a test case for #177. Signed-off-by: Yoan Blanc --- image_test.go | 56 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/image_test.go b/image_test.go index e7c431b2..4990882a 100644 --- a/image_test.go +++ b/image_test.go @@ -213,33 +213,45 @@ func TestImageThumbnail(t *testing.T) { } func TestImageWatermark(t *testing.T) { - image := initImage("test.jpg") - _, err := image.Crop(800, 600, GravityNorth) - if err != nil { - t.Errorf("Cannot process the image: %#v", err) + files := []struct { + Name string + Type ImageType + }{ + {"test.jpg", JPEG}, + {"test.png", PNG}, } - buf, err := image.Watermark(Watermark{ - Text: "Copy me if you can", - Opacity: 0.5, - Width: 200, - DPI: 100, - Background: Color{255, 255, 255}, - }) - if err != nil { - t.Error(err) - } + for _, file := range files { + image := initImage(file.Name) + _, err := image.Crop(800, 600, GravityNorth) + if err != nil { + t.Errorf("Cannot process the image: %#v", err) + continue + } - err = assertSize(buf, 800, 600) - if err != nil { - t.Error(err) - } + buf, err := image.Watermark(Watermark{ + Text: "Copy me if you can", + Opacity: 0.5, + Width: 200, + DPI: 100, + Background: Color{255, 255, 255}, + }) + if err != nil { + t.Errorf("Watermark failure: %s", err) + continue + } - if DetermineImageType(buf) != JPEG { - t.Fatal("Image is not jpeg") - } + err = assertSize(buf, 800, 600) + if err != nil { + t.Error(err) + continue + } - Write("fixtures/test_watermark_text_out.jpg", buf) + tp := DetermineImageType(buf) + if tp != file.Type { + t.Errorf("Image is not %v, got %v", ImageTypeName(file.Type), ImageTypeName(tp)) + } + } } func TestImageWatermarkWithImage(t *testing.T) {