Skip to content

test: add comprehensive unit tests, fixtures, and golangci-lint config - #24

Merged
ngoyal16 merged 1 commit into
mainfrom
test/add-tests-fixtures-and-linter
Sep 29, 2026
Merged

ngoyal16 merged 1 commit into
mainfrom
test/add-tests-fixtures-and-linter

Conversation

@ngoyal16

Copy link
Copy Markdown
Contributor

Fixes #2
Fixes #22

Summary of Changes

1. Test Coverage (Closes #2)

  • Added filter_test.go with tests for:
    • All DSL node types (not, dimensionExists, selector, and, or, contains across string, slice, map, and numeric values).
    • LoadFilterConfig loading YAML, JSON, falling back to default, and failing on malformed configs.
  • Added convert_test.go with tests for:
    • 6 convertJSONToParquet scenarios: heartbeat filtering, dropped fields, query matching, malformed JSON, empty event list, and numeric exitCode formatting.
    • decompressZlib round-trip, invalid/corrupt stream, and empty input.
    • decryptAWSEncryptionSDKPayload with matching key, mismatched key, and invalid ciphertext.
  • Statement coverage increased to 83.2% across the repository (exceeding the 70% target in Add unit and integration tests — zero test coverage currently #2).

2. Linter & Tooling (Closes #22)

  • Added .golangci.yml configured with govet, errcheck, staticcheck, revive, gosec, misspell, ineffassign, gosimple, and gofmt.
  • Updated Makefile lint target to automatically look in $GOPATH/bin if golangci-lint is not directly in $PATH.

3. Test Fixtures (Closes #22)

  • Created testdata/ containing:
    • das_events.json: Sample raw DAS database activity events list.
    • s3_event_notification.json: Standard S3 Event Notification format.
    • sns_s3_event.json: SNS-wrapped S3 event envelope.
    • eventbridge_s3_event.json: Amazon EventBridge S3 event format.
    • das_heartbeat_only.json & das_empty.json: Boundary fixtures for edge case verification.

4. Bugs Uncovered & Fixed During Testing

  • Decompression Bomb Defense: Protected decompressZlib with io.LimitReader(..., 256MB) resolving gosec G110 vulnerability.
  • Nil Schema Panic on Empty Rows: Configured parquet.NewWriter with explicit schema parquet.SchemaOf(new(DatabaseActivityEvent)) to prevent nil pointer segmentation fault when writing empty event batches.
  • Filter Evaluation Accuracy: Fixed dimensionExists and selector to properly return false when dimensions or values are invalid/missing.

#2, #22)

- Add .golangci.yml with standard Go linters (govet, errcheck, staticcheck, revive, gosec, misspell)
- Add testdata/ fixtures for DAS events, S3 notifications, SNS envelopes, and EventBridge events
- Add filter_test.go covering EvaluateFilter for all DSL node types (not, dimensionExists, selector, and, or, contains) and LoadFilterConfig (JSON, YAML, default fallback)
- Add convert_test.go covering convertJSONToParquet (heartbeat filtering, drop fields, query matching, empty events, exit codes), decompressZlib, and ESDK decryption
- Fix gosec G110 decompression bomb vulnerability in decompressZlib using io.LimitReader
- Fix nil pointer panic in parquet.NewWriter on empty event batches by supplying explicit schema
- Fix dimensionExists and selector in filter.go to return false for invalid dimensions
- Achieve 83.2% statement test coverage across the repository
@ngoyal16
ngoyal16 merged commit fccf065 into main Sep 29, 2026
9 checks passed
@ngoyal16
ngoyal16 deleted the test/add-tests-fixtures-and-linter branch September 29, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add .golangci.yml linter configuration and sample DAS test fixtures Add unit and integration tests — zero test coverage currently

1 participant