From 09221d592216f8e7310ceb90432564fd866f469f Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 27 Jul 2021 11:14:05 +0100 Subject: internal/pipeline: Add a test for CheckImages --- internal/pipeline/put_test.go | 36 +++++++++++++++++++++++++++++++++ internal/pipeline/testdata/bad/1.png | Bin 0 -> 9123 bytes internal/pipeline/testdata/bad/bad.png | Bin 0 -> 9114 bytes internal/pipeline/testdata/good/1.png | Bin 0 -> 9123 bytes internal/pipeline/testdata/good/2.png | Bin 0 -> 14823 bytes 5 files changed, 36 insertions(+) create mode 100644 internal/pipeline/put_test.go create mode 100644 internal/pipeline/testdata/bad/1.png create mode 100644 internal/pipeline/testdata/bad/bad.png create mode 100644 internal/pipeline/testdata/good/1.png create mode 100644 internal/pipeline/testdata/good/2.png (limited to 'internal') diff --git a/internal/pipeline/put_test.go b/internal/pipeline/put_test.go new file mode 100644 index 0000000..68dd173 --- /dev/null +++ b/internal/pipeline/put_test.go @@ -0,0 +1,36 @@ +// Copyright 2021 Nick White. +// Use of this source code is governed by the GPLv3 +// license that can be found in the LICENSE file. + +package pipeline + +import ( + "errors" + "testing" +) + +func Test_CheckImages(t *testing.T) { + cases := []struct { + dir string + err error + }{ + {"testdata/good", nil}, + {"testdata/bad", errors.New("Decoding image testdata/bad/bad.png failed: png: invalid format: invalid checksum")}, + {"testdata/nonexistent", nil}, + } + + for _, c := range cases { + t.Run(c.dir, func(t *testing.T) { + err := CheckImages(c.dir) + if err == nil && c.err != nil { + t.Fatalf("Expected error '%v', got no error", c.err) + } + if err != nil && c.err == nil { + t.Fatalf("Expected no error, got error '%v'", err) + } + if err != nil && c.err != nil && err.Error() != c.err.Error() { + t.Fatalf("Got an unexpected error, expected '%v', got '%v'", c.err, err) + } + }) + } +} diff --git a/internal/pipeline/testdata/bad/1.png b/internal/pipeline/testdata/bad/1.png new file mode 100644 index 0000000..8f90f19 Binary files /dev/null and b/internal/pipeline/testdata/bad/1.png differ diff --git a/internal/pipeline/testdata/bad/bad.png b/internal/pipeline/testdata/bad/bad.png new file mode 100644 index 0000000..77f2d14 Binary files /dev/null and b/internal/pipeline/testdata/bad/bad.png differ diff --git a/internal/pipeline/testdata/good/1.png b/internal/pipeline/testdata/good/1.png new file mode 100644 index 0000000..8f90f19 Binary files /dev/null and b/internal/pipeline/testdata/good/1.png differ diff --git a/internal/pipeline/testdata/good/2.png b/internal/pipeline/testdata/good/2.png new file mode 100644 index 0000000..a9ecd94 Binary files /dev/null and b/internal/pipeline/testdata/good/2.png differ -- cgit v1.2.1-24-ge1ad