From 26e1267f6cb31c459267f117020289cc2c106763 Mon Sep 17 00:00:00 2001 From: Aleksandr Tolstikhin Date: Sat, 14 Sep 2024 00:49:33 +0700 Subject: [PATCH] Update flow_test.go --- flow/flow_test.go | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/flow/flow_test.go b/flow/flow_test.go index a31ba67e..3adcdfff 100644 --- a/flow/flow_test.go +++ b/flow/flow_test.go @@ -5,33 +5,32 @@ import ( "testing" ) -func TestMarshall(t *testing.T) { - a := "json" - res := []byte(a) - m := RawMessage(a) +func FuzzMarshall(f *testing.F) { + f.Fuzz(func(t *testing.T, ref []byte) { + rm := RawMessage(ref) - b, err := m.MarshalJSON() - if err != nil { - t.Errorf("Error %s", err) - } - - if !reflect.DeepEqual(b, res) { - t.Errorf("Error %s", err) - } + b, err := rm.MarshalJSON() + if err != nil { + t.Errorf("Error MarshalJSON: %s", err) + } + if !reflect.DeepEqual(ref, b) { + t.Errorf("Error. Expected '%s', was '%s'", ref, b) + } + }) } -func TestUnmarshall(t *testing.T) { - strn := "json" - b := []byte(strn) - // exp := string(b) - m := RawMessage(b) +func FuzzUnmarshall(f *testing.F) { + f.Fuzz(func(t *testing.T, ref string) { + b := []byte(ref) + rm := RawMessage(b) - if err := m.UnmarshalJSON(b); err != nil { - t.Errorf("Error %s", m) - } + if err := rm.UnmarshalJSON(b); err != nil { + t.Errorf("Error UnmarshalJSON: %s", err) + } - if string(m) != strn { - t.Errorf("Error %s", m) - } + if ref != string(rm) { + t.Errorf("Error. Expected '%s', was '%s'", ref, rm) + } + }) }