Add unit tests and code coverage for the message path#13
Merged
Conversation
Establish real test coverage on rtbeat's core logic, which previously had none (config_test.go was an empty stub; beater had no tests). Production change (behavior-preserving): - Extract the rxtx MessageBatch -> []beat.Event logic out of the gin handler closure into buildEvents(), and the POST /in handler into inHandler(). Metric updates are injected as onBatch/onMessages callbacks so the handler is testable without the global prometheus registry. An eventPublisher interface lets tests fake the libbeat client. - Incidental fix: clientIp is now read synchronously from the request instead of from the publish goroutine, where gin may already have recycled the context. Tests: - beater: table-driven buildEvents (field mapping, Private index, the leading-empty-event quirk locked down as a regression guard) and httptest coverage of POST /in (200/500, metric callbacks, clientIp propagation, no-publish-on-error). - config: DefaultConfig values, Unpack overrides, empty-keeps-defaults. buildEvents and inHandler are 100% covered. README gains a codecov badge. make verify passes; no production behavior change (the leading-empty-event quirk is asserted, not altered). Closes #12
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12.
Establishes real test coverage on rtbeat's core logic, which previously had none (
config_test.gowas an empty stub;beaterhad no tests).make verifypasses; no production behavior change.Production change (behavior-preserving)
MessageBatch→[]beat.Eventlogic out of the gin handler closure intobuildEvents(), and thePOST /inhandler intoinHandler(). Metric updates are injected asonBatch/onMessagescallbacks so the handler is testable without touching the global prometheus registry; aneventPublisherinterface lets tests fake the libbeat client.clientIpis now read synchronously from the request instead of from the publish goroutine, where gin may already have recycled the*gin.Context.Tests
buildEvents(field mapping fortype/rxtxMsg/clientIp,Privateindex, the leading-empty-event quirk locked down as a regression guard) andhttptestcoverage ofPOST /in(200/500, metric callbacks,clientIppropagation, no-publish-on-error).DefaultConfigvalues,Unpackoverrides, empty-keeps-defaults.Coverage
buildEventsandinHandlerare 100% covered;beaterpackage total 27.1% (the remainder —New/Run/Stop— needs a live beat pipeline / integration test).Notes
Per #12, the leading-empty-event publishing quirk is asserted, not changed — altering it is a separate decision. Adversarial review confirmed behavioral equivalence and that the
c.ClientIP()move is a latent-bug fix.