Files
nova-platform/tests/test_terraform_adapter.py
CIAgent 2443909362 docs(milestone): complete v1.0-nova-platform (release v0.1.6)
---ci---
project: nova-platform
milestone: v1.0
status: complete
requirements:
  covered: [REQ-01,REQ-02,REQ-03,REQ-04,REQ-05,REQ-06,REQ-07,REQ-08,REQ-09,REQ-10,REQ-11,REQ-12,REQ-13,REQ-14,REQ-15,REQ-16,REQ-17,REQ-18,REQ-19,REQ-20,REQ-21,REQ-22,REQ-23,REQ-24,REQ-25,REQ-26,REQ-27,REQ-28,REQ-29,REQ-30,REQ-31,REQ-32,REQ-33,REQ-34,REQ-35,REQ-36,REQ-37,REQ-38]
  partial: []
---/ci---

v1.0 milestone complete: simplified infrastructure-delivery platform
derived from Nova (acdl). 6 phases (P0-P5 + P6 final). 38 REQ-IDs.
38 decisions (D-001..D-038). 76 tests pass. Engine boundary holds.
Happy paths green (check-only + CI). 13 L1 + 2 L2 modules. 5 terraform
roots. Shell reproducibility. Zero OOS files.

Tags: v0.1.0 (P0) → v0.1.1..v0.1.5 (P1..P5) → v0.1.6 (P6 = milestone
release on v0.1 patch line).
2026-08-25 02:18:35 +00:00

95 lines
3.0 KiB
Python

"""Tests for adapters/terraform/adapter.py — REQ-25."""
import sys
from pathlib import Path
import pytest
from adapters.terraform.adapter import adapt, _tf_value
def _stack(resources):
return {
"contract_id": "test", "contract_name": "Test", "environment": "dev",
"resources": resources,
}
class TestAdapt:
def test_single_resource(self, repo_root):
stack = _stack([
{"module": "s3", "version": "1.0.0",
"inputs": {"bucket_name": "test-bucket", "enabled": True}},
])
hcl = adapt(stack, repo_root)
assert 'module "s3" {' in hcl
assert 'source = ' in hcl
assert 'bucket_name = "test-bucket"' in hcl
assert "enabled = true" in hcl
def test_multi_resource(self, repo_root):
stack = _stack([
{"module": "s3", "version": "1.0.0",
"inputs": {"bucket_name": "b1", "enabled": True}},
{"module": "vpc", "version": "1.0.0",
"inputs": {"cidr": "10.0.0.0/16"}},
])
hcl = adapt(stack, repo_root)
assert 'module "s3" {' in hcl
assert 'module "vpc" {' in hcl
def test_input_passthrough_scalar(self, repo_root):
stack = _stack([
{"module": "s3", "version": "1.0.0",
"inputs": {"bucket_name": "my-bucket", "region": "us-east-1"}},
])
hcl = adapt(stack, repo_root)
assert 'bucket_name = "my-bucket"' in hcl
assert "us-east-1" not in hcl.split("inputs")[0] if "inputs" in hcl else True
# region is skipped (provider-level)
def test_input_passthrough_list(self, repo_root):
stack = _stack([
{"module": "vpc", "version": "1.0.0",
"inputs": {"azs": ["us-east-1a", "us-east-1b"]}},
])
hcl = adapt(stack, repo_root)
assert 'azs = ["us-east-1a", "us-east-1b"]' in hcl
def test_input_passthrough_number(self, repo_root):
stack = _stack([
{"module": "vpc", "version": "1.0.0",
"inputs": {"desired_count": 3}},
])
hcl = adapt(stack, repo_root)
assert "desired_count = 3" in hcl
def test_hcl_validity_balanced_braces(self, repo_root):
stack = _stack([
{"module": "s3", "version": "1.0.0",
"inputs": {"bucket_name": "b", "enabled": True}},
])
hcl = adapt(stack, repo_root)
assert hcl.count("{") == hcl.count("}")
def test_unknown_module_raises(self, repo_root):
stack = _stack([
{"module": "nonexistent", "version": "1.0.0", "inputs": {}},
])
with pytest.raises(ValueError, match="no terraform_dir"):
adapt(stack, repo_root)
class TestTfValue:
def test_bool(self):
assert _tf_value(True) == "true"
assert _tf_value(False) == "false"
def test_int(self):
assert _tf_value(42) == "42"
def test_string(self):
assert _tf_value("hello") == '"hello"'
def test_list(self):
assert _tf_value(["a", "b"]) == '["a", "b"]'