]> Sergey Matveev's repositories - btrtrc.git/blob - webtorrent/fuzz_test.go
Drop support for go 1.20
[btrtrc.git] / webtorrent / fuzz_test.go
1 //go:build go1.18
2 // +build go1.18
3
4 package webtorrent
5
6 import (
7         "encoding/json"
8         "testing"
9
10         qt "github.com/frankban/quicktest"
11 )
12
13 func FuzzJsonBinaryStrings(f *testing.F) {
14         f.Fuzz(func(t *testing.T, in []byte) {
15                 jsonBytes, err := json.Marshal(binaryToJsonString(in))
16                 if err != nil {
17                         t.Fatal(err)
18                 }
19                 // t.Logf("%q", jsonBytes)
20                 var jsonStr string
21                 err = json.Unmarshal(jsonBytes, &jsonStr)
22                 if err != nil {
23                         t.Fatal(err)
24                 }
25                 // t.Logf("%q", jsonStr)
26                 c := qt.New(t)
27                 out, err := decodeJsonByteString(jsonStr, []byte{})
28                 c.Assert(err, qt.IsNil)
29                 c.Assert(out, qt.DeepEquals, in)
30         })
31 }