Update Base64LineBreaker_Write testing

Enhanced testing for the Base64LineBreaker_Write function by adding a fuzz test. This additional fuzz test provides the function with a variety of random byte inputs as a way of uncovering any hidden errors and contributing to more reliable coding.
This commit is contained in:
Winni Neessen 2024-03-23 16:35:32 +01:00
parent 280f85abd1
commit 821ee0a9e1
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -5,6 +5,7 @@
package mail
import (
"bufio"
"bytes"
"encoding/base64"
"fmt"
@ -463,12 +464,18 @@ func (e errorWriter) Close() error {
}
func FuzzBase64LineBreaker_Write(f *testing.F) {
f.Add([]byte(logoB64))
f.Add([]byte("abc"))
f.Add([]byte("def"))
f.Add([]uint8{00, 01, 02, 30, 255})
buf := bytes.Buffer{}
bw := bufio.NewWriter(&buf)
f.Fuzz(func(t *testing.T, data []byte) {
b := &Base64LineBreaker{out: &buf}
b := &Base64LineBreaker{out: bw}
if _, err := b.Write(data); err != nil {
t.Errorf("failed to write to B64LineBreaker: %s", err)
}
if err := b.Close(); err != nil {
t.Errorf("failed to close B64LineBreaker: %s", err)
}
})
}