Skip to content

Commit

Permalink
Merge pull request #4631 from Microsoft/users/biprasad/AzureVmssL0
Browse files Browse the repository at this point in the history
L0 tests for vmss task
  • Loading branch information
bishal-pdMSFT authored Jun 25, 2017
2 parents c06e957 + e1c0d22 commit 4089042
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 16 deletions.
8 changes: 8 additions & 0 deletions Tasks/AzureResourceGroupDeployment/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
],
"options": "-Rf"
}
],
"rm": [
{
"items": [
"node_modules/azure-arm-rest/node_modules/vsts-task-lib"
],
"options": "-Rf"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"loc.friendlyName": "Azure VM Scale set Deployment (PREVIEW)",
"loc.helpMarkDown": "[More Information](https://aka.ms/azurevmsstaskreadme)",
"loc.description": "Deploy virtual machine scale set image",
"loc.friendlyName": "Azure VM scale set Deployment (PREVIEW)",
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=852117)",
"loc.description": "Deploy Virtual Machine scale set image",
"loc.instanceNameFormat": "Azure VMSS $(vmssName): $(action)",
"loc.releaseNotes": "- Updates azure virtual machine scale set with a custom image.\n- Works with Xplat agents (Windows, Linux or OSX).",
"loc.releaseNotes": "- Updates Azure Virtual Machine scale set with a custom machine image.",
"loc.group.displayName.AzureDetails": "Azure Details",
"loc.group.displayName.Image": "Image Details",
"loc.input.label.ConnectedServiceName": "Azure subscription",
"loc.input.help.ConnectedServiceName": "Select the Azure Resource Manager subscription for the scale set.",
"loc.input.label.action": "Action",
"loc.input.help.action": "Action to be performed on the scale set.",
"loc.input.label.vmssName": "VMSS",
"loc.input.label.vmssName": "Virtual Machine scale set name",
"loc.input.help.vmssName": "Provide the name of scale set. Note that image can be updated only for a scale set which is running a custom image. If a scale set is using platform/gallery image, then image update operation will fail.",
"loc.input.label.imageUrl": "Image url",
"loc.input.help.imageUrl": "Specify the URL of image VHD. If it is a azure storage blob url, the storage account location should be same as scale set location.",
"loc.input.help.imageUrl": "Specify the URL of image VHD. If it is an Azure storage blob url, the storage account location should be same as scale set location.",
"loc.messages.InvalidAction": "This action is not defined. Check with the task author.",
"loc.messages.TaskNotFound": "Task.json file could not be found: %s",
"loc.messages.TaskConstructorFailed": "Task failed while initializing. Error: %s",
Expand Down
86 changes: 86 additions & 0 deletions Tasks/AzureVmssDeployment/Tests/L0.ts
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);
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4089042

Please sign in to comment.