test: add table-driven tests for ReceiverServer#1297
Open
hamza-younas94 wants to merge 1 commit intofluxcd:mainfrom
Open
test: add table-driven tests for ReceiverServer#1297hamza-younas94 wants to merge 1 commit intofluxcd:mainfrom
hamza-younas94 wants to merge 1 commit intofluxcd:mainfrom
Conversation
4a94576 to
f804776
Compare
There was a problem hiding this comment.
Pull request overview
Adds direct unit test coverage for internal/server/receiver_server.go by exercising ReceiverServer construction, HTTP routing behavior, and graceful shutdown semantics.
Changes:
- Introduces
internal/server/receiver_server_test.gowith table-drivenhttptest-style HTTP calls against a real in-process server. - Tests 404 behavior for non-hook paths / unknown webhook tokens, including the
exportHTTPPathMetricsconfiguration variant. - Adds a shutdown test driven by closing the server stop channel.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f804776 to
714e7d7
Compare
Adds httptest-based unit tests for receiver_server.go covering: - NewReceiverServer constructor field validation - ListenAndServe routing: unknown hook token → 404, non-hook path → 404, exportHTTPPathMetrics variant → 404 - Graceful shutdown via stop channel - Webhook path routing dispatches to handlePayload (not 404) Each subtest uses a private Prometheus registry to avoid duplicate metric registration panics. Addresses fluxcd#496. Signed-off-by: Hamza Younas <hamza.younas94@gmail.com>
714e7d7 to
9929a16
Compare
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.
receiver_server.gohad no direct test coverage. This PR addsreceiver_server_test.gocovering the server layer itself (nothandlePayload, which is already tested inreceiver_handler_test.go).What's tested:
NewReceiverServerconstructor sets fields correctlyexportHTTPPathMetricsvariant returns 404 for unknown tokenshandlePayloadand returns 200Each subtest uses a private Prometheus registry to avoid duplicate metric registration panics when subtests each spin up a new server.
Closes #496
Test plan
go test ./internal/server/... -run "TestNewReceiverServer|TestReceiverServer"passesgo test ./internal/server/...no regressions