-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor: replace strings.SplitN(arg, sep, 2) with strings.Cut(arg, sep) #23954
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThis pull request modifies the Changes
Suggested reviewers
Possibly related PRs
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
client/v2/autocli/flag/map_test.go (3)
52-52
: Consider adding documentation comments.Adding a documentation comment to explain the purpose of this test function and how it relates to the
strings.Cut
implementation would improve readability.+// TestCompositeMapValue_Set tests the Set method of compositeMapValue +// which uses strings.Cut for parsing key-value pairs from input strings. func TestCompositeMapValue_Set(t *testing.T) {
53-111
: Consider adding edge cases to test suite.While the current test cases cover the main scenarios, consider adding tests for edge cases such as:
- Empty input string
- Input with no separator character
- Input with multiple consecutive separators
{ name: "value parsing fails", input: "1=foo,2=bar", resolver: func(s string) (int, error) { return 1, nil }, valueType: &mockType{err: errors.New("value error")}, expectErr: true, }, + { + name: "empty input", + input: "", + resolver: func(s string) (int, error) { + return 0, nil + }, + valueType: &mockType{}, + expectErr: false, + expectVals: map[int]string{}, + }, + { + name: "input with no separator", + input: "justkey", + resolver: func(s string) (int, error) { + return 0, nil + }, + valueType: &mockType{}, + expectErr: true, + },
127-139
: Consider verifying specific error messages.The tests currently check for error presence but don't verify specific error messages. Consider enhancing error verification to ensure the right type of error is being reported.
if tc.expectErr { assert.Error(t, err) + // For specific test cases, verify the error message + if tc.name == "invalid format" { + assert.Contains(t, err.Error(), "invalid key-value pair") + } } else { assert.NoError(t, err)
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
client/v2/autocli/flag/map_test.go
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
client/v2/autocli/flag/map_test.go
`**/*_test.go`: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
client/v2/autocli/flag/map_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (5)
client/v2/autocli/flag/map_test.go (5)
3-10
: Well-organized imports following Go conventions.Imports are correctly organized with standard library imports first, followed by third-party imports.
12-38
: Good mock implementation for testing.The
mockValue
struct and its methods are well-designed for testing purposes, implementing all necessary interfaces correctly.
40-50
: Well-structured mock type implementation.The
mockType
struct correctly implements methods needed to create mock values for testing. Good approach for test isolation.
53-111
: Well-structured table-driven tests with good test coverage.The test cases effectively cover valid input parsing, invalid format handling, key resolver failures, and value parsing errors. This is a good approach for comprehensive testing of the
strings.Cut
implementation.
113-142
: Test execution logic is well-structured and complete.The test execution properly initializes the compositeMapValue, calls the Set method, and checks for expected outcomes. The conversion of protoreflect.Value to string for comparison is a good approach for verification.
@healthyyyoung it looks like there are more occurrences of |
checked all @aljo242 |
Can we target |
no problem! |
Description
replace strings.SplitN(arg, sep, 2) with strings.Cut(arg, sep):
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Summary by CodeRabbit
Refactor
Tests
Set
method of the compositeMapValue structure, covering various scenarios for input parsing and error handling.