Path: blob/dev/pkg/operators/matchers/fuzz_harness_test.go
4538 views
package matchers12import (3"os"4"path/filepath"5"testing"67"github.com/stretchr/testify/require"8)910func TestMatcherFromFuzzDataSeedCorpus(t *testing.T) {11entries, err := os.ReadDir("testdata/gofuzz-corpus")12require.NoError(t, err)13require.NotEmpty(t, entries)1415for _, entry := range entries {16if entry.IsDir() {17continue18}1920path := filepath.Join("testdata/gofuzz-corpus", entry.Name())21data, err := os.ReadFile(path)22require.NoError(t, err)2324matcher, ok := matcherFromFuzzData(data)25require.Truef(t, ok, "seed %s should decode into a matcher", entry.Name())26require.NoErrorf(t, matcher.CompileMatchers(), "seed %s should compile", entry.Name())27}28}2930func TestMatcherFromFuzzDataRejectsOversizeInput(t *testing.T) {31data := make([]byte, fuzzMaxInputSize+1)32matcher, ok := matcherFromFuzzData(data)33require.False(t, ok)34require.Nil(t, matcher)35}363738