feat(golang): add license parsing from vendor dirs (#3522)

Signed-off-by: Dominik Schmidt <dev@dominik-schmidt.de>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Co-authored-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Dominik Schmidt
2025-01-17 20:25:05 -05:00
committed by GitHub
co-authored by Keith Zantow
parent 8198a706d6
commit 19a75fe504
9 changed files with 562 additions and 11 deletions
+22 -11
View File
@@ -10,11 +10,12 @@ import (
func Test_Config(t *testing.T) {
type opts struct {
local bool
cacheDir string
remote bool
proxy string
noProxy string
local bool
cacheDir string
vendorDir string
remote bool
proxy string
noProxy string
}
homedirCacheDisabled := homedir.DisableCache
@@ -45,10 +46,15 @@ func Test_Config(t *testing.T) {
"GOPRIVATE": "my.private",
"GONOPROXY": "no.proxy",
},
opts: opts{},
opts: opts{
// defaults to $cwd/vendor, we need to set it to make the output predictable
vendorDir: "/vendor",
},
expected: CatalogerConfig{
SearchLocalModCacheLicenses: false,
LocalModCacheDir: filepath.Join("/go", "pkg", "mod"),
SearchLocalVendorLicenses: false,
LocalVendorDir: "/vendor",
SearchRemoteLicenses: false,
Proxies: []string{"https://my.proxy"},
NoProxy: []string{"my.private", "no.proxy"},
@@ -64,15 +70,18 @@ func Test_Config(t *testing.T) {
"GONOPROXY": "no.proxy",
},
opts: opts{
local: true,
cacheDir: "/go-cache",
remote: true,
proxy: "https://alt.proxy,direct",
noProxy: "alt.no.proxy",
local: true,
cacheDir: "/go-cache",
vendorDir: "/vendor",
remote: true,
proxy: "https://alt.proxy,direct",
noProxy: "alt.no.proxy",
},
expected: CatalogerConfig{
SearchLocalModCacheLicenses: true,
LocalModCacheDir: "/go-cache",
SearchLocalVendorLicenses: true,
LocalVendorDir: "/vendor",
SearchRemoteLicenses: true,
Proxies: []string{"https://alt.proxy", "direct"},
NoProxy: []string{"alt.no.proxy"},
@@ -92,6 +101,8 @@ func Test_Config(t *testing.T) {
got := DefaultCatalogerConfig().
WithSearchLocalModCacheLicenses(test.opts.local).
WithLocalModCacheDir(test.opts.cacheDir).
WithSearchLocalVendorLicenses(test.opts.local).
WithLocalVendorDir(test.opts.vendorDir).
WithSearchRemoteLicenses(test.opts.remote).
WithProxy(test.opts.proxy).
WithNoProxy(test.opts.noProxy)