Skip to content

Commit 016d4dc

Browse files
committed
chore(test): migrate to terraform test and add initial .tftest for zed
Replace Bun-based test runner with Terraform native testing. Adds script to discover and run tests across modules and updates docs/scripts to use terraform test.
1 parent c8d99cf commit 016d4dc

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

MAINTAINER.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ sudo apt install golang-go
1818

1919
Check that PRs have:
2020

21-
- [ ] All required files (`main.tf`, `main.test.ts`, `README.md`)
21+
- [ ] All required files (`main.tf`, `README.md`, at least one `.tftest.hcl`)
2222
- [ ] Proper frontmatter in README
23-
- [ ] Working tests (`bun test`)
23+
- [ ] Working tests (`terraform test`)
2424
- [ ] Formatted code (`bun run fmt`)
2525
- [ ] Avatar image for new namespaces (`avatar.png` or `avatar.svg` in `.images/`)
2626

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"fmt": "bun x prettier --write **/*.sh **/*.ts **/*.md *.md && terraform fmt -recursive -diff",
55
"fmt:ci": "bun x prettier --check **/*.sh **/*.ts **/*.md *.md && terraform fmt -check -recursive -diff",
66
"terraform-validate": "./scripts/terraform_validate.sh",
7-
"test": "bun test",
7+
"test": "./scripts/terraform_test_all.sh",
88
"update-version": "./update-version.sh"
99
},
1010
"devDependencies": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run "default_output" {
2+
command = apply
3+
4+
variables {
5+
agent_id = "foo"
6+
}
7+
8+
assert {
9+
condition = output.zed_url == "zed://ssh/default.coder"
10+
error_message = "zed_url did not match expected default URL"
11+
}
12+
}
13+
14+
run "adds_folder" {
15+
command = apply
16+
17+
variables {
18+
agent_id = "foo"
19+
folder = "/foo/bar"
20+
}
21+
22+
assert {
23+
condition = output.zed_url == "zed://ssh/default.coder/foo/bar"
24+
error_message = "zed_url did not include provided folder path"
25+
}
26+
}
27+
28+
run "adds_agent_name" {
29+
command = apply
30+
31+
variables {
32+
agent_id = "foo"
33+
agent_name = "myagent"
34+
}
35+
36+
assert {
37+
condition = output.zed_url == "zed://ssh/myagent.default.default.coder"
38+
error_message = "zed_url did not include agent_name in hostname"
39+
}
40+
}

scripts/terraform_test_all.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Find all directories that contain any .tftest.hcl files and run terraform test in each
5+
6+
run_dir() {
7+
local dir="$1"
8+
echo "==> Running terraform test in $dir"
9+
(cd "$dir" && terraform init -upgrade -input=false -no-color >/dev/null && terraform test -no-color -verbose)
10+
}
11+
12+
mapfile -t test_dirs < <(find . -type f -name "*.tftest.hcl" -print0 | xargs -0 -I{} dirname {} | sort -u)
13+
14+
if [[ ${#test_dirs[@]} -eq 0 ]]; then
15+
echo "No .tftest.hcl tests found."
16+
exit 0
17+
fi
18+
19+
status=0
20+
for d in "${test_dirs[@]}"; do
21+
if ! run_dir "$d"; then
22+
status=1
23+
fi
24+
done
25+
26+
exit $status

0 commit comments

Comments
 (0)