Merge branch 'main' into patch-1
This commit is contained in:
+24
-3
@@ -1,4 +1,4 @@
|
||||
import { parseGoList, parseGoModGraph } from './parse'
|
||||
import { parseGoPackage, parseGoList, parseGoModGraph } from './parse'
|
||||
|
||||
const GO_DEPENDENCIES = `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp@v1.7.0
|
||||
golang.org/x/sys@v0.0.0-20220317061510-51cd9980dadf
|
||||
@@ -6,7 +6,28 @@ golang.org/x/text@v0.3.7
|
||||
golang.org/x/text@v0.3.7
|
||||
golang.org/x/text@v0.3.7`
|
||||
|
||||
describe('test dependenciesProcessorFunc', () => {
|
||||
describe('parseGoPackage', () => {
|
||||
it('parses a package with a namespace', () => {
|
||||
expect(parseGoPackage('foo/bar@0.1.2').toString()).toEqual(
|
||||
'pkg:golang/foo/bar@0.1.2'
|
||||
)
|
||||
})
|
||||
// this test should pass, but packageurl-js is double URL-safe encoding the
|
||||
// '%' to %25. It won't, however, URL-encode the '/' that is represented by
|
||||
// %2F.
|
||||
it.skip('parses a package with a namespace with slashes', () => {
|
||||
expect(parseGoPackage('foo/boo/bar@0.1.2').toString()).toEqual(
|
||||
'pkg:golang/foo%2Fboo/bar@0.1.2'
|
||||
)
|
||||
})
|
||||
it('parses a package without a namespace', () => {
|
||||
expect(parseGoPackage('foo.io@0.1.2').toString()).toEqual(
|
||||
'pkg:golang/foo.io@0.1.2'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseGoList', () => {
|
||||
test('parses output of go list command into dependencies', () => {
|
||||
const dependencies = parseGoList(GO_DEPENDENCIES)
|
||||
|
||||
@@ -49,7 +70,7 @@ describe('parseGoModGraph', () => {
|
||||
expect(assocList[0][0]).toEqual({
|
||||
type: 'golang',
|
||||
name: 'go-example',
|
||||
namespace: '.', // we expect the namespace for the root package to process to dot
|
||||
namespace: null,
|
||||
version: null,
|
||||
qualifiers: null,
|
||||
subpath: null
|
||||
|
||||
+10
-3
@@ -1,10 +1,17 @@
|
||||
import path from 'path'
|
||||
import { PackageURL } from 'packageurl-js'
|
||||
|
||||
function parseGoPackage (pkg: string): PackageURL {
|
||||
export function parseGoPackage (pkg: string): PackageURL {
|
||||
const [qualifiedPackage, version] = pkg.split('@')
|
||||
const namespace = encodeURIComponent(path.dirname(qualifiedPackage))
|
||||
const name = path.basename(qualifiedPackage)
|
||||
let namespace: string | null = null
|
||||
let name: string
|
||||
if (qualifiedPackage.indexOf('/') !== -1) {
|
||||
// need to URL-safe encode slashes in the namespace
|
||||
namespace = encodeURIComponent(path.dirname(qualifiedPackage))
|
||||
name = path.basename(qualifiedPackage)
|
||||
} else {
|
||||
name = qualifiedPackage
|
||||
}
|
||||
return new PackageURL('golang', namespace, name, version ?? null, null, null)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user