Skip to main content

Merge pull request #14 from alexwlchan/test-bad-image

ID
52220e2
date
2022-05-05 07:13:41+00:00
author
Alex Chan <alex@alexwlchan.net>
parents
91bac35, 2e807e8
message
Merge pull request #14 from alexwlchan/test-bad-image

Add a test for dealing with malformed images
changed files
2 files, 13 additions

Changed files

src/main.rs (8732) → src/main.rs (9071)

diff --git a/src/main.rs b/src/main.rs
index bf7a924..e4acce6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -254,6 +254,18 @@ mod tests {
         assert_eq!(output.stderr, "The image format Tiff is not supported\n");
     }
 
+    #[test]
+    fn it_fails_if_you_pass_a_malformed_image() {
+        let output = get_failure(&["./src/tests/malformed.txt.png"]);
+
+        assert_eq!(output.exit_code, 1);
+        assert_eq!(output.stdout, "");
+        assert_eq!(
+            output.stderr,
+            "Format error decoding Png: invalid signature\n"
+        );
+    }
+
     struct DcOutput {
         exit_code: i32,
         stdout: String,

src/tests/malformed.txt.png (0) → src/tests/malformed.txt.png (22)

diff --git a/src/tests/malformed.txt.png b/src/tests/malformed.txt.png
new file mode 100644
index 0000000..d6d2570
--- /dev/null
+++ b/src/tests/malformed.txt.png
@@ -0,0 +1 @@
+Ceci n'est pas une png
\ No newline at end of file