Qualifiers are a map of string key-value pairs
This commit is contained in:
@@ -1,20 +1,39 @@
|
||||
import ComponentDetection from './componentDetection';
|
||||
import fs from 'fs';
|
||||
import ComponentDetection from "./componentDetection";
|
||||
import fs from "fs";
|
||||
|
||||
test('Downloads CLI', async () => {
|
||||
test("Downloads CLI", async () => {
|
||||
await ComponentDetection.downloadLatestRelease();
|
||||
expect(fs.existsSync(ComponentDetection.componentDetectionPath));
|
||||
});
|
||||
|
||||
test('Runs CLI', async () => {
|
||||
test("Runs CLI", async () => {
|
||||
await ComponentDetection.downloadLatestRelease();
|
||||
await ComponentDetection.runComponentDetection('./test');
|
||||
await ComponentDetection.runComponentDetection("./test");
|
||||
expect(fs.existsSync(ComponentDetection.outputPath));
|
||||
});
|
||||
|
||||
test('Parses CLI output', async () => {
|
||||
test("Parses CLI output", async () => {
|
||||
await ComponentDetection.downloadLatestRelease();
|
||||
await ComponentDetection.runComponentDetection('./test');
|
||||
await ComponentDetection.runComponentDetection("./test");
|
||||
var manifests = await ComponentDetection.getManifestsFromResults();
|
||||
expect(manifests?.length == 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ComponentDetection.makePackageUrl", () => {
|
||||
test("returns a valid package url", () => {
|
||||
const packageUrl = ComponentDetection.makePackageUrl({
|
||||
Scheme: "pkg",
|
||||
Type: "npm",
|
||||
Namespace: "github",
|
||||
Name: "component-detection-action",
|
||||
Version: "0.0.2",
|
||||
Qualifiers: {
|
||||
arch: "amd64",
|
||||
os: "linux",
|
||||
},
|
||||
});
|
||||
expect(packageUrl).toBe(
|
||||
"pkg:npm/github/component-detection-action@0.0.2?arch=amd64&os=linux"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ export default class ComponentDetection {
|
||||
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
|
||||
}
|
||||
|
||||
private static makePackageUrl(packageUrlJson: any): string {
|
||||
public static makePackageUrl(packageUrlJson: any): string {
|
||||
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
|
||||
if (packageUrlJson.Namespace) {
|
||||
packageUrl += `${packageUrlJson.Namespace.replaceAll("@", "%40")}/`;
|
||||
@@ -128,8 +128,11 @@ export default class ComponentDetection {
|
||||
if (packageUrlJson.Version) {
|
||||
packageUrl += `@${packageUrlJson.Version}`;
|
||||
}
|
||||
if (packageUrlJson.Qualifiers) {
|
||||
packageUrl += `?${packageUrlJson.Qualifiers}`;
|
||||
if (packageUrlJson.Qualifiers !== null) {
|
||||
const qualifierString = Object.entries(packageUrlJson.Qualifiers)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join("&");
|
||||
packageUrl += `?${qualifierString}`;
|
||||
}
|
||||
return packageUrl;
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ export default class ComponentDetection {
|
||||
private static getComponentDetectionParameters;
|
||||
static getManifestsFromResults(): Promise<Manifest[] | undefined>;
|
||||
private static getDependencyScope;
|
||||
private static makePackageUrl;
|
||||
static makePackageUrl(packageUrlJson: any): string;
|
||||
private static getLatestReleaseURL;
|
||||
}
|
||||
|
||||
+5
-2
@@ -23425,8 +23425,11 @@ class ComponentDetection {
|
||||
if (packageUrlJson.Version) {
|
||||
packageUrl += `@${packageUrlJson.Version}`;
|
||||
}
|
||||
if (packageUrlJson.Qualifiers) {
|
||||
packageUrl += `?${packageUrlJson.Qualifiers}`;
|
||||
if (packageUrlJson.Qualifiers !== null) {
|
||||
const qualifierString = Object.entries(packageUrlJson.Qualifiers)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join("&");
|
||||
packageUrl += `?${qualifierString}`;
|
||||
}
|
||||
return packageUrl;
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user