diff --git a/cmd/mime-extractor/mime-extractor_test.go b/cmd/mime-extractor/mime-extractor_test.go index 824bf1cf..7af05f11 100644 --- a/cmd/mime-extractor/mime-extractor_test.go +++ b/cmd/mime-extractor/mime-extractor_test.go @@ -2,7 +2,7 @@ package main import ( "bytes" - "fmt" + "errors" "io" "os" "path/filepath" @@ -85,7 +85,7 @@ func TestExtractFailedToParse(t *testing.T) { func TestExtractAttachmentWriteFail(t *testing.T) { s := &bytes.Buffer{} fw := func(filename string, data []byte, perm os.FileMode) error { - return fmt.Errorf("AttachmentWriteFail") + return errors.New("AttachmentWriteFail") } testExtractor := &extractor{ errOut: io.Discard, diff --git a/cmd/utils.go b/cmd/utils.go index f94a19f7..57dd26b2 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -168,7 +168,7 @@ func FormatPart(w io.Writer, p *enmime.Part, indent string) { } disposition := "" if p.Disposition != "" { - disposition = fmt.Sprintf(", disposition: %s", p.Disposition) + disposition = ", disposition: " + p.Disposition } filename := "" if p.FileName != "" { diff --git a/envelope.go b/envelope.go index 77d313e1..5c36e6f8 100644 --- a/envelope.go +++ b/envelope.go @@ -69,7 +69,7 @@ func (e *Envelope) GetHeaderValues(name string) []string { // If the header exists already, all existing values are replaced. func (e *Envelope) SetHeader(name string, value []string) error { if name == "" { - return fmt.Errorf("provide non-empty header name") + return errors.New("provide non-empty header name") } for i, v := range value { @@ -86,7 +86,7 @@ func (e *Envelope) SetHeader(name string, value []string) error { // If the header does not exist already, it will be created. func (e *Envelope) AddHeader(name string, value string) error { if name == "" { - return fmt.Errorf("provide non-empty header name") + return errors.New("provide non-empty header name") } e.header.Add(name, mime.BEncoding.Encode("utf-8", value)) @@ -96,7 +96,7 @@ func (e *Envelope) AddHeader(name string, value string) error { // DeleteHeader deletes given header. func (e *Envelope) DeleteHeader(name string) error { if name == "" { - return fmt.Errorf("provide non-empty header name") + return errors.New("provide non-empty header name") } e.header.Del(name) @@ -106,7 +106,7 @@ func (e *Envelope) DeleteHeader(name string) error { // AddressList returns a mail.Address slice with RFC 2047 encoded names converted to UTF-8 func (e *Envelope) AddressList(key string) ([]*mail.Address, error) { if e.header == nil { - return nil, fmt.Errorf("no headers available") + return nil, errors.New("no headers available") } if !AddressHeaders[strings.ToLower(key)] { return nil, fmt.Errorf("%s is not an address header", key) @@ -272,7 +272,7 @@ func parseMultiPartBody(root *Part, e *Envelope) error { } boundary := params[hpBoundary] if boundary == "" { - return fmt.Errorf("unable to locate boundary param in Content-Type header") + return errors.New("unable to locate boundary param in Content-Type header") } // Locate text body diff --git a/envelope_test.go b/envelope_test.go index 6ece7bce..bc19759c 100644 --- a/envelope_test.go +++ b/envelope_test.go @@ -30,7 +30,7 @@ func TestParseHeaderOnly(t *testing.T) { t.Errorf("Expected no HTML body, got %q", e.HTML) } if e.Root == nil { - t.Errorf("Expected a root part") + t.Error("Expected a root part") } if len(e.Root.Header) != 7 { t.Errorf("Expected 7 headers, got %d", len(e.Root.Header)) @@ -998,11 +998,11 @@ func TestAttachmentOnly(t *testing.T) { } // Check, if root header is set if len(e.Root.Header) < 1 { - t.Errorf("No root header defined, but must be set from binary only part.") + t.Error("No root header defined, but must be set from binary only part.") } // Check, that the root part has content if len(e.Root.Content) == 0 { - t.Errorf("Root part of envelope has no content.") + t.Error("Root part of envelope has no content.") } } } diff --git a/inspect_test.go b/inspect_test.go index e65a83ba..97a63504 100644 --- a/inspect_test.go +++ b/inspect_test.go @@ -16,21 +16,21 @@ func TestDecodeRFC2047(t *testing.T) { t.Run("rfc2047 basic", func(t *testing.T) { s := enmime.DecodeRFC2047("=?UTF-8?Q?Miros=C5=82aw_Marczak?=") if s != "Mirosław Marczak" { - t.Errorf("Wrong decoded result") + t.Error("Wrong decoded result") } }) t.Run("rfc2047 unknown", func(t *testing.T) { s := enmime.DecodeRFC2047("=?ABC-1?Q?FooBar?=") if s != "=?ABC-1?Q?FooBar?=" { - t.Errorf("Expected unmodified result for unknown charset") + t.Error("Expected unmodified result for unknown charset") } }) t.Run("rfc2047 pass-through", func(t *testing.T) { s := enmime.DecodeRFC2047("Hello World") if s != "Hello World" { - t.Errorf("Expected unmodified result") + t.Error("Expected unmodified result") } }) } @@ -47,7 +47,7 @@ func TestDecodeHeaders(t *testing.T) { t.Errorf("%+v", err) } if !strings.Contains(h.Get("To"), "Mirosław Marczak") { - t.Errorf("Error decoding RFC2047 header value") + t.Error("Error decoding RFC2047 header value") } }) @@ -62,7 +62,7 @@ func TestDecodeHeaders(t *testing.T) { t.Errorf("%+v", err) } if !strings.Contains(h.Get("To"), "Mirosław Marczak") { - t.Errorf("Error decoding RFC2047 header value") + t.Error("Error decoding RFC2047 header value") } }) @@ -92,7 +92,7 @@ func TestDecodeHeaders(t *testing.T) { t.Errorf("%+v", err) } if !strings.Contains(h.Get("From"), "WirelessCaller (203) 402-5984 WirelessCaller (203) 402-5984 WirelessCaller (203) 402-5984") { - t.Errorf("Error decoding recursive RFC2047 header value") + t.Error("Error decoding recursive RFC2047 header value") } }) } diff --git a/internal/coding/headerext.go b/internal/coding/headerext.go index 8b545121..6aec1775 100644 --- a/internal/coding/headerext.go +++ b/internal/coding/headerext.go @@ -61,10 +61,10 @@ func RFC2047Decode(s string) string { // Add quotes as needed. if !strings.HasPrefix(value, "\"") { - value = fmt.Sprintf("\"%s", value) + value = `"` + value } if !strings.HasSuffix(value, "\"") { - value = fmt.Sprintf("%s\"", value) + value += `"` } return fmt.Sprintf("%s=%s", key, value) diff --git a/internal/stringutil/uuid_test.go b/internal/stringutil/uuid_test.go index 7df63902..4ad68e7d 100644 --- a/internal/stringutil/uuid_test.go +++ b/internal/stringutil/uuid_test.go @@ -4,15 +4,12 @@ import ( "testing" "github.com/jhillyerd/enmime/internal/stringutil" + "github.com/stretchr/testify/assert" ) func TestUUID(t *testing.T) { id1 := stringutil.UUID(nil) id2 := stringutil.UUID(nil) - if id1 == id2 { - t.Errorf("Random UUID should not equal another random UUID") - t.Logf("id1: %q", id1) - t.Logf("id2: %q", id2) - } + assert.NotEqual(t, id1, id2, "Random UUID should not equal another random UUID") } diff --git a/internal/textproto/reader.go b/internal/textproto/reader.go index 68321537..73759f9b 100644 --- a/internal/textproto/reader.go +++ b/internal/textproto/reader.go @@ -127,7 +127,7 @@ func (r *Reader) ReadContinuedLineBytes() ([]byte, error) { // error is returned from readContinuedLineSlice. func (r *Reader) readContinuedLineSlice(validateFirstLine func([]byte) error) ([]byte, error) { if validateFirstLine == nil { - return nil, fmt.Errorf("missing validateFirstLine func") + return nil, errors.New("missing validateFirstLine func") } // Read the first line.