Skip to main content

Makefile

To test your hook locally, you may use the following makefile.

#!/usr/bin/make -f
include_guard = sethook = finding-post-processing
include ../../hooks.mk

Available makefile targets#

TargetUse
clean-integration-testsResets the integration-tests namespace
unit-testsRun your hook unit tests
docker-buildBuilds your hook
docker-exportExports your hook into a .tar file
kind-importLoads your hook .tar files into your local kind cluster
deployDeploys your hook helm chart into your local kind cluster
deploy-test-depsDeploys your hook's test dependencies (demo-targets) into your local kind cluster
integration-testsDeletes all scans and runs your integration test scanners/SCANNER_NAME.test.js

Configuring your makefile (examples)#

Adding test dependencies (demo-targets)#

#!/usr/bin/make -f
include_guard = sethook = generic-webhook
include ../../hooks.mk

deploy-test-deps: deploy-test-dep-http-webhook deploy-test-dep-test-scan
deploy:    @echo ".: ๐Ÿ’พ Deploying '$(name)' $(hook-prefix) HelmChart with the docker tag '$(IMG_TAG)' into kind namespace 'integration-tests'."    helm -n integration-tests upgrade --install ro-hook . \        --set="hook.image.repository=docker.io/$(IMG_NS)/$(hook-prefix)-$(name)" \        --set="hook.image.tag=$(IMG_TAG)" \        --set="webhookUrl=http://http-webhook/hallo-welt"
integration-tests:    @echo ".: ๐Ÿฉบ Starting integration test in kind namespace 'integration-tests'."    kubectl -n integration-tests delete scans --all    cd ../../tests/integration/ && npm ci &&    npx --yes --package jest@$(JEST_VERSION) jest --verbose --ci --colors --coverage --passWithNoTests generic/read-only-write-hook.test.js

This adds the http-webhook demo-target to your integration tests. deploy-test-dep-test-scan is a sample scanner used in most hook integration tests.

The above makefile also overrides the integration-test target such that it references the generic folder as a test suite.

Changing the unit test language#

#!/usr/bin/make -f
include_guard = sethook = persistence-defectdojo
include ../../hooks.mk
unit-tests:    @$(MAKE) -s unit-test-java

You can choose from: unit-test-js unit-test-py unit-test-java.