From 18f36b6f354ec4cdea051016cdd7cc16345c1733 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 3 Jan 2022 16:37:00 +0100 Subject: [PATCH] [YAML] Automatically add simulated clusters from the clusters directory into the list of clusters used for test generation instead of manually adding them one by one at the top of SimulatedClusters.js --- .../simulated-clusters/SimulatedClusters.js | 16 ++++++++++------ .../DelayCommands.js} | 2 +- .../LogCommands.js} | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) rename src/app/zap-templates/common/simulated-clusters/{TestDelayCommands.js => clusters/DelayCommands.js} (97%) rename src/app/zap-templates/common/simulated-clusters/{TestLogCommands.js => clusters/LogCommands.js} (97%) diff --git a/src/app/zap-templates/common/simulated-clusters/SimulatedClusters.js b/src/app/zap-templates/common/simulated-clusters/SimulatedClusters.js index f43d4841343b8d..19ace7b76d17f4 100644 --- a/src/app/zap-templates/common/simulated-clusters/SimulatedClusters.js +++ b/src/app/zap-templates/common/simulated-clusters/SimulatedClusters.js @@ -16,13 +16,17 @@ */ const { ensureClusters } = require('../ClustersHelper.js'); -const { DelayCommands } = require('./TestDelayCommands.js'); -const { LogCommands } = require('./TestLogCommands.js'); -const SimulatedClusters = [ - DelayCommands, - LogCommands, -]; +const fs = require('fs'); +const path = require('path'); + +let SimulatedClusters = []; +(async () => { + const simulatedClustersPath = path.join(__dirname, 'clusters'); + const simulatedClustersFiles = await fs.promises.readdir(simulatedClustersPath); + SimulatedClusters = simulatedClustersFiles.map(filename => (require(path.join(simulatedClustersPath, filename))).cluster); + return SimulatedClusters; +})(); function getSimulatedCluster(clusterName) { diff --git a/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js b/src/app/zap-templates/common/simulated-clusters/clusters/DelayCommands.js similarity index 97% rename from src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js rename to src/app/zap-templates/common/simulated-clusters/clusters/DelayCommands.js index e02d1796353b87..a2026851141905 100644 --- a/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js +++ b/src/app/zap-templates/common/simulated-clusters/clusters/DelayCommands.js @@ -53,4 +53,4 @@ const DelayCommands = { // // Module exports // -exports.DelayCommands = DelayCommands; +exports.cluster = DelayCommands; diff --git a/src/app/zap-templates/common/simulated-clusters/TestLogCommands.js b/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js similarity index 97% rename from src/app/zap-templates/common/simulated-clusters/TestLogCommands.js rename to src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js index a35de84b1e17ac..aba2675c345582 100644 --- a/src/app/zap-templates/common/simulated-clusters/TestLogCommands.js +++ b/src/app/zap-templates/common/simulated-clusters/clusters/LogCommands.js @@ -44,4 +44,4 @@ const LogCommands = { // // Module exports // -exports.LogCommands = LogCommands; +exports.cluster = LogCommands;