Skip to content

Commit 1b7628c

Browse files
committed
fix: update tests/README.md to use aqua
1 parent 7dcd93b commit 1b7628c

3 files changed

Lines changed: 23 additions & 102 deletions

File tree

.github/workflows/test.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@ jobs:
1919
- name: Check out Git repository
2020
uses: actions/checkout@v4
2121

22-
- name: Install BATS
23-
run: |
24-
sudo apt-get update
25-
sudo apt-get install -y bats
26-
27-
- name: Install Task
28-
uses: arduino/setup-task@v2
22+
- name: Install tools via aqua
23+
uses: aquaproj/aqua-installer@v3.0.1
2924
with:
30-
version: 3.x
31-
repo-token: ${{ secrets.GITHUB_TOKEN }}
25+
aqua_version: v2.55.0
3226

3327
- name: Run BATS tests
3428
run: bats tests/

aqua.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ packages:
99
tags: [cursor]
1010
- name: cli/cli@v2.83.0
1111
tags: [gh]
12+
- name: bats-core/bats-core@v1.13.0
13+
tags: [cicd]

tests/README.md

Lines changed: 18 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,49 @@
11
# Taskit Test Suite
22

3-
## Purpose
3+
BATS test suite for Taskit. Tests validate Task commands using dry-run mode (`task -n`).
44

5-
This directory contains the BATS (Bash Automated Testing System) test suite for Taskit. Tests validate Task command functionality using dry-run mode, ensuring reliability without requiring actual tool installations.
6-
7-
## Prerequisites
8-
9-
Install BATS:
5+
## Setup
106

117
```bash
12-
# macOS
13-
brew install bats-core
14-
15-
# Debian/Ubuntu
16-
apt-get install bats
17-
18-
# Manual installation
19-
git clone https://github.com/bats-core/bats-core.git
20-
cd bats-core
21-
./install.sh /usr/local
8+
aqua install # Installs BATS and Task
229
```
2310

2411
## Running Tests
2512

26-
### Local Development
27-
2813
```bash
29-
# Run all tests
30-
bats tests/
31-
32-
# Run specific test file
33-
bats tests/terraform_plan.bats
34-
35-
# Run tests by tag
36-
bats --filter-tags basic tests/
37-
bats --filter-tags precondition tests/
14+
bats tests/ # Run all
15+
bats tests/terraform_plan.bats # Run specific file
16+
bats --filter-tags precondition tests/ # Run by tag
3817
```
3918

40-
### Continuous Integration
41-
42-
Tests run automatically on:
43-
44-
- **Pull Requests**: All PRs trigger the test suite
45-
- **Main Branch**: Tests run on every push to main
46-
47-
The GitHub Actions workflow (`.github/workflows/test.yaml`) handles:
48-
49-
1. BATS and Task installation
50-
2. Test execution across the `tests/` directory
51-
3. Result artifacts upload (30-day retention)
52-
53-
View results in the GitHub Actions tab or PR checks section.
19+
CI runs automatically on PRs and main branch pushes via `.github/workflows/test.yaml`.
5420

5521
## Writing Tests
5622

57-
Tests leverage Task's dry-run mode (`task -v -n`) to verify command construction without execution:
23+
Tests use Task's dry-run mode to verify command construction:
5824

5925
```bash
6026
@test "terraform:plan validates environment argument" {
61-
# Arrange: Create test fixture
62-
touch "tfvars/test-env.tfvars"
63-
64-
# Act: Execute task in dry-run mode
27+
touch "tfvars/test-env.tfvars" # Setup fixture
6528
run task -v -n terraform:plan -- test-env
66-
67-
# Assert: Verify output
6829
[ "$status" -eq 0 ]
69-
[[ "$output" =~ "expected text" ]]
30+
[[ "$output" =~ "tofu plan -var-file ./tfvars/test-env.tfvars" ]]
7031
}
7132
```
7233

73-
### Test Structure
74-
75-
- `setup()`: Pre-test fixture creation and environment setup
76-
- `@test "description"`: Individual test case
77-
- `teardown()`: Post-test cleanup
78-
79-
### Test Tags
34+
Key helpers: `setup()`, `teardown()`, `run`, `$status`, `$output`
8035

81-
Use tags for selective test execution:
36+
## Quick Reference
8237

83-
- `terraform`: Terraform-related functionality
84-
- `plan`: Plan command behavior
85-
- `basic`: Core functionality
86-
- `args`: Argument handling
87-
- `precondition`: Validation logic
88-
- `config`: Configuration management
89-
- `error`: Error handling
90-
91-
## Best Practices
92-
93-
1. **Dry-run Testing**: Use `task -v -n` to test without requiring actual tool installations
94-
2. **Debug Output**: Include `echo "Output: $output" >&3` for troubleshooting failed tests
95-
3. **Fixture Management**: Create temporary files in `setup()`, clean up in `teardown()`
96-
4. **Assertions**: Use `[ ]` for exit codes, `[[ =~ ]]` for pattern matching
38+
**Debug failed tests:** `echo "Output: $output" >&3`
39+
**Test pattern:** `task -v -n <task> -- <args>`
40+
**Assertions:** `[ ]` for exit codes, `[[ =~ ]]` for regex matching
41+
**Tags:** terraform, plan, basic, args, precondition, config, error
42+
**Fixtures:** Create in `setup()`, clean in `teardown()`
9743

9844
## Troubleshooting
9945

100-
**Tests fail in CI but pass locally:**
101-
102-
- Ensure proper cleanup in `teardown()`
103-
- Verify tests don't depend on local environment state
104-
- Confirm all required files are committed
105-
106-
**Workflow doesn't run:**
107-
108-
- Verify `.github/workflows/test.yaml` exists
109-
- Check GitHub Actions are enabled for the repository
110-
- Review branch protection rules
111-
112-
## Workflow Permissions
113-
114-
The CI workflow uses minimal permissions:
115-
116-
- `actions: read` - Access workflow logs
117-
- `checks: write` - Report check results
118-
- `contents: read` - Read repository
119-
- `pull-requests: read` - Access PR information
120-
121-
No secrets or credentials required for test execution.
46+
**CI/local mismatch:** Check `teardown()` cleanup and committed test fixtures.
12247

12348
## Resources
12449

0 commit comments

Comments
 (0)