-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write Test Case For Azure cli Action #48
Changes from 4 commits
70a2786
2e6ad25
1406d17
f44023b
1e73842
44a2a62
bf01cb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: ci-workflow | ||
on: | ||
workflow_dispatch: | ||
push: | ||
jobs: | ||
test_action_job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out source code | ||
uses: actions/checkout@v1 | ||
- uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
- run: npm install --production | ||
|
||
- run: sudo npm i -g ts-node | ||
- run: npm install typescript | ||
|
||
- name: Azure CLI Version test | ||
env: | ||
INPUT_AZCLIVERSION: 2.0.72 | ||
INPUT_INLINESCRIPT: | | ||
az account show | ||
az storage -h | ||
EXPECTED_TO: pass | ||
run: ts-node test/main.test.ts | ||
|
||
- name: Azure CLI Version Test - Negative | ||
env: | ||
INPUT_AZCLIVERSION: 0 | ||
INPUT_INLINESCRIPT: | | ||
az account show | ||
az storage -h | ||
EXPECTED_TO: fail | ||
run: ts-node test/main.test.ts | ||
|
||
- name: Inline Script Test - Negative | ||
env: | ||
INPUT_AZCLIVERSION: 2.0.72 | ||
INPUT_INLINESCRIPT: " " | ||
EXPECTED_TO: fail | ||
run: ts-node test/main.test.ts | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add post status action at the end
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ const BASH_ARG: string = `bash --noprofile --norc -e `; | |
const CONTAINER_WORKSPACE: string = '/github/workspace'; | ||
const CONTAINER_TEMP_DIRECTORY: string = '/_temp'; | ||
|
||
const run = async () => { | ||
|
||
export const run = async () => { | ||
var scriptFileName: string = ''; | ||
const CONTAINER_NAME = `MICROSOFT_AZURE_CLI_${getCurrentTime()}_CONTAINER`; | ||
try { | ||
|
@@ -21,15 +22,18 @@ const run = async () => { | |
} | ||
|
||
let inlineScript: string = core.getInput('inlineScript', { required: true }); | ||
let azcliversion: string = core.getInput('azcliversion', { required: true }).trim().toLowerCase(); | ||
|
||
let azcliversion: string = core.getInput('azcliversion', { required: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added .trim().toLowerCase() |
||
if (!(await checkIfValidCLIVersion(azcliversion))) { | ||
console.log("INVALID VERSION") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this console.log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
core.setFailed('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.') | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
if (!inlineScript.trim()) { | ||
core.setFailed('Please enter a valid script.'); | ||
throw new Error('Please enter a valid script.') | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
inlineScript = ` set -e >&2; echo '${START_SCRIPT_EXECUTION_MARKER}' >&2; ${inlineScript}`; | ||
|
@@ -66,6 +70,7 @@ const run = async () => { | |
} catch (error) { | ||
core.error(error); | ||
core.setFailed(error.stderr); | ||
throw error; | ||
} | ||
finally { | ||
// clean up | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { run } from "../src/main"; | ||
import * as core from '@actions/core'; | ||
|
||
run() | ||
.then(() => { | ||
checkOutcome('pass') | ||
}) | ||
.catch((e) => { | ||
core.error(e) | ||
checkOutcome('fail') | ||
}); | ||
|
||
function checkOutcome(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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace on with this -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done