Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Script that generate all permutations of user input for IVS and Livestream services #210

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature(gen-test-payload): fix typo error and add possibility to blac…
…klist paths
  • Loading branch information
spaniernathan committed Apr 19, 2021
commit df7b19023da1feee590d5306d80d12ea25c0ea26
48 changes: 26 additions & 22 deletions scripts/gen-test-payload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ class Tree {
}

buildTree(questions, helper) {
this.rootNode = new TreeNode('root', 'root', 0);
const firstQuestion = helper[questions.content.video.inputs[0].key];
const getNextNode = (currNode, currQuestion, depth) => {
depth++;
if (typeof currQuestion === 'undefined' || (!!currQuestion.next && !!currQuestion.options)) {
if (typeof currQuestion === 'undefined' || (!!currQuestion.next && !!currQuestion.options) || (typeof currQuestion.ignore !== 'undefined')) {
return;
}
if (!!currQuestion.type && currQuestion.type === 'list') {
Object.keys(currQuestion.options).forEach((optionKey) => {
if (currQuestion.options[optionKey].ignore === true) {
return;
}
if (!currQuestion.options[optionKey].next) {
currNode.addChild(new TreeNode(currQuestion.options[optionKey].value,
currQuestion.key, depth));
Expand All @@ -78,6 +79,9 @@ class Tree {
getNextNode(nextNode, helper[currQuestion.next], depth);
}
};

this.rootNode = new TreeNode('root', 'root', 0);
const firstQuestion = helper[questions.content.video.inputs[0].key];
const firstNode = new TreeNode(helper[questions.content.video.inputs[0].key].defaultValue,
questions.content.video.inputs[0].key, 1);
this.rootNode.addChild(firstNode);
Expand All @@ -99,37 +103,37 @@ class Tree {
});
}

static buildScript(questions, path, idx) {
ejs.renderFile('./template.ejs', {
payload: {
inputs: path,
serviceType: questions.serviceType,
provider: questions.content.video.provider,
},
}, (ejsErr, str) => {
if (ejsErr) {
console.error(ejsErr);
return;
}
fs.writeFile(`output/${questions.serviceType}-${idx}.sh`, str, (fsErr) => {
if (fsErr) {
console.error(fsErr);
buildScript(questions) {
this.paths.forEach((path, idx) => {
ejs.renderFile('./template.ejs', {
payload: {
inputs: path,
serviceType: questions.serviceType,
provider: questions.content.video.provider,
},
}, (ejsErr, str) => {
if (ejsErr) {
console.error(ejsErr);
return;
}
fs.writeFile(`output/${questions.serviceType}-${idx}.sh`, str, (fsErr) => {
if (fsErr) {
console.error(fsErr);
}
});
});
});
}
}

// Entrypoint
// Entrypoint (node index.js)
servicesQuestions.forEach((question) => {
if (question.serviceType === 'livestream' || question.serviceType === 'ivs') {
console.info(`---Service ${question.serviceType}---`);
const tree = new Tree();
tree.buildTree(question, servicesHelpers[`${question.serviceType}`]);
tree.buildPaths(tree.rootNode, [], servicesHelpers[`${question.serviceType}`].content);
console.info('Number of permutations:', tree.paths.length);
tree.paths.forEach((val, idx) => {
tree.buildScript(question, val, idx);
});
tree.buildScript(question);
}
});
13 changes: 8 additions & 5 deletions scripts/gen-test-payload/test-helpers/livestream-helpers.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@
"options": {
"RTMP_PUSH": {
"next": "storageType",
"value": "RTMP_PUSH"
"value": "RTMP_PUSH",
"ignore": true
},
"RTP_PUSH": {
"next": "storageType",
"value": "RTP_PUSH"
},
"UDP_PUSH": {
"next": "storageType",
"value": "UDP_PUSH"
"value": "UDP_PUSH",
"ignore": true
},
"MP4_FILE": {
"next": "mp4URL",
"value": "MP4_FILE"
"value": "MP4_FILE",
"ignore": true
}
}
},
Expand Down Expand Up @@ -200,11 +203,11 @@
"type": "list",
"options": {
"mPackage": {
"next": "endpoint",
"next": "endpoints",
"value": "mPackage"
},
"mPackageStore": {
"next": "endpoint",
"next": "endpoints",
"value": "mPackageStore"
},
"mStore": {
Expand Down