Updated tests and main to resolve negative test issues

This commit is contained in:
Deepak Dahiya 2022-10-25 20:48:43 +00:00
Родитель 9a159bda93
Коммит 547c91c0a9
2 изменённых файлов: 16 добавлений и 19 удалений

Просмотреть файл

@ -12,7 +12,7 @@ const START_SCRIPT_EXECUTION_MARKER: string = `Starting script execution via doc
const BASH_ARG: string = `bash --noprofile --norc -e `;
const AZ_CLI_VERSION_DEFAULT_VALUE = 'agentazcliversion'
export const run = async () => {
export async function main(){
var scriptFileName: string = '';
const CONTAINER_NAME = `MICROSOFT_AZURE_CLI_${getCurrentTime()}_CONTAINER`;
try {
@ -39,12 +39,12 @@ export const run = async () => {
}
if (!(await checkIfValidCLIVersion(azcliversion))) {
core.setFailed('Please enter a valid azure cli version. \nSee available versions: https://github.com/Azure/azure-cli/releases.');
core.error('Please enter a valid azure cli version. \nSee available versions: https://github.com/Azure/azure-cli/releases.');
throw new Error('Please enter a valid azure cli version. \nSee available versions: https://github.com/Azure/azure-cli/releases.')
}
if (!inlineScript.trim()) {
core.setFailed('Please enter a valid script.');
core.error('Please enter a valid script.');
throw new Error('Please enter a valid script.')
}
inlineScript = ` set -e >&2; echo '${START_SCRIPT_EXECUTION_MARKER}' >&2; ${inlineScript}`;
@ -75,7 +75,6 @@ export const run = async () => {
console.log("az script ran successfully.");
} catch (error) {
core.error(error);
core.setFailed(error.stderr);
throw error;
}
finally {
@ -155,5 +154,3 @@ const executeDockerCommand = async (dockerCommand: string, continueOnError: bool
core.warning(errorStream)
}
}
run();

Просмотреть файл

@ -1,20 +1,20 @@
import { run } from "../src/main";
import { main } from "../src/main";
import * as core from '@actions/core';
run()
.then(() => {
checkOutcome('pass')
})
.catch((e) => {
core.error(e)
checkOutcome('fail')
});
// Unit Tests
export async function runTests() {
try {
let result = await main()
return 'pass'
} catch (e) {
core.error(JSON.stringify(e))
return 'fail'
}
}
function checkOutcome(outcome){
runTests().then(outcome => {
if(outcome != process.env.EXPECTED_TO){
core.error(`Expected outcome did not meet the real outcome. Expected value: ${process.env.EXPECTED_TO}, actual value: ${outcome}`)
process.exit(1)
} else{
process.exit(0)
}
}
})