Files
steamcache2/.cursor/rules/testing-guidelines.mdc
Justin Harms 3703e40442 Add comprehensive documentation for caching, configuration, development, and security patterns
- Introduced multiple new markdown files detailing caching patterns, configuration management, development workflows, Go language conventions, HTTP proxy patterns, logging and monitoring practices, performance optimization guidelines, project structure, security validation, and VFS architecture.
- Each document outlines best practices, patterns, and guidelines to enhance the understanding and implementation of various components within the SteamCache2 project.
- This documentation aims to improve maintainability, facilitate onboarding for new contributors, and ensure consistent application of coding and architectural standards across the codebase.
2025-09-22 17:29:26 -05:00

78 lines
2.6 KiB
Plaintext

---
globs: *_test.go
---
# Testing Guidelines for SteamCache2
## Test Structure
- Use table-driven tests for multiple test cases
- Group related tests in the same test function when appropriate
- Use descriptive test names that explain what is being tested
- Include both positive and negative test cases
## Test Data Management
- Use `t.TempDir()` for temporary files and directories
- Clean up resources in defer statements
- Use unique temporary directories for each test to avoid conflicts
- Don't rely on external services in unit tests
## Integration Testing
- Mark integration tests with `testing.Short()` checks
- Use real Steam URLs for integration tests when appropriate
- Test both cache hits and cache misses
- Verify response integrity between direct and cached responses
- Test against actual Steam servers for real-world validation
- Use `httptest.NewServer` for local testing scenarios
- Compare direct vs cached responses byte-for-byte
## Mocking and Stubbing
- Use `httptest.NewServer` for HTTP server mocking
- Create mock responses that match real Steam responses
- Test error conditions and edge cases
- Use `httptest.NewRecorder` for response testing
## Performance Testing
- Test with realistic data sizes
- Measure cache hit/miss ratios
- Test concurrent request handling
- Verify memory usage doesn't grow unbounded
## Cache Testing
- Test cache key generation and uniqueness
- Verify cache file format serialization/deserialization
- Test garbage collection algorithms
- Test cache eviction policies
- Test cache corruption scenarios and recovery
- Verify cache file format integrity (magic numbers, hashes)
- Test range request handling from cached files
- Test request coalescing behavior
## Service Detection Testing
- Test User-Agent pattern matching
- Test service configuration management
- Test cache key generation for different services
- Test service expandability (adding new services)
## Error Handling Testing
- Test network failures and timeouts
- Test malformed requests and responses
- Test cache corruption scenarios
- Test resource exhaustion conditions
## Test Timeouts
- All tests should run with appropriate timeouts
- Use `context.WithTimeout` for long-running operations
- Set reasonable timeouts for network operations
- Fail fast on obvious errors
## Test Coverage
- Aim for high test coverage on critical paths
- Test edge cases and error conditions
- Test concurrent access patterns
- Test resource cleanup and memory management
## Test Documentation
- Document complex test scenarios
- Explain the purpose of integration tests
- Include comments for non-obvious test logic
- Document expected behavior and assumptions