Skip to content

Add unit tests for streaming request and response body logging#209

Open
ravindu-danthanarayana wants to merge 1 commit into
wso2:mainfrom
ravindu-danthanarayana:add-log-message-streaming-tests
Open

Add unit tests for streaming request and response body logging#209
ravindu-danthanarayana wants to merge 1 commit into
wso2:mainfrom
ravindu-danthanarayana:add-log-message-streaming-tests

Conversation

@ravindu-danthanarayana

Copy link
Copy Markdown

Purpose

This PR adds missing unit test coverage for the streaming methods in the log-message policy.

Goals

Improve test coverage for streaming request and response body logging paths.

Approach

Added a new test case TestLogMessagePolicy_StreamingRequestAndResponse covering:

  • NeedsMoreRequestData
  • NeedsMoreResponseData
  • OnRequestBodyChunk
  • OnResponseBodyChunk

The test verifies the expected forwarding behavior and logging of streamed request and response payload chunks.

User stories

N/A

Release note

Added unit test coverage for streaming request and response body logging.

Documentation

N/A

Training

N/A

Certification

N/A

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f7e53b4-813c-43ab-b9c2-e14a74e470ef

📥 Commits

Reviewing files that changed from the base of the PR and between e5c126d and b27561f.

📒 Files selected for processing (1)
  • policies/log-message/logmessage_test.go

📝 Walkthrough

Summary

This PR adds unit test coverage for streaming methods in the log-message policy by introducing a new test case, TestLogMessagePolicy_StreamingRequestAndResponse. The test validates four streaming-related methods: NeedsMoreRequestData, NeedsMoreResponseData, OnRequestBodyChunk, and OnResponseBodyChunk. The test verifies that these methods correctly handle streamed payload chunks, return appropriate forwarding actions, and emit log records with the expected payload and request context information. This improves test coverage for the streaming request and response body logging paths within the log-message policy implementation.

Changes

  • File: policies/log-message/logmessage_test.go
    • Added new test function TestLogMessagePolicy_StreamingRequestAndResponse (+75 lines)

Walkthrough

A new test function, TestLogMessagePolicy_StreamingRequestAndResponse, is added to policies/log-message/logmessage_test.go. The test verifies that NeedsMoreRequestData and NeedsMoreResponseData return false when passed nil. It then exercises OnRequestBodyChunk and OnResponseBodyChunk, asserting that each returns the appropriate forwarding action (ForwardRequestChunk and ForwardResponseChunk respectively) and that exactly one log record is emitted per chunk with the correct Payload and RequestID values drawn from the respective stream contexts.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change: adding unit tests for streaming request and response body logging.
Description check ✅ Passed The description covers key sections including Purpose, Goals, Approach, and Release note with relevant details about the streaming test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant