test: add comprehensive Go test suite with ~75% coverage
New test files: - config/config_test.go (100% coverage) - constants/constants_test.go (100% coverage) - httputil/response_test.go (100% coverage) - validation/rules_test.go (91.9% coverage) - middleware/logger_test.go, security_test.go, security_logger_test.go - handlers/errors_test.go Updated documentation: - doc/27-GO-TESTING.md: Complete testing guide - doc/00-GO-DOCUMENTATION-INDEX.md: Added testing section - doc/01-ARCHITECTURE.md: Updated package structure - doc/DECISIONS.md: Added ADR-004 caching decision - PROJECT-MEMORY.md: Added Go testing section
This commit is contained in:
+13
-6
@@ -17,12 +17,17 @@ This CV website is built following Go best practices with a focus on:
|
||||
cv/
|
||||
├── main.go # Application entry point
|
||||
└── internal/ # Private packages (cannot be imported by other projects)
|
||||
├── cache/ # Application-level data caching
|
||||
├── config/ # Configuration management
|
||||
├── constants/ # Project-wide constants
|
||||
├── email/ # Email service (SMTP)
|
||||
├── fileutil/ # File path utilities
|
||||
├── handlers/ # HTTP request handlers
|
||||
├── httputil/ # HTTP response helpers
|
||||
├── middleware/ # HTTP middleware (security, logging, rate limiting)
|
||||
├── models/ # Data models and business logic
|
||||
├── models/ # Data models (cv, ui)
|
||||
├── pdf/ # PDF generation service
|
||||
├── services/ # Business services (email, etc.)
|
||||
├── routes/ # Route configuration
|
||||
├── templates/ # Template management
|
||||
└── validation/ # Input validation utilities
|
||||
```
|
||||
@@ -41,13 +46,15 @@ Handlers and services receive their dependencies through constructors:
|
||||
// ✅ Good: Dependencies injected
|
||||
type CVHandler struct {
|
||||
templates *templates.Manager
|
||||
emailService *services.EmailService
|
||||
emailService *email.Service
|
||||
dataCache *cache.DataCache
|
||||
}
|
||||
|
||||
func NewCVHandler(tmpl *templates.Manager, addr string, email *services.EmailService) *CVHandler {
|
||||
func NewCVHandler(tmpl *templates.Manager, addr string, emailSvc *email.Service, dc *cache.DataCache) *CVHandler {
|
||||
return &CVHandler{
|
||||
templates: tmpl,
|
||||
emailService: email, // Can be nil for graceful degradation
|
||||
emailService: emailSvc, // Can be nil for graceful degradation
|
||||
dataCache: dc, // Startup-loaded data cache
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +177,7 @@ func (h *CVHandler) HandleContact(w http.ResponseWriter, r *http.Request)
|
||||
- Consistent error handling
|
||||
- HTMX-aware responses
|
||||
|
||||
### Email Service (`internal/services`)
|
||||
### Email Service (`internal/email`)
|
||||
|
||||
**Pattern**: Service layer with dependency injection and interface-based design
|
||||
|
||||
|
||||
Reference in New Issue
Block a user