LoongCollector Testing Standards
Test Categories
1. Unit Tests (C++)
- Use Google Test (GTest) / Google Mock
- Place in
core/unittest/ - Cover success and failure paths
- Core logic must have 100% coverage
- Test boundary conditions explicitly
- Test naming: accurately describe behavior being tested
- Each
core/unittest/*/directory produces one executable - Build and run tests from inside
build/to ensure relative paths and temp files work correctly - See
skills/compile/SKILL.mdfor build & run instructions
2. Unit Tests (Go)
- Use standard
testingpackage - Table-driven tests for function coverage
- Integration tests via E2E framework
3. E2E Tests
- BDD Godog framework
- Configuration-driven via
.featurefiles - See
skills/e2e/SKILL.mdfor complete guide (design → write → run → debug)
4. Benchmarks
- Required for performance-sensitive code paths
- Compare against baseline versions
- Measure throughput, latency, CPU/Memory usage
E2E Test Quick Reference
Feature File Structure
@input
Feature: input file
Test input file
@e2e @host
Scenario: TestInputFileWithRegexSingle
Given {host} environment
Given subcribe data from {sls} with config
"""
enable: true
inputs:
- Type: input_file
"""
When generate {100} regex logs to file {/tmp/loongcollector/regex_single.log}, with interval {100}ms
Then there is {100} logs
Behavior Types
| Type | Purpose |
|---|---|
Given |
Setup/prepare test conditions |
When |
Trigger test actions (e.g., log generation) |
Then |
Verify test results |
Environment Tags
@host- Host environment@k8s- Kubernetes environment@docker-compose- Docker Compose environment@e2e- E2E test marker@regression- Regression test marker
Adding New Test Behaviors
- Write the Go function in the appropriate directory:
cleanup/- Post-test cleanup (auto-executed)control/- Control operations (init, config)setup/- Environment setuptrigger/- Data generationverify/- Result verification
- Function signature:
func Name(ctx context.Context, params...) (context.Context, error) - Register in
test/e2e_enterprise/main_test.goviascenarioInitializer - Use in feature files with
{param}syntax
Strict Rules
- Do NOT change behavior of the method being tested
- Do NOT modify existing test behaviors in engine
- Always start trigger
When begin triggerBEFORE generating logs - Only use registered behaviors from
test/engine/steps.go - Verify behavior type matches (Given/When/Then)
Test Naming
- Format:
Test${FunctionName}${CaseBriefDescription} - Examples:
TestInputFileWithBlackListDir,TestInputFileWithRegexSingle - Must include
@e2eand environment tags
Benchmark Testing
For performance-sensitive code:
- Provide baseline comparison
- Measure: throughput, latency, CPU profile, memory profile
- Run under realistic load conditions
- Document methodology and results