Skip to main content
ubx test discovers and runs *.test.iac files. No cloud resources, no credentials required.

Usage

ubx test [path] [flags]

Examples

ubx test
ubx test tests/s3.test.iac
ubx test tests/
ubx test --verbose

Flags

FlagDescription
--verboseShow assertion details for passing tests

Test File Syntax

Plan Assertion Tests

test "bucket_created" {
  assert {
    resource   = "aws_s3_bucket_v2.assets"
    action     = "create"
    attributes = { bucket = "my-assets" }
  }
}

test "bucket_name_uses_env" {
  inputs = { env = "staging" }

  assert {
    resource   = "aws_s3_bucket_v2.assets"
    action     = "create"
    attributes = { bucket = "staging-assets" }
  }
}

Error Assertion Tests

test "undefined_ref_caught" {
  source       = "unit \"aws_s3_bucket_v2\" \"assets\" { bucket = ~unit.missing.thing.attr }"
  expect_error = "missing"
}

test "required_field_missing" {
  source = """
    unit "aws_rds_instance" "db" {
      username = "admin"
    }
  """
  expect_error = "required attribute \"engine\" is missing"
}

Test Block Fields

FieldDescription
inputsMap of input values ({ env = "staging" })
assertOne or more assertion sub-blocks
sourceInline .iac source (overrides project files)
expect_errorExpected error substring

Assert Fields

FieldDescription
resource"type.name" matching the unit block
action"create", "update", "delete", "no-change"
attributesMap of expected key-value pairs

Output

=== RUN   bucket_name_uses_env
--- PASS: bucket_name_uses_env (0.00s)

Tests: 1 passed, 0 failed, 1 total
Failing test:
=== RUN   wrong_bucket_name
--- FAIL: wrong_bucket_name (0.00s)
    attribute "bucket" on resource "aws_s3_bucket_v2.assets":
        expected: "wrong-name"
        got:      "my-assets"

Tests: 0 passed, 1 failed, 1 total

Exit Codes

CodeMeaning
0All tests pass
1One or more tests fail