TLS Docker Support
Recording Testcases and Data Mocks
- To record test cases and data mocks, follow these steps in the root directory of your application. Ensure that you have the following prerequisites in place:
- If you're running via docker-compose, ensure to include the
<CONTAINER_NAME>
under your application service in the docker-compose.yaml file like this. - You must run all of the containers on the same network when you're using docker run command (you can add your custom network name using
--network
flag in docker run command). - In your Docker Compose file, every container should run on the same network.
Docker_CMD_to_run_user_container
refers to the Docker command for launching the application.- Add the required commands to your DockerFile as stated below.
- Add the following commands to your Dockerfile to download the
ca.crt
file and thesetup_ca.sh
script.
# Download the ca.crt file
RUN curl -o ca.crt https://raw.githubusercontent.com/keploy/keploy/refs/heads/main/pkg/core/proxy/tls/asset/ca.crt
RUN curl -o setup_ca.sh https://raw.githubusercontent.com/keploy/keploy/refs/heads/main/pkg/core/proxy/tls/asset/setup_ca.sh
# Give execute permission to the setup_ca.sh script
RUN chmod +x setup_ca.sh
# Run the CA setup script and then run the application server
CMD ["/bin/bash", "-c", "source ./setup_ca.sh && <your app running command>"]
Note: Also add curl installation command if curl is not installed on your image
To capture test cases, Execute the following command within your application's root directory.
keploy record -c "Docker_CMD_to_run_user_container --network <network_name>" --container-name "<container_name>"
Perform API calls using tools like Hoppscotch, Postman, or cURL commands.
Keploy will capture the API calls you've conducted, generating test suites comprising test cases (KTests) and data mocks (KMocks) in YAML
format.
Running Testcases
To execute the test cases, follow these steps in the root directory of your application.
When using docker-compose to start the application, it's important to ensure that the --container-name
parameter matches the container name in your docker-compose.yaml
file.
keploy test -c "Docker_CMD_to_run_user_container --network <network_name>" --container-name "<container_name>" --delay 20
Voilà! 🧑🏻💻 We have the tests with data mocks running! 🐰🎉
You'll be able to see the test cases that ran with the results report on the console as well as locally in the testReport
directory.