Skip to content

Instantly share code, notes, and snippets.

@dillonstreator
Created November 30, 2021 16:34
Show Gist options
  • Save dillonstreator/ef831f496e1f705b40e9858b436d5c66 to your computer and use it in GitHub Desktop.
Save dillonstreator/ef831f496e1f705b40e9858b436d5c66 to your computer and use it in GitHub Desktop.
generate mocks for golang interfaces in mocks.go files using mockery and goconcat binaries in shell scripts by finding internal and pkg
#!/usr/bin/env bash
cd "$(dirname "$0")"
find internal pkg -type d -print0 |
while IFS= read -r -d '' path; do
rm -f $path/mock_*.go || exit 1
rm -f $path/mocks.go || exit 1
mockery --dir $path --inpackage --name '(.*)' --quiet || exit 1
if ls $path/mock_*.go 1> /dev/null 2>&1; then
./bin/goconcat-$(uname)-$(uname -m) -k -p "$(basename $path)" $path/mock_*.go > $path/mocks.go || exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment