docs: add comprehensive Go testing guide
- Add detailed testing instructions in TESTING.md - Include quick start commands for all test scenarios - Document new notes and highlights test coverage - Add coverage analysis and reporting commands - Include troubleshooting guide for common issues - Add test flag reference and workflow recommendations - Document test categories and what they verify
This commit is contained in:
-76
@@ -1,76 +0,0 @@
|
|||||||
# Test Suite Documentation
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
This comprehensive test suite covers the Bookmann multi-library system with authentication, authorization, and security testing.
|
|
||||||
|
|
||||||
## Test Structure
|
|
||||||
|
|
||||||
- **Authentication Tests** (`auth_test.go`)
|
|
||||||
- JWT middleware validation
|
|
||||||
- Missing/invalid token handling
|
|
||||||
- User role extraction
|
|
||||||
|
|
||||||
- **Library Management Tests** (`library_test.go`)
|
|
||||||
- Library creation with authorization checks
|
|
||||||
- Library types endpoint testing
|
|
||||||
- User library visibility control
|
|
||||||
- Media items browsing with library filtering
|
|
||||||
|
|
||||||
- **Security Tests** (scattered across files)
|
|
||||||
- JSON validation
|
|
||||||
- Error handling
|
|
||||||
- Authorization bypass attempts
|
|
||||||
|
|
||||||
## Running Tests
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Run all tests from project root
|
|
||||||
cd /home/nymusicman/Code/bookmann && go test ./cmd/server/tests/...
|
|
||||||
|
|
||||||
# Run specific test
|
|
||||||
go test ./cmd/server/tests/... -run TestAuthMiddleware
|
|
||||||
|
|
||||||
# Run with verbose output
|
|
||||||
go test -v ./cmd/server/tests/...
|
|
||||||
```
|
|
||||||
|
|
||||||
## Current Issues
|
|
||||||
|
|
||||||
The test suite is experiencing Go environment setup issues related to:
|
|
||||||
1. Database querier interface conflicts with old user ebook folder methods
|
|
||||||
2. Import resolution problems in some test files
|
|
||||||
|
|
||||||
## Test Coverage Areas
|
|
||||||
|
|
||||||
- ✅ JWT Authentication & Authorization
|
|
||||||
- ✅ Library Management & CRUD Operations
|
|
||||||
- ✅ User Visibility Control
|
|
||||||
- ✅ JSON Validation & Error Handling
|
|
||||||
- ⚠️ Test Environment Setup (being resolved)
|
|
||||||
|
|
||||||
## Docker Integration
|
|
||||||
|
|
||||||
Tests are designed to work with Docker build environment:
|
|
||||||
```bash
|
|
||||||
docker-compose build # Build application
|
|
||||||
docker-compose up -d # Start application
|
|
||||||
# Tests can run against the running container
|
|
||||||
```
|
|
||||||
|
|
||||||
## Security Test Scenarios
|
|
||||||
|
|
||||||
- Valid and invalid JWT tokens
|
|
||||||
- Admin vs user role verification
|
|
||||||
- JSON injection attempts
|
|
||||||
- Authorization header manipulation
|
|
||||||
- SQL injection prevention
|
|
||||||
- Cross-site scripting attempts
|
|
||||||
|
|
||||||
## Best Practices
|
|
||||||
|
|
||||||
- Uses `httptest.ResponseRecorder` for isolated HTTP testing
|
|
||||||
- Follows Go testing conventions
|
|
||||||
- Comprehensive input validation
|
|
||||||
- Proper HTTP status code testing
|
|
||||||
- Role-based access control verification
|
|
||||||
Reference in New Issue
Block a user