From 242cb412f7f7c27ee846dbb6afeac9c69bad6d85 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 28 Jul 2021 11:02:25 +0700 Subject: [PATCH] add fuzz example --- txpool/pool_fuzz.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 txpool/pool_fuzz.go diff --git a/txpool/pool_fuzz.go b/txpool/pool_fuzz.go new file mode 100644 index 000000000..9cb551179 --- /dev/null +++ b/txpool/pool_fuzz.go @@ -0,0 +1,28 @@ +// +build gofuzzbeta + +package txpool + +// https://blog.golang.org/fuzz-beta +// golang.org/s/draft-fuzzing-design +//gotip doc testing +//gotip doc testing.F +//gotip doc testing.F.Add +//gotip doc testing.F.Fuzz + +func FuzzParseQuery(f *testing.F) { + f.Add("x=1&y=2") + f.Fuzz(func(t *testing.T, queryStr string) { + query, err := url.ParseQuery(queryStr) + if err != nil { + t.Skip() + } + queryStr2 := query.Encode() + query2, err := url.ParseQuery(queryStr2) + if err != nil { + t.Fatalf("ParseQuery failed to decode a valid encoded query %s: %v", queryStr2, err) + } + if !reflect.DeepEqual(query, query2) { + t.Errorf("ParseQuery gave different query after being encoded\nbefore: %v\nafter: %v", query, query2) + } + }) +}