Skip to content

Commit

Permalink
fix special case for ParseVendorModule
Browse files Browse the repository at this point in the history
  • Loading branch information
vearne committed Jan 3, 2024
1 parent d1193f8 commit 965bbfa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
coverage.txt
/test/plugins/workspace
/test/plugins/dist/
*.pb.go
*.pb.go
vendor/
4 changes: 4 additions & 0 deletions tools/go-agent/tools/testdata/special-modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# github.com/abc/def v0.3.0
## explicit; go 1.18
github.com/abc/def/aa
github.com/abc/def/bb/cc
3 changes: 2 additions & 1 deletion tools/go-agent/tools/vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ func ParseVendorModule(path string) (VendorModules, error) {
return nil, fmt.Errorf("module data cannot be analyzed")
}
module = &VendorModule{
Name: moduleInfo[1],
Name: strings.TrimSpace(moduleInfo[1]),
Version: moduleInfo[2],
}
modules[module.Name] = module
continue
} else if strings.HasPrefix(moduleString, "#") {
// go version required, ignore
Expand Down
13 changes: 13 additions & 0 deletions tools/go-agent/tools/vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ func TestParseVendorModule(t *testing.T) {
return nil
},
},
{
path: "./testdata/special-modules.txt",
hasError: false,
packageCount: 3,
validate: func(modules VendorModules) error {
if m := modules["github.com/abc/def"]; m == nil {
return fmt.Errorf("module missing")
} else if m.Version != "v0.3.0" {
return fmt.Errorf("version not correct")
}
return nil
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 965bbfa

Please sign in to comment.