add gofuzz test for consensus wal

This commit is contained in:
Anton Kaliaev 2017-12-15 11:56:24 -06:00
parent e57cad6c3f
commit 709cf18aef
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
1 changed files with 31 additions and 0 deletions

31
consensus/wal_fuzz.go Normal file
View File

@ -0,0 +1,31 @@
// +build gofuzz
package consensus
import (
"bytes"
"io"
)
func Fuzz(data []byte) int {
dec := NewWALDecoder(bytes.NewReader(data))
for {
msg, err := dec.Decode()
if err == io.EOF {
break
}
if err != nil {
if msg != nil {
panic("msg != nil on error")
}
return 0
}
var w bytes.Buffer
enc := NewWALEncoder(&w)
err = enc.Encode(msg)
if err != nil {
panic(err)
}
}
return 1
}