-
Notifications
You must be signed in to change notification settings - Fork 21
[test] Add tests for config.isDynamicTOMLPath and proxy.truncateForLog #3500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lpcox
merged 1 commit into
main
from
test/coverage-isDynamicTOMLPath-truncateForLog-ef8f1b8ed68f335b
Apr 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package proxy | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // TestTruncateForLog verifies all three branches of truncateForLog: | ||
| // the early-exit for non-positive maxRunes, the no-op for short strings, | ||
| // and the actual truncation path — including correct Unicode rune handling. | ||
| func TestTruncateForLog(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| s string | ||
| maxRunes int | ||
| expected string | ||
| }{ | ||
| // ── maxRunes ≤ 0 always returns "" ─────────────────────────────────── | ||
| { | ||
| name: "maxRunes zero returns empty string", | ||
| s: "hello", | ||
| maxRunes: 0, | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "maxRunes negative returns empty string", | ||
| s: "hello", | ||
| maxRunes: -1, | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "maxRunes very negative returns empty string", | ||
| s: "hello", | ||
| maxRunes: -100, | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "empty string with zero maxRunes returns empty string", | ||
| s: "", | ||
| maxRunes: 0, | ||
| expected: "", | ||
| }, | ||
|
|
||
| // ── string fits within maxRunes (returned unchanged) ───────────────── | ||
| { | ||
| name: "empty string with positive maxRunes returns empty string", | ||
| s: "", | ||
| maxRunes: 10, | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "string shorter than maxRunes returned unchanged", | ||
| s: "hello", | ||
| maxRunes: 10, | ||
| expected: "hello", | ||
| }, | ||
| { | ||
| name: "string exactly equal to maxRunes returned unchanged", | ||
| s: "hello", | ||
| maxRunes: 5, | ||
| expected: "hello", | ||
| }, | ||
| { | ||
| name: "single character string within limit", | ||
| s: "a", | ||
| maxRunes: 1, | ||
| expected: "a", | ||
| }, | ||
| { | ||
| name: "unicode string within limit unchanged", | ||
| s: "日本語", | ||
| maxRunes: 10, | ||
| expected: "日本語", | ||
| }, | ||
| { | ||
| name: "unicode string exactly at limit unchanged", | ||
| s: "日本語", | ||
| maxRunes: 3, | ||
| expected: "日本語", | ||
| }, | ||
|
|
||
| // ── truncation path ─────────────────────────────────────────────────── | ||
| { | ||
| name: "ASCII string truncated to first N chars", | ||
| s: "hello world", | ||
| maxRunes: 5, | ||
| expected: "hello", | ||
| }, | ||
| { | ||
| name: "truncate to single rune", | ||
| s: "hello", | ||
| maxRunes: 1, | ||
| expected: "h", | ||
| }, | ||
| { | ||
| name: "unicode string truncated by rune count not byte count", | ||
| s: "日本語テスト", | ||
| maxRunes: 3, | ||
| expected: "日本語", | ||
| }, | ||
| { | ||
| name: "mixed ASCII and unicode truncated at rune boundary", | ||
| s: "hello日本語", | ||
| maxRunes: 7, | ||
| expected: "hello日本", | ||
| }, | ||
| { | ||
| name: "multibyte euro sign truncated correctly", | ||
| s: "€€€€€", | ||
| maxRunes: 3, | ||
| expected: "€€€", | ||
| }, | ||
| { | ||
| name: "4-byte emoji runes truncated correctly", | ||
| s: "😀😃😄😁", | ||
| maxRunes: 2, | ||
| expected: "😀😃", | ||
| }, | ||
| { | ||
| name: "long string truncated at exactly maxRunes runes", | ||
| s: "abcdefghij", | ||
| maxRunes: 7, | ||
| expected: "abcdefg", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := truncateForLog(tt.s, tt.maxRunes) | ||
| assert.Equal(t, tt.expected, got) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Equaldoes not interpret the provided string as a format string; the%vwill not be substituted, which makes failures harder to read. Useassert.Equalf(...)for formatted messages or pass a plain message without formatting tokens.