Skip to content

Commit 5b2c2a4

Browse files
committed
Moved the uploadAdvisory method to helpers.
Signed-off-by: Vilem Obratil <vobratil@redhat.com>
1 parent e86aefa commit 5b2c2a4

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

e2e/tests/api/dependencies/global.setup.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SETUP_TIMEOUT,
1111
} from "../../common/constants";
1212
import { test as setup } from "../fixtures";
13-
import { uploadSboms } from "../helpers/upload";
13+
import { uploadAdvisories, uploadSboms } from "../helpers/upload";
1414

1515
setup.describe("Ingest initial data", () => {
1616
setup.skip(
@@ -22,22 +22,9 @@ setup.describe("Ingest initial data", () => {
2222
setup.setTimeout(SETUP_TIMEOUT);
2323

2424
logger.info("Setup: start uploading assets");
25-
await uploadSboms(axios, SBOM_FILES, "../../common/assets/sbom/");
26-
await uploadAdvisories(axios, ADVISORY_FILES);
25+
await uploadSboms(axios, "../../common/assets/sbom/", SBOM_FILES);
26+
await uploadAdvisories(axios, "../../common/assets/csaf/", ADVISORY_FILES);
2727
logger.info("Setup: upload finished successfully");
2828
});
2929
});
3030

31-
const uploadAdvisories = async (axios: AxiosInstance, files: string[]) => {
32-
const uploads = files.map((e) => {
33-
const filePath = path.join(__dirname, `../../common/assets/csaf/${e}`);
34-
fs.statSync(filePath); // Verify file exists
35-
36-
const fileStream = fs.createReadStream(filePath);
37-
return axios.post("/api/v2/advisory", fileStream, {
38-
headers: { "Content-Type": "application/json+bzip2" },
39-
});
40-
});
41-
42-
await Promise.all(uploads);
43-
};

e2e/tests/api/features/performance-delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test.describe("Performance / Deletion", { tag: "@performance" }, () => {
3939
test.beforeEach(async ({ axios }) => {
4040
logger.info("Uploading SBOMs before deletion performance tests.");
4141

42-
var uploads = await uploadSboms(axios, SBOM_FILES, SBOM_DIR);
42+
var uploads = await uploadSboms(axios, SBOM_DIR, SBOM_FILES);
4343

4444
uploads.forEach((upload) => sbomIds.push(upload.id));
4545

e2e/tests/api/helpers/upload.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,36 @@ import type { AxiosInstance } from "axios";
55

66
export async function uploadSboms(
77
axios: AxiosInstance,
8-
files: string[],
98
sbomDirPath: string,
9+
files: string[]
1010
) {
1111
const uploads = files.map((e) => {
1212
const filePath = path.join(__dirname, `${sbomDirPath}/${e}`);
1313
fs.statSync(filePath); // Verify file exists
1414

1515
const fileStream = fs.createReadStream(filePath);
16-
const promise = axios.post("/api/v2/sbom", fileStream, {
16+
return axios.post("/api/v2/sbom", fileStream, {
1717
headers: { "Content-Type": "application/json+bzip2" },
1818
});
1919

20-
return promise;
2120
});
2221

2322
const responses = await Promise.all(uploads);
2423
return responses.map((response) => response.data);
2524
}
25+
26+
export async function uploadAdvisories(axios: AxiosInstance, advisoryDirPath: string, files: string[]) {
27+
28+
const uploads = files.map((e) => {
29+
const filePath = path.join(__dirname, `${advisoryDirPath}/${e}`);
30+
fs.statSync(filePath); // Verify file exists
31+
32+
const fileStream = fs.createReadStream(filePath);
33+
return axios.post("/api/v2/advisory", fileStream, {
34+
headers: { "Content-Type": "application/json+bzip2" },
35+
});
36+
});
37+
38+
const responses = await Promise.all(uploads)
39+
return responses
40+
}

0 commit comments

Comments
 (0)