Skip to content

Commit

Permalink
fix: go work duplicate prefix get err
Browse files Browse the repository at this point in the history
  • Loading branch information
godLei6 authored and kevwan committed Dec 19, 2024
1 parent 86e3c6a commit 14e8e6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tools/goctl/util/ctx/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func getRealModule(workDir string, execRun execx.RunFunc) (*Module, error) {
if err != nil {
return nil, err
}

if workDir[len(workDir)-1] != os.PathSeparator {
workDir = workDir + string(os.PathSeparator)
}
for _, m := range modules {
realDir, err := pathx.ReadLink(m.Dir)
if err != nil {
Expand Down
31 changes: 28 additions & 3 deletions tools/goctl/util/ctx/gomod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ func Test_getRealModule(t *testing.T) {
return `
{
"Path": "gitee.com/unitedrhino/core",
"Main": true,
"Dir": "D:\\code\\company\\core",
"GoMod": "D:\\code\\company\\core\\go.mod",
"GoVersion": "1.21.4"
}
{
"Path": "gitee.com/unitedrhino/core-ee",
"Main": true,
"Dir": "D:\\code\\company\\core-ee",
"GoMod": "D:\\code\\company\\core-ee\\go.mod",
"GoVersion": "1.21.4"
Expand All @@ -124,7 +122,34 @@ func Test_getRealModule(t *testing.T) {
Path: "gitee.com/unitedrhino/core-ee",
Dir: "D:\\code\\company\\core-ee",
GoMod: "D:\\code\\company\\core-ee\\go.mod",
GoVersion: "go1.19",
GoVersion: "1.21.4",
},
},
{
name: "go work duplicate prefix2",
args: args{
workDir: "D:\\code\\company\\core-ee",
execRun: func(arg, dir string, in ...*bytes.Buffer) (string, error) {
return `
{
"Path": "gitee.com/unitedrhino/core",
"Dir": "D:\\code\\company\\core",
"GoMod": "D:\\code\\company\\core\\go.mod",
"GoVersion": "1.21.4"
}
{
"Path": "gitee.com/unitedrhino/core-ee",
"Dir": "D:\\code\\company\\core-ee",
"GoMod": "D:\\code\\company\\core-ee\\go.mod",
"GoVersion": "1.21.4"
}`, nil
},
},
want: &Module{
Path: "gitee.com/unitedrhino/core-ee",
Dir: "D:\\code\\company\\core-ee",
GoMod: "D:\\code\\company\\core-ee\\go.mod",
GoVersion: "1.21.4",
},
},
}
Expand Down

0 comments on commit 14e8e6f

Please sign in to comment.