mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
fix dir name in module dir removal
This commit is contained in:
@@ -22,8 +22,8 @@ func (n notFoundError) Error() string {
|
||||
return fmt.Sprintf("%q not found in cache", n.repo)
|
||||
}
|
||||
|
||||
func dirName(repo string) string {
|
||||
return fmt.Sprintf("_repos/src/%s", strings.ToLower(repo))
|
||||
func dirName(repo, ver string) string {
|
||||
return fmt.Sprintf("_repos/src/%s@%s", strings.ToLower(repo), ver)
|
||||
}
|
||||
|
||||
func getFromCache(db *badger.DB, repo string) (checksResp, error) {
|
||||
@@ -99,13 +99,13 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
|
||||
return checksResp{}, fmt.Errorf("could not download repo: %v", err)
|
||||
}
|
||||
|
||||
checkResult, err := check.Run(dirName(repo + "@" + ver))
|
||||
checkResult, err := check.Run(dirName(repo, ver))
|
||||
if err != nil {
|
||||
return checksResp{}, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.RemoveAll(dirName(repo))
|
||||
err := os.RemoveAll(dirName(repo, ver))
|
||||
if err != nil {
|
||||
log.Println("ERROR: could not remove dir:", err)
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ import "testing"
|
||||
|
||||
var dirNameTests = []struct {
|
||||
url string
|
||||
ver string
|
||||
want string
|
||||
}{
|
||||
{"github.com/foo/bar", "_repos/src/github.com/foo/bar"},
|
||||
{"github.com/foo/bar", "v0.1.0", "_repos/src/github.com/foo/bar@v0.1.0"},
|
||||
}
|
||||
|
||||
func TestDirName(t *testing.T) {
|
||||
for _, tt := range dirNameTests {
|
||||
if got := dirName(tt.url); got != tt.want {
|
||||
t.Errorf("dirName(%q) = %q, want %q", tt.url, got, tt.want)
|
||||
if got := dirName(tt.url, tt.ver); got != tt.want {
|
||||
t.Errorf("dirName(%q, %q) = %q, want %q", tt.url, tt.ver, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user