lizining1231 opened a new pull request, #3649:
URL: https://github.com/apache/dubbo-go/pull/3649
### Description
Fixes #3644 (task 8)
This PR adds doc comments for `ExtractFromOutgoingContext`,
`SetHeader`,`SetTrailer`, `SendHeader`, and `Error.Error`, clarifying their
behavior, error return conditions, and how the framework uses them internally.
Italso adds 13 boundary tests covering previously untested branches.
### Changes
- **header.go**
- `ExtractFromOutgoingContext`: new doc comment. Returns nil if no
outgoing headers have been set. The framework calls it internally — on the
client side to populate request headers before sending, and on the server side
to merge handler-set headers into response trailers.
- `SetHeader` / `SetTrailer` / `SendHeader`: augmented to state that they
return a `CodeInternal` error when called outside a Triple handler context.
- **error.go**
- `Error.Error`: new doc comment. Returns the status code's name and, if
non-empty, the underlying error's message separated by a colon.
**header_test.go (8 tests):**
| Test | What it verifies |
| --- | --- |
| `TestDecodeBinaryHeader` | Handles empty, unpadded (`len%4 != 0` →
RawStdEncoding), padded (`len%4 == 0` with `=`), and naturally-aligned (`len%4
== 0` without `=`) base64 inputs |
| `TestExtractFromOutgoingContext` | Returns nil when no outgoing headers
are set; returns the headers when set via `NewOutgoingContext` |
| `TestNewOutgoingContextReplacesExisting` | A second call to
`NewOutgoingContext` replaces existing headers instead of merging |
| `TestAppendToOutgoingContextPanicsOnOddKV` | Panics when given an odd
number of key-value arguments |
| `TestSetHeader` | Within a handler context, headers are merged into
`ResponseHeader` |
| `TestSetTrailer` | Within a handler context, headers are merged into
`ResponseTrailer` |
| `TestSetHeaderOutsideHandler` | Outside a handler context, returns
`CodeInternal` |
| `TestSetTrailerOutsideHandler` | Outside a handler context, returns
`CodeInternal` |
**error_test.go (5 tests):**
| Test | What it verifies |
| --- | --- |
| `TestNewWireError` | `IsWireError` returns true for wire errors created by
`NewWireError` (including when wrapped), false for regular `*Error` and
non-triple errors |
| `TestNewErrorDetailWithAny` | Uses an `*anypb.Any` directly without
wrapping it into another `Any` |
| `TestErrorDetailBytesReturnsCopy` | `Bytes()` returns a copy; mutating the
returned slice does not affect internal state |
| `TestWrapIfContextError` | `context.Canceled` → `CodeCanceled`,
`context.DeadlineExceeded` → `CodeDeadlineExceeded` (both preserve the
`errors.Is` chain); already-coded errors returned unchanged (same pointer);
plain errors returned as-is; nil returns nil |
| `TestWrapIfUncoded` | nil returns nil; already-coded errors preserved
(same pointer); `context.Canceled` wrapped with `CodeCanceled` via
`wrapIfContextError`; plain errors wrapped with `CodeUnknown` |
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature
works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]