Skip to content

Commit edeac48

Browse files
committed
fuzz: fixed fuzz test matrix
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent ce05440 commit edeac48

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/fuzz-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ jobs:
4141
jq '.|select(.Action == "output")|select( (.Output|test("^(ok)|(\\?)"))|not )|{package: .Package, test: (.Output|gsub("\n";""))}'|\
4242
jq --slurp \
4343
)
44-
echo "matrix=${fuzz_test}" >> "${GITHUB_OUTPUT}"
44+
export fuzz_tests
45+
echo "matrix<<EOF" >> "${GITHUB_OUTPUT}"
46+
printenv fuzz_tests >> "${GITHUB_OUTPUT}"
47+
echo "EOF" >> "${GITHUB_OUTPUT}"
4548
echo "::notice title=Fuzz tests found:${fuzz_tests}"
4649
4750
fuzz-test:

sample/sample.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ package sample
44
func Sample() int {
55
return 1
66
}
7+
8+
func fuzzable(input []byte) string {
9+
if len(input) > 0 {
10+
return string(input)
11+
}
12+
13+
return "0"
14+
}

sample/sample_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ func TestSample(t *testing.T) {
1717
*/
1818
require.Equal(t, 1, Sample())
1919
}
20+
21+
func FuzzSample(f *testing.F) {
22+
f.Add([]byte(nil))
23+
f.Add([]byte{})
24+
f.Add([]byte{'x'})
25+
26+
f.Fuzz(func(t *testing.T, input []byte) {
27+
require.NotPanics(t, func() {
28+
_ = fuzzable(input)
29+
})
30+
})
31+
}

0 commit comments

Comments
 (0)