Skip to main content

Postman

Overview

This document guides you through the steps required to run Postman tests using Signadot's Continuous Testing (CT) feature.

Running Tests as a Signadot Job

Running a test as a Signadot Job provides context awareness, meaning that if the sandbox referenced in the test is terminated, closed, or in any other failed state, the test will automatically fail. This makes the tests more reliable.

Create Job Runner Group

To start with Signadot CT, we need to create a Job Runner Group

your_project/.signadot/testing/postman-runner.yaml
name: postman
spec:
cluster: "@{cluster}"
labels:
env: "@{env}"
# We will be using Postman's Newman collection runner to run the tests. However,
# since its image doesn't contain git (which we will need), we'll be using
# the node image instead.
image: node:latest
jobTimeout: 30m
scaling:
manual:
desiredPods: 1

Create Job Specification

your_project/.signadot/testing/postman-integration-job.yaml
spec:
namePrefix: integration-api
runnerGroup: postman
script: |
#!/bin/bash
set -e

npm install -g newman
# Clone the git repo
echo "Cloning repo"
git clone --single-branch -b "@{branch}" \
https://github.com/<org>/<repo>.git

# Run all postman tests
cd <repo>

set +e
newman run your_postman_collection.json \
-r cli,json
E2E_EXIT_CODE=$?
set -e

# Compress the `newman` directory so that it can be uploaded as a single artifact.
tar czf postman-report.tar.gz newman

exit $E2E_EXIT_CODE

uploadArtifact:
- path: your_project/postman-report.tar.gz
tip

The code block between set +e and set -e allows to continue the execution of the Job while saving the status of the execution of the test for proper test status handling.

Set Up Routing Context

There are some use cases where we need to run tests against specific Sandboxes, so we need to rely on some routing context. We could use the preview url, but there are some situations where it would be better to use simply the routing key. For the postman integration, we have to make use of variables.

your_project/.signadot/testing/postman-integration-job.yaml
spec:
namePrefix: integration-api
runnerGroup: postman
script: |
#!/bin/bash
set -e

npm install -g newman
# Clone the git repo
echo "Cloning repo"
git clone --single-branch -b "@{branch}" \
https://github.com/<org>/<repo>.git

# Run all postman tests
cd <repo>

set +e
newman run your_postman_collection.json \
-r cli,json \
--env-var routing_key=$SIGNADOT_ROUTING_KEY # This is supposing you have set the {{routing_key}} in postman as the setting
E2E_EXIT_CODE=$?
set -e

tar czf postman-report.tar.gz newman

exit $E2E_EXIT_CODE

uploadArtifact:
- path: your_project/postman-report.tar.gz