Syntax
Condor uses a declarative, HCL-like syntax for defining resources, tests, and configurations. This guide provides a complete reference to the syntax and supported constructs.
Resource Definitions
Resources define the endpoints, requests, or actions to be tested. They are reusable components referenced in tests.
Example: HTTP Resource
http "get_user" { method = "get" path = "/user/${var.id}"
headers { Authorization = "Bearer ${var.auth_token}" }
query { expand = "details" }}
Attributes
method
: (Required) The HTTP method (get
,post
,put
,delete
, etc.).path
: (Required) The endpoint path, supporting placeholders (e.g.,{id}
).headers
: (Optional) Key-value pairs for HTTP headers.query
: (Optional) Key-value pairs for query parameters.body
: (Optional) Request body, often encoded as JSON.
Test Definitions
Tests validate the behavior of resources by executing requests and asserting conditions.
Example: Basic Test
test "get_user_test" { name = "Fetch user details" request = http.get_user
variables { auth_token = "your-auth-token" id = "12345" }
assert { condition = resp.status == 200 error = "Expected status 200, got ${resp.status}." }
assert { condition = json::decode(resp.body).name != "" error = "Expected a non-empty name in the response." }}
Blocks and Attributes
name
: (Optional) Descriptive name for the test.request
: (Required) Reference to a defined resource.variables
: (Optional) Key-value pairs for dynamic inputs.assert
: (Required) Validates the response with conditions and optional error messages.
Assertions
condition
: (Required) Logical expression that must evaluate totrue
.error
: (Optional) Error message displayed if the condition fails.
Environment Configurations
Environment files store configurations such as base_url
and other variables.
Example: Environment File
base_url = "https://api.dev.example.com"
variables { default_auth_token = "dev-auth-token"}
Error Handling
When an assertion fails, Condor provides detailed error messages, including:
- Failed condition.
- Expected and actual values.
- File and line number.
Example:
Error: Expected status 200, got 404.
on ./tests/get_user_test.condor line 12, in test "get_user_test": 11: assert { 12: condition = resp.status == 200
with resp.status as 404.
This syntax reference provides the foundation for writing robust Condor tests. Explore other sections for advanced usage and best practices.