Skip to content

Test automated fuzz testing #30

Test automated fuzz testing

Test automated fuzz testing #30

Workflow file for this run

name: Fuzz test
on:
pull_request:
jobs:
find-tests:
name: Find fuzz tests
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Find fuzz tests
id: set-matrix
run: |
TEST_FILES=$(find . -name '*_test.go' -not -path './vendor/*')
RESULTS=()
for FILE in $TEST_FILES; do
FUZZ_FUNC=$(grep -E 'func Fuzz\w*' $FILE | sed 's/func //' | sed 's/(.*$//')
if [ -z "$FUZZ_FUNC" ]; then
continue
fi
PACKAGE_PATH=$(dirname ${FILE#./})
RESULTS+=("{\"package\":\"$PACKAGE_PATH\",\"function\":\"$FUZZ_FUNC\"}")
echo "Found $PACKAGE_PATH :: $FUZZ_FUNC"
done
NUM_RESULTS=${#RESULTS[@]}
INCLUDE_STRING=""
for (( i=0; i<$NUM_RESULTS; i++ )); do
INCLUDE_STRING+="${RESULTS[$i]}"
if [[ $i -lt $(($NUM_RESULTS-1)) ]]; then
INCLUDE_STRING+=","
fi
done
echo 'matrix={"include": ['$INCLUDE_STRING']}' >> $GITHUB_OUTPUT
fuzz:
name: "${{ matrix.package }} :: ${{ matrix.function }}"
runs-on: ubuntu-latest
if: needs.find-tests.outputs.matrix != ''
needs: [find-tests]
strategy:
matrix: ${{fromJson(needs.find-tests.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: false
- name: Find cache location
run:
echo "FUZZ_CACHE=$(go env GOCACHE)/fuzz" >> $GITHUB_ENV
- name: Restore corpus
uses: actions/cache@v4
with:
path: ${{ env.FUZZ_CACHE }}
key: fuzz-${{ matrix.package }}-${{ matrix.function }}-${{ github.sha }}
restore-keys: |
fuzz-${{ matrix.package }}-${{ matrix.function }}-
save-always: true
- name: Fuzz
run: |
cd "${{ matrix.package }}"
go test -fuzz="${{ matrix.function }}" -run="${{ matrix.function }}" -fuzztime=5s .