From 4b283db0f13ff2cc8f311a62eb19d36a414d54b0 Mon Sep 17 00:00:00 2001 From: Blallo Date: Mon, 18 Jan 2021 21:14:19 +0100 Subject: [PATCH] Add test on MailFile parsing failure --- fs/maildir_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/maildir_test.go b/fs/maildir_test.go index e8388a2..0e3e0f0 100644 --- a/fs/maildir_test.go +++ b/fs/maildir_test.go @@ -2,6 +2,7 @@ package fs import ( "fmt" + "strconv" "testing" "time" @@ -75,3 +76,22 @@ func TestNewMailFile(t *testing.T) { t.Errorf("MailFile mismatch: %s", cmp.Diff(expect, mf, cmp.AllowUnexported(MailFile{}))) } } + +func TestNewMailFileErrs(t *testing.T) { + var err error + + // The name has the wrong shape + _, err = NewMailFile("pippo") + if err != ErrMalformedName { + t.Error("Function should have errored") + } + + // The shape is correct, but one of the integer field is instead a string + _, err = NewMailFile("aaaa_123.456.myplace,U=1312,FMD5=f2cf513ad46d4d9b9684103e468803a0:2,") + switch err.(type) { + case *strconv.NumError: + // Happy path + default: + t.Error("Unexpected error") + } +}