From 008de18191f091344d91e26bea4e41cfa080837f Mon Sep 17 00:00:00 2001 From: Aidar Negimatzhanov Date: Wed, 4 Dec 2024 15:55:29 +0100 Subject: [PATCH] Added report files cleanup after bank load tests --- signify-ts-test/test-workflow-banks.sh | 8 ++++ .../test/run-bank-reports-cleanup.test.ts | 40 +++++++++++++++++++ .../test/run-bank-reports-download.test.ts | 11 ----- 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100755 signify-ts-test/test/run-bank-reports-cleanup.test.ts diff --git a/signify-ts-test/test-workflow-banks.sh b/signify-ts-test/test-workflow-banks.sh index 6c3cc71..5883405 100755 --- a/signify-ts-test/test-workflow-banks.sh +++ b/signify-ts-test/test-workflow-banks.sh @@ -61,6 +61,14 @@ while [[ $# -gt 0 ]]; do fi shift # past argument ;; + --reports-cleanup) + npx jest ./run-bank-reports-cleanup.test.ts --runInBand --forceExit + download_exit_code=$? + if [[ $download_exit_code -ne 0 ]]; then + exit 1 + fi + shift # past argument + ;; --data-report) npx jest ./run-workflow-bank-issuance.test.ts --runInBand --detectOpenHandles --forceExit report_exit_code=$? diff --git a/signify-ts-test/test/run-bank-reports-cleanup.test.ts b/signify-ts-test/test/run-bank-reports-cleanup.test.ts new file mode 100755 index 0000000..22de4fe --- /dev/null +++ b/signify-ts-test/test/run-bank-reports-cleanup.test.ts @@ -0,0 +1,40 @@ +import path from "path"; +const fs = require("fs"); +const yaml = require("js-yaml"); + +const tmpReportsPath = path.join(__dirname, "./data/tmp_reports"); +const tmpReportsUnpackedPath = path.join( + __dirname, + "./data/tmp_reports_unpacked", +); +const signedReportsPath = path.join(__dirname, "./data/signed_reports"); +const faileportsPath = path.join(__dirname, "./data/fail_reports"); + +const removeFolderRecursive = (folderPath: string) => { + if (fs.existsSync(folderPath)) { + fs.rmSync(folderPath, { recursive: true, force: true }); + console.log(`Deleted folder: ${folderPath}`); + } else { + console.log(`Folder not found: ${folderPath}`); + } +}; + +const cleanupReports = (bankName: string) => { + const currentTmpSignedReportsUnpackedPath = `${tmpReportsUnpackedPath}/${bankName}/reports/signed_reports`; + const currentTmpFailReportsUnpackedPath = `${tmpReportsUnpackedPath}/${bankName}/reports/fail_reports`; + const signedItems = fs.readdirSync(currentTmpSignedReportsUnpackedPath); + signedItems.forEach((item: any) => { + removeFolderRecursive(`${signedReportsPath}/${item}`); + }); + const failItems = fs.readdirSync(currentTmpFailReportsUnpackedPath); + failItems.forEach((item: any) => { + removeFolderRecursive(`${faileportsPath}/${item}`); + }); + removeFolderRecursive(`${tmpReportsPath}`); + removeFolderRecursive(`${tmpReportsUnpackedPath}`); +}; +test("bank-reports-cleanup", async function run() { + // You need to set the BANK_NAME environment variable. Ex.: export BANK_NAME=Bank_2. + const bankName = process.env.BANK_NAME || "Bank_1"; + cleanupReports(bankName); +}, 3600000); diff --git a/signify-ts-test/test/run-bank-reports-download.test.ts b/signify-ts-test/test/run-bank-reports-download.test.ts index acf426d..6288240 100755 --- a/signify-ts-test/test/run-bank-reports-download.test.ts +++ b/signify-ts-test/test/run-bank-reports-download.test.ts @@ -69,16 +69,6 @@ const unpackZipFile = ( ); } moveFiles(path.join(destFolder, bankName), path.join(confPath, bankName)); - removeFolderRecursive(path.join(destFolder, bankName)); -}; - -const removeFolderRecursive = (folderPath: string) => { - if (fs.existsSync(folderPath)) { - fs.rmSync(folderPath, { recursive: true, force: true }); - console.log(`Deleted folder: ${folderPath}`); - } else { - console.log(`Folder not found: ${folderPath}`); - } }; const moveReports = ( @@ -149,5 +139,4 @@ test("bank-reports-download", async function run() { doAllSigned, doFailReps, ); - removeFolderRecursive(destFilePath); }, 3600000);