Add test on MailFile parsing failure

This commit is contained in:
Blallo 2021-01-18 21:14:19 +01:00
parent b74764b71a
commit 4b283db0f1
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

View file

@ -2,6 +2,7 @@ package fs
import ( import (
"fmt" "fmt"
"strconv"
"testing" "testing"
"time" "time"
@ -75,3 +76,22 @@ func TestNewMailFile(t *testing.T) {
t.Errorf("MailFile mismatch: %s", cmp.Diff(expect, mf, cmp.AllowUnexported(MailFile{}))) 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")
}
}