-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4631 from Microsoft/users/biprasad/AzureVmssL0
L0 tests for vmss task
- Loading branch information
Showing
10 changed files
with
480 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
Tasks/AzureVmssDeployment/Strings/resources.resjson/en-US/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const ttm = require('vsts-task-lib/mock-test'); | ||
const path = require('path'); | ||
|
||
function setResponseFile(name) { | ||
process.env['MOCK_RESPONSES'] = path.join(__dirname, name); | ||
} | ||
|
||
function runValidations(validator: () => void, tr, done) { | ||
try { | ||
validator(); | ||
done(); | ||
} | ||
catch (error) { | ||
console.log("STDERR", tr.stderr); | ||
console.log("STDOUT", tr.stdout); | ||
done(error); | ||
} | ||
} | ||
|
||
describe('Azure VMSS Deployment', function () { | ||
this.timeout(30000); | ||
before((done) => { | ||
done(); | ||
}); | ||
after(function () { | ||
}); | ||
it("should succeed if vmss image updated successfully", (done) => { | ||
let tp = path.join(__dirname, "updateImage.js"); | ||
let tr = new ttm.MockTestRunner(tp); | ||
tr.run(); | ||
runValidations(() => { | ||
assert(tr.succeeded, "Should have succeeded"); | ||
assert(tr.stdout.indexOf("virtualMachineScaleSets.list is called") > -1, "virtualMachineScaleSets.list function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called with RG: testrg1, VMSS: testvmss1 and imageurl : https://someurl") > -1, "virtualMachinesScaleSets.updateImage function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); | ||
}, tr, done); | ||
}); | ||
|
||
it("should fail if failed to update VMSS image", (done) => { | ||
process.env["imageUpdateFailed"] = "true"; | ||
let tp = path.join(__dirname, "updateImage.js"); | ||
let tr = new ttm.MockTestRunner(tp); | ||
tr.run(); | ||
process.env["imageUpdateFailed"] = undefined; | ||
|
||
runValidations(() => { | ||
assert(tr.failed, "Should have failed"); | ||
assert(tr.stdout.indexOf("virtualMachineScaleSets.list is called") > -1, "virtualMachineScaleSets.list function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called") > -1, "virtualMachinesScaleSets.updateImage function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("loc_mock_VMSSImageUpdateFailed") > -1, "VMSS image update should fail"); | ||
}, tr, done); | ||
}); | ||
|
||
it("should fail if failed to list VMSSs", (done) => { | ||
process.env["vmssListFailed"] = "true"; | ||
let tp = path.join(__dirname, "updateImage.js"); | ||
let tr = new ttm.MockTestRunner(tp); | ||
tr.run(); | ||
process.env["vmssListFailed"] = undefined; | ||
|
||
runValidations(() => { | ||
assert(tr.failed, "Should have failed"); | ||
assert(tr.stdout.indexOf("virtualMachineScaleSets.list is called") > -1, "virtualMachineScaleSets.list function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called") == -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); | ||
assert(tr.stdout.indexOf("loc_mock_VMSSListFetchFailed") > -1, "VMSS list should be failed"); | ||
}, tr, done); | ||
}); | ||
|
||
it("should fail if failed to get matching VMSS", (done) => { | ||
process.env["noMatchingVmss"] = "true"; | ||
let tp = path.join(__dirname, "updateImage.js"); | ||
let tr = new ttm.MockTestRunner(tp); | ||
tr.run(); | ||
process.env["noMatchingVmss"] = undefined; | ||
|
||
runValidations(() => { | ||
assert(tr.failed, "Should have failed"); | ||
assert(tr.stdout.indexOf("virtualMachineScaleSets.list is called") > -1, "virtualMachineScaleSets.list function should have been called from azure-sdk"); | ||
assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called") == -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); | ||
assert(tr.stdout.indexOf("loc_mock_FailedToGetRGForVMSS") > -1, "VMSS list should be failed"); | ||
}, tr, done); | ||
}); | ||
}); |
176 changes: 176 additions & 0 deletions
176
Tasks/AzureVmssDeployment/Tests/mock_node_modules/azure-arm-compute/LICENSE.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
Tasks/AzureVmssDeployment/Tests/mock_node_modules/azure-arm-compute/README.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.