-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Get GOPATH
with go env
#133
Conversation
WalkthroughThe recent updates streamline the handling of GOPATH and GOBIN within a Go project. Notably, unnecessary imports and functions related to environment variable checks have been removed, simplifying the codebase. A significant enhancement includes a new method for dynamically retrieving the GOPATH, ensuring greater flexibility and reliability in environments where this path is not explicitly set. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- cmd/remove_test.go (2 hunks)
- internal/goutil/goutil.go (1 hunks)
- internal/goutil/goutil_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
- cmd/remove_test.go
Additional comments: 2
internal/goutil/goutil.go (1)
- 247-250: The addition of
exec.Command
to dynamically retrieve theGOPATH
is a welcome improvement for flexibility. However, consider handling the case where thego
command is not available or fails unexpectedly. It might be beneficial to log the error or provide a fallback mechanism.internal/goutil/goutil_test.go (1)
- 191-196: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]
The removal of tests related to
GOPATH
handling suggests a shift in testing strategy. Ensure that the new approach for dynamically retrievingGOPATH
is adequately tested, possibly by mockingexec.Command
to simulate different scenarios.
@rkscv |
Do you mind if I delete these tests? Or any suggestions? |
@rkscv func TestGetPackageVersion_getting_error_from_gobin(t *testing.T) {
// Set env variable to temporary value and defer restore on Cleanup
t.Setenv("GOBIN", "")
t.Setenv("GOPATH", "")
// Backup and defer restore
oldKeyGoPath := keyGoPath
defer func() {
keyGoPath = oldKeyGoPath
}()
// Mock the value
keyGoPath = t.Name()
// Setting GOBIN, GOPATH and build.Default.GOPATH to empty string
// should be an error internally and return "unknown" as a version.
got := GetPackageVersion(".")
want := "unknown"
if want != got {
t.Errorf("GetPackageVersion() should return %v. got: %v", want, got)
}
} |
Thanks, it looks fine. But |
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- cmd/remove_test.go (2 hunks)
- internal/goutil/goutil.go (1 hunks)
- internal/goutil/goutil_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (3)
- cmd/remove_test.go
- internal/goutil/goutil.go
- internal/goutil/goutil_test.go
@rkscv |
https://github.com/golang/go/blob/35b1a146d9febca70db87dc4e1f8bac33de857bb/src/go/build/build.go#L289-L306
build.Default.GOPATH
is hard-coded~/go
while I use a customGOPATH
in~/.config/go/env
managed bygo env
.I don't tend to test
goPath
because~/.config/go/env
could be read or written by other programs during the test.Summary by CodeRabbit