This document describes the comprehensive test suite for the Go Bulk Data Generator project.
The test suite covers all major components of the bulk data generator:
- Configuration Testing: Validates BulkGenerator initialization with various configurations
- Record Generation: Tests all supported table types (incident, case, hr_case, change_request, knowledge_article)
- Batch Processing: Tests concurrent batch generation and error handling
- Data Validation: Ensures generated records have proper field values, formats, and constraints
- Date Generation: Tests random date generation with proper formatting
- Error Handling: Tests unsupported table types and error recovery
- Client Initialization: Tests OpenRouter client setup with various configurations
- Fallback Behavior: Tests graceful degradation when API key is missing
- Text Generation: Tests various text generation scenarios (descriptions, close notes, etc.)
- JSON Parsing: Tests JSON response parsing and error recovery
- Category-Specific Logic: Tests specialized fallback logic for different record categories
- Writer Creation: Tests CSV file creation and initialization
- Header Management: Tests header setting and validation for different table types
- Record Writing: Tests writing individual and batch records
- Data Integrity: Validates CSV output contains expected data
- Error Handling: Tests behavior with unsupported record types
- File Operations: Tests proper file closing and cleanup
# Run all tests
go test ./...
# Run tests with verbose output
go test ./... -v
# Run specific package tests
go test ./internal/generator -v
go test ./internal/llm -v
go test ./pkg/csv -v# Make script executable (first time only)
chmod +x run_tests.sh
# Run full test suite with benchmarks and coverage
./run_tests.shThe run_tests.sh script provides:
- Verbose Testing: Shows detailed test execution
- Benchmark Testing: Performance measurements for key operations
- Coverage Analysis: Code coverage reporting
- Race Detection: Concurrent access safety testing
The test suite includes benchmark tests for performance-critical operations:
BenchmarkGenerateIncidentRecord: Measures incident record generation speedBenchmarkGenerateCaseRecord: Measures case record generation speedBenchmarkGenerateBatch: Measures batch processing performance
BenchmarkGenerateTextFallback: Measures fallback text generation speedBenchmarkGenerateIncidentDescriptionsFallback: Measures description generation speedBenchmarkFallbackIncidentDescriptions: Measures fallback logic performance
BenchmarkWriteIncidentRecord: Measures CSV writing performance
- Tests all required fields (caller, category, description, dates, etc.)
- Validates impact/urgency ranges (1-4)
- Tests proper incident state values
- Validates date format (YYYY-MM-DD HH:MM:SS)
- Tests CSM case number format (CS prefix)
- Validates priority ranges (1-5)
- Tests account and contact information
- Validates case state transitions
- Tests HR case number format (HRC prefix)
- Validates HR service types (employee_relations, benefits, payroll, etc.)
- Tests due date calculations
- Validates priority ranges (1-4)
- Tests change number format (CHG prefix)
- Validates comprehensive LLM-generated sections (justification, implementation plan, etc.)
- Tests risk levels (Low, Medium, High, Very High)
- Validates change categories and workflow states
- Tests knowledge base article number format (KB prefix)
- Validates HTML content structure
- Tests article categories and workflow states
- Validates publication dates and author information
- Field Presence: Ensures all required fields are populated
- Format Validation: Checks date formats, number formats, etc.
- Range Validation: Validates numeric fields are within expected ranges
- Enum Validation: Checks choice field values against valid options
- Unsupported Tables: Tests graceful handling of unknown table types
- Missing API Keys: Tests fallback behavior when LLM API is unavailable
- Invalid Data: Tests error recovery for malformed inputs
- Concurrent Processing: Tests thread safety and concurrent batch generation
- Memory Usage: Benchmark tests include memory allocation tracking
- Throughput: Measures records generated per second
- ✅ All tests pass without errors
- ✅ Generated records contain valid, realistic data
- ✅ CSV output is properly formatted and complete
- ✅ Fallback mechanisms work when LLM API is unavailable
- ✅ Performance benchmarks meet acceptable thresholds
- No API Key: Tests run with empty API key to validate fallback behavior
- Concurrent Generation: Multiple goroutines generate records simultaneously
- Large Batches: Tests handle batch sizes up to configured limits
- File I/O: Tests create, write, and clean up temporary files
- Add record generation test in
bulk_generator_test.go - Add CSV header test in
csv_test.go - Add LLM fallback test in
openrouter_test.go - Update benchmark tests for performance measurement
- Create focused unit tests for the specific functionality
- Add integration tests that test the feature end-to-end
- Include error handling and edge case tests
- Add performance benchmarks if applicable
The test suite aims for:
- >90% Code Coverage: Most code paths should be tested
- 100% Critical Path Coverage: All main functionality must be tested
- Error Path Coverage: All error conditions should be tested
- Performance Baseline: Benchmarks establish performance expectations
The test suite is designed to run in CI/CD environments:
- Fast Execution: Tests complete in under 30 seconds
- No External Dependencies: Tests work without internet or external services
- Clean Cleanup: All temporary files are properly removed
- Deterministic Results: Tests produce consistent results across runs