forked from TrueCloudLab/policy-engine
Evgenii Stratonikov
2fa27b6557
Make it possible to execute fuzz tests with different backend, such as go-fuzz which supports coverage collection. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
34 lines
605 B
Go
34 lines
605 B
Go
//go:build gofuzz
|
|
// +build gofuzz
|
|
|
|
package chain
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func FuzzUnmarshal(f *testing.F) {
|
|
for _, id := range generateTestIDs() {
|
|
for _, rules := range generateTestRules() {
|
|
for _, matchType := range generateTestMatchTypes() {
|
|
|
|
chain := Chain{
|
|
ID: id,
|
|
Rules: rules,
|
|
MatchType: matchType,
|
|
}
|
|
data, err := chain.MarshalBinary()
|
|
require.NoError(f, err)
|
|
f.Add(data)
|
|
}
|
|
}
|
|
}
|
|
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
require.NotPanics(t, func() {
|
|
DoFuzzChainUnmarshalBinary(data)
|
|
})
|
|
})
|
|
}
|