moby/libnetwork/etchosts/fuzz_test.go
AdamKorcz 93fa093122
testing: move fuzzers over from OSS-Fuzz
Signed-off-by: AdamKorcz <adam@adalogics.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-30 17:31:03 +01:00

40 lines
711 B
Go

package etchosts
import (
"os"
"path/filepath"
"testing"
fuzz "github.com/AdaLogics/go-fuzz-headers"
)
func FuzzAdd(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
ff := fuzz.NewConsumer(data)
fileBytes, err := ff.GetBytes()
if err != nil {
return
}
noOfRecords, err := ff.GetInt()
if err != nil {
return
}
recs := make([]Record, 0)
for i := 0; i < noOfRecords%40; i++ {
r := Record{}
err = ff.GenerateStruct(&r)
if err != nil {
return
}
recs = append(recs, r)
}
tmpDir := t.TempDir()
testFile := filepath.Join(tmpDir, "testFile")
err = os.WriteFile(testFile, fileBytes, 0o644)
if err != nil {
return
}
_ = Add(testFile, recs)
})
}