Module D06: Unit Testing Checks and Services
Track: D2 · Checks · Effort: 2.5 h · Prowler: 5.48
Scenario
Your s3_bucket_owner_tag_present branch (feat/s3-owner-tag) has a three-test MagicMock file from Module D03, metadata from Module D04 and a configurable tag key from Module D05. A Prowler maintainer reviewing a draft asks for more before approval: tests that run the real S3 service through moto, edge cases such as an empty Owner value and a custom tag key, and a test that records what happens when Cloudsmiths' scanning role cannot read bucket tags. The Azure team also wants coverage for a storage check they rely on. In this module you learn how Prowler tests are laid out, how each provider is mocked, and what CI runs when you push.
Learning objectives
- Place check and service tests in the folder that mirrors the source tree and follow the file, class and function naming rules.
- Write AWS check tests with
@mock_aws,set_mocked_aws_providerand the twomock.patchcalls every check test needs. - Choose between pure
moto,motoplus a patched_make_api_call, andMagicMock, based on moto's API coverage. - Test Azure, GCP and other non-AWS checks by patching the
<service>_clientwith aMagicMockthat holds real resource models. - Cover the required scenarios (no resources,
PASS,FAIL, andMANUALwhere it applies) and run a single file, folder or provider locally. - Explain how CI picks which tests to run: the AWS service dependency table and test impact analysis.
Regístrate para leer el módulo completo
El temario y el resumen de cada módulo son públicos. Crea una cuenta gratuita para desbloquear las lecciones completas, los laboratorios, las comprobaciones de conocimientos y el examen final, y para seguir tu progreso.