tests: fix errors after lint series

Fix the following test failures:

 FAIL: TestMessageInfoHandledError (0.00s)
 parse_test.go:53: could not parse envelope: date parsing failed:
 unrecognized date format:

 FAIL: TestReader (0.07s)
 gpg_test.go:27: using GNUPGHOME = /tmp/TestReader2384941142/001
 reader_test.go:108: Test case: Invalid Signature
 reader_test.go:112: gpg.Read() = gpgmail: failed to read PGP
 message: gpg: failed to run verification: exit status 1

Fixes: 5ca6022d00 ("lint: ensure errors are at least logged (errcheck)")
Fixes: 70bfcfef42 ("lint: work nicely with wrapped errors (errorlint)")
Signed-off-by: Robin Jarry <robin@jarry.cc>
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
Robin Jarry 2022-08-04 22:48:14 +02:00
parent 1b4b225318
commit 6b1afc3ae3
4 changed files with 7 additions and 20 deletions

View file

@ -25,13 +25,10 @@ func Encrypt(r io.Reader, to []string, from string) ([]byte, error) {
args = append(args, "--encrypt", "-") args = append(args, "--encrypt", "-")
g := newGpg(r, args) g := newGpg(r, args)
err := g.cmd.Run() _ = g.cmd.Run()
if err != nil {
return nil, fmt.Errorf("gpg: failed to run encryption: %w", err)
}
outRdr := bytes.NewReader(g.stdout.Bytes()) outRdr := bytes.NewReader(g.stdout.Bytes())
var md models.MessageDetails var md models.MessageDetails
err = parse(outRdr, &md) err := parse(outRdr, &md)
if err != nil { if err != nil {
return nil, fmt.Errorf("gpg: failure to encrypt: %w. check public key(s)", err) return nil, fmt.Errorf("gpg: failure to encrypt: %w. check public key(s)", err)
} }

View file

@ -17,14 +17,11 @@ func Sign(r io.Reader, from string) ([]byte, string, error) {
} }
g := newGpg(r, args) g := newGpg(r, args)
err := g.cmd.Run() _ = g.cmd.Run()
if err != nil {
return nil, "", fmt.Errorf("failed to run signing: %w", err)
}
outRdr := bytes.NewReader(g.stdout.Bytes()) outRdr := bytes.NewReader(g.stdout.Bytes())
var md models.MessageDetails var md models.MessageDetails
err = parse(outRdr, &md) err := parse(outRdr, &md)
if err != nil { if err != nil {
return nil, "", fmt.Errorf("failed to parse messagedetails: %w", err) return nil, "", fmt.Errorf("failed to parse messagedetails: %w", err)
} }

View file

@ -2,7 +2,6 @@ package gpgbin
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -30,17 +29,11 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
return nil, err return nil, err
} }
g := newGpg(bytes.NewReader(orig), args) g := newGpg(bytes.NewReader(orig), args)
err = g.cmd.Run() _ = g.cmd.Run()
if err != nil {
return nil, fmt.Errorf("gpg: failed to run verification: %w", err)
}
out := bytes.NewReader(g.stdout.Bytes()) out := bytes.NewReader(g.stdout.Bytes())
md := new(models.MessageDetails) md := new(models.MessageDetails)
err = parse(out, md) _ = parse(out, md)
if err != nil {
return nil, fmt.Errorf("gpg: failed to parse result: %w", err)
}
md.Body = bytes.NewReader(orig) md.Body = bytes.NewReader(orig)

View file

@ -167,7 +167,7 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) {
if err != nil { if err != nil {
// still return a valid struct plus a sentinel date parsing error // still return a valid struct plus a sentinel date parsing error
// if only the date parsing failed // if only the date parsing failed
err = fmt.Errorf("%v: %w", DateParseError, err) err = fmt.Errorf("%w: %v", DateParseError, err)
} }
return &models.Envelope{ return &models.Envelope{
Date: date, Date: date,