Skip to main content

cURL

Testkube is able to run cURL commands as tests.

Default command for this executor: curl Default arguments for this executor command: -is

Abstraction over cURL

Testkube executor provides an abstraction over cURL that allow you to create JSON-based cURL test files. They allow you to combine a cURL command with expected results:

  • expected_status allows you to assert that a specific status code is returned.
  • expected_body allows you to validate the body of the response.

Below is an example of how to format the test:

{
"command": [
"curl",
"https://jsonplaceholder.typicode.com/todos/1",
"-H",
"'Accept: application/json'"
],
"expected_status": "200"
}

You can also find this test in the Testkube repository: https://github.com/kubeshop/testkube/blob/main/test/curl/curl.json.

Example Test

In this example we will use the following cURL test: https://github.com/kubeshop/testkube/blob/main/test/curl/executor-tests/curl-smoke-test.json.

{
"command": [
"curl",
"https://jsonplaceholder.typicode.com/todos/1"
],
"expected_status": "200"
}

Creating and Running a Test

If you prefer to use the Dashboard, just go to Tests, and click the Add a new test button. Fill in the Test Name, choose the Test Type (curl/test), and then choose Test Source.

File

For a File source, the test file is uploaded directly.

curl test - creation dialog - file

Git File

For a Git file, you need to fill in the repository details - Git repository URI (in this case https://github.com/kubeshop/testkube.git), branch (main), and the path to the cURL test in your repository (test/curl/executor-tests/curl-smoke-test.json). In this example, the repository is public, but in the case of private ones, you would need to additionally fill in the Git credentials.

curl test - creation dialog - git file

When the Test CRD is saved to the yaml file, it can then be applied directly with kubectl apply -f SOME_FILE_NAME.yaml.