Skip to content

test: add table-driven tests for ReceiverServer#1297

Open
hamza-younas94 wants to merge 1 commit intofluxcd:mainfrom
hamza-younas94:test/receiver-server-coverage
Open

test: add table-driven tests for ReceiverServer#1297
hamza-younas94 wants to merge 1 commit intofluxcd:mainfrom
hamza-younas94:test/receiver-server-coverage

Conversation

@hamza-younas94
Copy link
Copy Markdown

@hamza-younas94 hamza-younas94 commented Apr 21, 2026

receiver_server.go had no direct test coverage. This PR adds receiver_server_test.go covering the server layer itself (not handlePayload, which is already tested in receiver_handler_test.go).

What's tested:

  • NewReceiverServer constructor sets fields correctly
  • Unknown hook token returns 404
  • Non-hook paths return 404
  • exportHTTPPathMetrics variant returns 404 for unknown tokens
  • Stop channel shuts the server down gracefully
  • A POST to a valid webhook path reaches handlePayload and returns 200

Each 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" passes
  • go test ./internal/server/... no regressions

Copilot AI review requested due to automatic review settings April 21, 2026 10:43
@hamza-younas94 hamza-younas94 force-pushed the test/receiver-server-coverage branch from 4a94576 to f804776 Compare April 21, 2026 10:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go with table-driven httptest-style HTTP calls against a real in-process server.
  • Tests 404 behavior for non-hook paths / unknown webhook tokens, including the exportHTTPPathMetrics configuration 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.

Comment thread internal/server/receiver_server_test.go Outdated
@hamza-younas94 hamza-younas94 force-pushed the test/receiver-server-coverage branch from f804776 to 714e7d7 Compare April 21, 2026 10:49
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>
@hamza-younas94 hamza-younas94 force-pushed the test/receiver-server-coverage branch from 714e7d7 to 9929a16 Compare April 21, 2026 10:53
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.

Increase ReceiverServer test coverage

2 participants