Skip to content

Commit 1579f43

Browse files
committed
Add comprehensive unit tests and CI workflow
Added unit tests for config, JMAP, similarity, and server packages to ensure full test coverage. Updated documentation in CLAUDE.md and README.md to describe test and coverage commands. Introduced a GitHub Actions workflow for automated test execution and coverage reporting.
1 parent 5937593 commit 1579f43

8 files changed

Lines changed: 2993 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Test Suite
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
checks: write
10+
pull-requests: write
11+
12+
jobs:
13+
test:
14+
name: Run Tests
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '1.21'
25+
cache: true
26+
27+
- name: Download dependencies
28+
run: go mod download
29+
30+
- name: Run tests with coverage
31+
run: |
32+
go test ./... -v -race -coverprofile=coverage.out -covermode=atomic -json > test-results.json || true
33+
34+
- name: Generate coverage report
35+
run: |
36+
echo "## Test Coverage Report" >> $GITHUB_STEP_SUMMARY
37+
echo "" >> $GITHUB_STEP_SUMMARY
38+
go tool cover -func=coverage.out | tail -n 1 | awk '{print "**Total Coverage: " $3 "**"}' >> $GITHUB_STEP_SUMMARY
39+
echo "" >> $GITHUB_STEP_SUMMARY
40+
echo "### Coverage by Package" >> $GITHUB_STEP_SUMMARY
41+
echo "" >> $GITHUB_STEP_SUMMARY
42+
echo "| Package | Coverage |" >> $GITHUB_STEP_SUMMARY
43+
echo "|---------|----------|" >> $GITHUB_STEP_SUMMARY
44+
go tool cover -func=coverage.out | grep -v "total:" | awk '{print "| " $1 " | " $3 " |"}' | sort -u >> $GITHUB_STEP_SUMMARY
45+
46+
- name: Test Report
47+
uses: dorny/test-reporter@v1
48+
if: always()
49+
with:
50+
name: Go Test Results
51+
path: test-results.json
52+
reporter: 'go-test'
53+
fail-on-error: true
54+
fail-on-empty: true
55+
56+
- name: Upload coverage to GitHub
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: coverage-report
60+
path: coverage.out
61+
62+
- name: Check test results
63+
run: |
64+
if grep -q '"Action":"fail"' test-results.json; then
65+
echo "Some tests failed"
66+
exit 1
67+
else
68+
echo "All tests passed"
69+
fi

CLAUDE.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,25 @@ mock_mode: true # Enable mock mode
249249
# Quick start with mock data (no Fastmail account required)
250250
go run main.go -config config-mock.yaml.example
251251

252-
# Run all tests (when implemented)
252+
# Run all tests
253253
go test ./...
254254

255+
# Run tests with verbose output
256+
go test ./... -v
257+
255258
# Run with race detection
256259
go test -race ./...
257260

261+
# Run tests with coverage
262+
go test ./... -cover
263+
264+
# Generate coverage report
265+
go test ./... -coverprofile=coverage.out
266+
go tool cover -html=coverage.out
267+
268+
# Run benchmarks
269+
go test ./... -bench=.
270+
258271
# Lint the code (requires golangci-lint)
259272
golangci-lint run
260273
```
@@ -363,7 +376,21 @@ log.SetFlags(log.LstdFlags | log.Lshortfile)
363376
3. **Interface Design:** Clean separation of concerns
364377
4. **Memory Management:** Efficient string operations and minimal allocations
365378
5. **Concurrency Safety:** Thread-safe operations where needed
366-
6. **Testing Ready:** Structured for unit test implementation
379+
6. **Comprehensive Testing:** Full unit test coverage with table-driven tests
380+
381+
### Test Coverage
382+
The project includes comprehensive unit tests for all packages:
383+
- **Config Package:** Configuration loading, validation, and error handling
384+
- **JMAP Package:** Data parsing, mock client functionality, and helper functions
385+
- **Similarity Package:** Fuzzy matching algorithms, Levenshtein distance, email similarity
386+
- **Server Package:** HTTP handlers, API endpoints, and request/response handling
387+
388+
Tests follow Go best practices:
389+
- Table-driven test design for multiple scenarios
390+
- Clear test naming and organization
391+
- Use of test helpers and fixtures
392+
- Mock clients for external dependencies
393+
- Benchmark tests for performance-critical functions
367394

368395
### Code Style
369396
- **Naming:** Clear, descriptive variable and function names

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ mailboxzero/
169169
└── static/ # CSS and JavaScript files
170170
```
171171

172+
### Running Tests
173+
174+
The project includes comprehensive unit tests for all packages:
175+
176+
```bash
177+
# Run all tests
178+
go test ./...
179+
180+
# Run tests with verbose output
181+
go test ./... -v
182+
183+
# Run tests with coverage
184+
go test ./... -cover
185+
186+
# Generate coverage report
187+
go test ./... -coverprofile=coverage.out
188+
go tool cover -html=coverage.out
189+
```
190+
172191
## License
173192

174193
This project is provided as-is for educational and personal use.

0 commit comments

Comments
 (0)