From 280f85abd1b34a4b4b1eb2db3111fffdda16aaf8 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 23 Mar 2024 16:14:07 +0100 Subject: [PATCH] Add fuzz testing to Base64LineBreaker_Write function The update enhances testing for the Base64LineBreaker_Write function by creating a fuzz test. This new fuzz test feeds the function with a wide range of random byte inputs to improve the detection of hidden anomalies and help ensure more robust code. --- b64linebreaker_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/b64linebreaker_test.go b/b64linebreaker_test.go index e95245b..bf732a6 100644 --- a/b64linebreaker_test.go +++ b/b64linebreaker_test.go @@ -461,3 +461,14 @@ func (e errorWriter) Write([]byte) (int, error) { func (e errorWriter) Close() error { return fmt.Errorf("supposed to always fail") } + +func FuzzBase64LineBreaker_Write(f *testing.F) { + f.Add([]byte(logoB64)) + buf := bytes.Buffer{} + f.Fuzz(func(t *testing.T, data []byte) { + b := &Base64LineBreaker{out: &buf} + if _, err := b.Write(data); err != nil { + t.Errorf("failed to write to B64LineBreaker: %s", err) + } + }) +}