Skip to content

Coding Conventions

This guide outlines the coding and syntax conventions used for writing Condor tests and resource definitions. Following these conventions helps maintain consistency and readability throughout the collection files.

Formatting

  • Alignment of Equal Signs:
    • Equal signs (=) should align vertically within the same block where practical. This aids in readability and makes it easier to compare similar lines.

Example:

http "get_user" {
method = "GET"
path = "/user"
headers {
Accept = "application/json"
Content-Type = "application/json"
}
}
  • Spacing:
    • Use two spaces for indentation.
    • Leave one blank line between blocks to visually separate them.

Example:

test "create_post_test" {
request = http.create_post
assert {
condition = resp.status == 201
}
}
  • Line Length:
    • Keep lines reasonably short. If a line becomes too long, consider splitting it across multiple lines for clarity.

Example:

http "complex_query" {
method = "GET"
path = "/search"
query {
q = "example search"
limit = "10"
}
}

Naming Conventions

  • Block Names:
    • Use snake_case for block names, such as get_user, create_post, and find_users_by_status.
    • The block names should be descriptive and reflect their purpose.

Examples:

http "find_users_by_status" {
method = "GET"
path = "/users"
query {
status = "active"
}
}
test "verify_active_users" {
request = http.find_users_by_status
assert {
condition = resp.status == 200
}
}
  • Variable Names:
    • Use snake_case for variables as well. This ensures consistency across the codebase.
    • Avoid abbreviations where clarity might be sacrificed.

Example:

http "find_users_by_status" {
method = "GET"
path = "/users"
query {
status = var.user_status
}
}

Best Practices

  • Readability Over Brevity:

    • Always prioritize clear, readable code over shorter, more cryptic expressions.
  • Consistency:

    • Apply the same conventions throughout your collection files. Inconsistent formatting can make maintenance and troubleshooting more difficult.
  • Documentation:

    • Use comments to explain non-obvious configurations or assertions. While Condor files are intended to be declarative, a few well-placed comments can help future developers understand the purpose behind certain blocks.

Following these conventions ensures that Condor configurations are not only functional but also maintainable, readable, and consistent.