API testing example with curl, bash, and jq

In this integration test example, we will hit GET: /project/:vcs-type/:username/:project (https://circleci.com/docs/api/v1-reference/#recent-builds-project), a recent build endpoint in the CircleCI API. Here is the code testing this endpoint:

#! /bin/bashGO_TEMPLATE_EXAMPLE_REPO=$(curl -X GET \    --header "Accept: application/json" \    "https://circleci.com/api/v1.1/project/github/packtci/go-template-example-with-circle-ci?circle-token=$CIRCLECI_API_TOKEN_GITHUB" | jq '.[0].author_name' | tr -d "\n")if [[ -n ${GO_TEMPLATE_EXAMPLE_REPO} ]]; then    echo "The current owner was shown"    exit 0else     echo "No owner own"    exit 1fi

Here, we test that we received an author_name attribute from the endpoint that should ...

Get Hands-On Continuous Integration and Delivery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.