Skip to content

Commit ccdca6d

Browse files
chore: update CONTRIBUTION docs to explain both tests, and update CI for both tests (#384)
Closes #383 ## Description - Update CONTRIBUTION.md to elaborate on ts and tf tests - Add ./scripts/terraform_test_all.sh to CI for ts tests <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [ ] Bug fix - [ ] Feature/enhancement - [X] Documentation - [X] Other ## Testing & Validation - [ ] Tests pass (`bun test`) - [X] Code formatted (`bun run fmt`) - [ ] Changes tested locally --------- Co-authored-by: Atif Ali <[email protected]>
1 parent ce039f6 commit ccdca6d

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
run: bun install
2929
- name: Run TypeScript tests
3030
run: bun test
31+
- name: Run Terraform tests
32+
run: ./scripts/terraform_test_all.sh
3133
- name: Run Terraform Validate
3234
run: bun terraform-validate
3335
validate-style:

CONTRIBUTING.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,23 @@ This script generates:
124124
- Accurate description and usage examples
125125
- Correct icon path (usually `../../../../.icons/your-icon.svg`)
126126
- Proper tags that describe your module
127-
3. **Create at least one `.tftest.hcl`** to test your module with `terraform test`
127+
3. **Create tests for your module:**
128+
- **Terraform tests**: Create a `*.tftest.hcl` file and test with `terraform test`
129+
- **TypeScript tests**: Create `main.test.ts` file if your module runs scripts or has business logic that Terraform tests can't cover
128130
4. **Add any scripts** or additional files your module needs
129131

130132
### 4. Test and Submit
131133

132134
```bash
133-
# Test your module (from the module directory)
135+
# Test your module
136+
cd registry/[namespace]/modules/[module-name]
137+
138+
# Required: Test Terraform functionality
134139
terraform init -upgrade
135140
terraform test -verbose
136141

137-
# Or run all tests in the repo
138-
./scripts/terraform_test_all.sh
142+
# Optional: Test TypeScript files if you have main.test.ts
143+
bun test main.test.ts
139144

140145
# Format code
141146
bun run fmt
@@ -343,8 +348,8 @@ coder templates push test-[template-name] -d .
343348
terraform init -upgrade
344349
terraform test -verbose
345350

346-
# Test all modules
347-
./scripts/terraform_test_all.sh
351+
# Optional: If you have TypeScript tests
352+
bun test main.test.ts
348353
```
349354

350355
### 3. Maintain Backward Compatibility
@@ -393,7 +398,9 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template=
393398
### Every Module Must Have
394399

395400
- `main.tf` - Terraform code
396-
- One or more `.tftest.hcl` files - Working tests with `terraform test`
401+
- **Tests**:
402+
- `*.tftest.hcl` files with `terraform test` (to test terraform specific logic)
403+
- `main.test.ts` file with `bun test` (to test business logic, i.e., `coder_script` to install a package.)
397404
- `README.md` - Documentation with frontmatter
398405

399406
### Every Template Must Have
@@ -493,7 +500,7 @@ When reporting bugs, include:
493500
2. **No tests** or broken tests
494501
3. **Hardcoded values** instead of variables
495502
4. **Breaking changes** without defaults
496-
5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`) before submitting
503+
5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`, and `bun test main.test.ts` if applicable) before submitting
497504

498505
## For Maintainers
499506

examples/modules/MODULE_NAME.tftest.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ run "app_url_uses_port" {
1515
}
1616

1717
assert {
18-
condition = resource.coder_app.MODULE_NAME.url == "http://localhost:19999"
19-
error_message = "Expected MODULE_NAME app URL to include configured port"
18+
condition = resource.coder_app.module_name.url == "http://localhost:19999"
19+
error_message = "Expected module-name app URL to include configured port"
2020
}
2121
}

examples/modules/main.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ variable "agent_id" {
3535

3636
variable "log_path" {
3737
type = string
38-
description = "The path to log MODULE_NAME to."
39-
default = "/tmp/MODULE_NAME.log"
38+
description = "The path to the module log file."
39+
default = "/tmp/module_name.log"
4040
}
4141

4242
variable "port" {
4343
type = number
44-
description = "The port to run MODULE_NAME on."
44+
description = "The port to run the application on."
4545
default = 19999
4646
}
4747

@@ -59,9 +59,9 @@ variable "order" {
5959
# Add other variables here
6060

6161

62-
resource "coder_script" "MODULE_NAME" {
62+
resource "coder_script" "module_name" {
6363
agent_id = var.agent_id
64-
display_name = "MODULE_NAME"
64+
display_name = "Module Name"
6565
icon = local.icon_url
6666
script = templatefile("${path.module}/run.sh", {
6767
LOG_PATH : var.log_path,
@@ -70,10 +70,10 @@ resource "coder_script" "MODULE_NAME" {
7070
run_on_stop = false
7171
}
7272

73-
resource "coder_app" "MODULE_NAME" {
73+
resource "coder_app" "module_name" {
7474
agent_id = var.agent_id
75-
slug = "MODULE_NAME"
76-
display_name = "MODULE_NAME"
75+
slug = "module-name"
76+
display_name = "Module Name"
7777
url = "http://localhost:${var.port}"
7878
icon = local.icon_url
7979
subdomain = false
@@ -88,10 +88,10 @@ resource "coder_app" "MODULE_NAME" {
8888
}
8989
}
9090

91-
data "coder_parameter" "MODULE_NAME" {
92-
type = "list(string)"
93-
name = "MODULE_NAME"
94-
display_name = "MODULE_NAME"
91+
data "coder_parameter" "module_name" {
92+
type = "string"
93+
name = "module_name"
94+
display_name = "Module Name"
9595
icon = local.icon_url
9696
mutable = var.mutable
9797
default = local.options["Option 1"]["value"]

0 commit comments

Comments
 (0)