export function getArtifactToolLocation(dirName: string): string { let toolPath: string = path.join(dirName, "ArtifactTool.exe"); if (tl.osType() !== "Windows_NT"){ toolPath = path.join(dirName, "artifacttool"); } return toolPath; }
export async function getArtifactToolFromService(serviceUri: string, accessToken: string, toolName: string){ let osName = tl.osType(); let arch = os.arch(); if(osName === "Windows_NT"){ osName = "windows"; } if (arch === "x64"){ arch = "amd64"; } const blobstoreAreaName = "clienttools"; const blobstoreAreaId = "187ec90d-dd1e-4ec6-8c57-937d979261e5"; const ApiVersion = "5.0-preview"; const blobstoreConnection = getWebApiWithProxy(serviceUri, accessToken); try{ const artifactToolGetUrl = await blobstoreConnection.vsoClient.getVersioningData(ApiVersion, blobstoreAreaName, blobstoreAreaId, { toolName }, {osName, arch}); const artifactToolUri = await blobstoreConnection.rest.get(artifactToolGetUrl.requestUrl); if (artifactToolUri.statusCode !== 200){ tl.debug(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolUri.toString())); throw new Error(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolGetUrl.requestUrl)); } let artifactToolPath = toollib.findLocalTool(toolName, artifactToolUri.result.version); if (!artifactToolPath) { tl.debug(tl.loc("Info_DownloadingArtifactTool", artifactToolUri.result.uri)); const zippedToolsDir: string = await toollib.downloadTool(artifactToolUri.result.uri); tl.debug("Downloaded zipped artifact tool to " + zippedToolsDir); const unzippedToolsDir = await extractZip(zippedToolsDir); artifactToolPath = await toollib.cacheDir(unzippedToolsDir, "ArtifactTool", artifactToolUri.result.version); } else{ tl.debug(tl.loc("Info_ResolvedToolFromCache", artifactToolPath)); } return getArtifactToolLocation(artifactToolPath); } catch(err){ tl.error(err); tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToGetArtifactTool", err)); } }
it('Runs successfully with XDT Transformation (L1)', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules","webdeployment-common","Tests","L1XdtTransform.js"); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); if(tl.osType().match(/^Win/)) { var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web_test.config'))); var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform','Web_Expected.config'))); assert(ltx.equal(resultFile, expectFile) , 'Should Transform attributes on Web.config'); } else { tl.warning('Cannot test XDT Transformation in Non Windows Agent'); } done(); });
describe('IISWebsiteDeploymentOnMachineGroup test suite', function() { var taskSrcPath = path.join(__dirname, '..','deployiiswebapp.js'); before((done) => { tl.cp(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web.config'), path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_test.config'), null, false); tl.cp(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web.Debug.config'), path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_test.Debug.config'), null, false); tl.cp(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web.config'), path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web_test.config'), null, false); tl.cp(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'parameters.xml'), path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'parameters_test.xml'), null, false); done(); }); after(function() { tl.rmRF(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web_test.config'), true); tl.rmRF(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_test.config'), true); tl.rmRF(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_Test.Debug.config'), true); tl.rmRF(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'parameters_test.xml'), true); }); if(!tl.osType().match(/^Win/)) { return; } it('Runs successfully with default inputs', (done:MochaDone) => { let tp = path.join(__dirname, 'L0WindowsDefault.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 1, 'should have invoked tool once'); assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, 'task should have succeeded'); done(); }); it('Runs successfully with all other inputs', (done) => { let tp = path.join(__dirname, 'L0WindowsAllInput.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 1, 'should have invoked tool once'); assert(tr.stderr.length == 0 && tr.errorIssues.length == 0, 'should not have written to stderr'); assert(tr.succeeded, 'task should have succeeded'); done(); }); it('Fails if msdeploy fails to execute', (done) => { let tp = path.join(__dirname, 'L0WindowsFailDefault.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); var expectedErr = 'Error: msdeploy failed with return code: 1'; assert(tr.invokedToolCount == 1, 'should have invoked tool once'); assert(tr.errorIssues.length > 0 || tr.stderr.length > 0, 'should have written to stderr'); assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'E should have said: ' + expectedErr); assert(tr.failed, 'task should have failed'); done(); }); it('Runs successfully with parameter file present in package', (done) => { let tp = path.join(__dirname, 'L0WindowsParamFileinPkg.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 1, 'should have invoked tool once'); assert(tr.stderr.length == 0 && tr.errorIssues.length == 0, 'should not have written to stderr'); assert(tr.succeeded, 'task should have succeeded'); done(); }); it('Fails if parameters file provided by user is not present', (done) => { let tp = path.join(__dirname, 'L0WindowsFailSetParamFile.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 0, 'should not have invoked any tool'); assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr'); var expectedErr = 'Error: loc_mock_SetParamFilenotfound0 invalidparameterFile.xml'; assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'should have said: ' + expectedErr); assert(tr.failed, 'task should have succeeded'); done(); }); it('Fails if more than one package matched with specified pattern', (done) => { let tp = path.join(__dirname, 'L0WindowsManyPackage.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 0, 'should not have invoked any tool'); assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr'); var expectedErr = 'Error: loc_mock_MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpatern'; assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'should have said: ' + expectedErr); assert(tr.failed, 'task should have failed'); done(); }); it('Fails if package or folder name is invalid', (done) => { let tp = path.join(__dirname, 'L0WindowsNoPackage.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 0, 'should not have invoked any tool'); assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr'); var expectedErr = 'Error: loc_mock_Nopackagefoundwithspecifiedpattern'; assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'should have said: ' + expectedErr); assert(tr.failed, 'task should have failed'); done(); }); it('Runs Successfully with XDT Transformation (Mock)', (done) => { this.timeout(1000); let tp = path.join(__dirname, 'L0WindowsXdtTransformation.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.invokedToolCount == 2, 'should have invoked tool twice'); let expectedErr = "loc_mock_XDTTransformationsappliedsuccessfully"; assert(tr.stdout.search(expectedErr) >= 0); assert(tr.stderr.length == 0 && tr.errorIssues.length == 0, 'should not have written to stderr'); assert(tr.succeeded, 'task should have succeeded'); done(); }); it('Fails if XDT Transformation throws error (Mock)', (done) => { let tp = path.join(__dirname, 'L0WindowsXdtTransformationFail.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); var expectedErr = 'Error: loc_mock_XdtTransformationErrorWhileTransforming C:\\tempFolder\\web.config C:\\tempFolder\\web.Release.config'; assert(tr.invokedToolCount == 1, 'should have invoked tool only once'); assert(tr.stderr.length > 0 || tr.errorIssues.length > 0, 'should have written to stderr'); assert(tr.stdErrContained(expectedErr) || tr.createdErrorIssue(expectedErr), 'E should have said: ' + expectedErr); assert(tr.failed, 'task should have failed'); done(); }); it('Runs successfully with XDT Transformation (L1)', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules","webdeployment-common","Tests","L1XdtTransform.js"); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); if(tl.osType().match(/^Win/)) { var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform', 'Web_test.config'))); var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XdtTransform','Web_Expected.config'))); assert(ltx.equal(resultFile, expectFile) , 'Should Transform attributes on Web.config'); } else { tl.warning('Cannot test XDT Transformation in Non Windows Agent'); } done(); }); it('Runs successfully with XML variable substitution', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XmlVarSub', 'Web_test.config'))); var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules","webdeployment-common","Tests", 'L1XmlVarSub', 'Web_Expected.config'))); assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.config file'); var resultFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_test.Debug.config'))); var expectFile = ltx.parse(fs.readFileSync(path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1XmlVarSub', 'Web_Expected.Debug.config'))); assert(ltx.equal(resultFile, expectFile) , 'Should have substituted variables in Web.Debug.config file'); done(); }); it('Runs successfully with JSON variable substitution', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1JsonVarSub.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.stdout.search('JSON - eliminating object variables validated') > 0, 'JSON - eliminating object variables validation error'); assert(tr.stdout.search('JSON - simple string change validated') > 0,'JSON -simple string change validation error' ); assert(tr.stdout.search('JSON - system variable elimination validated') > 0, 'JSON -system variable elimination validation error'); assert(tr.stdout.search('JSON - special variables validated') > 0, 'JSON - special variables validation error'); assert(tr.stdout.search('JSON - variables with dot character validated') > 0, 'JSON varaibles with dot character validated'); assert(tr.stdout.search('JSON - substitute inbuilt JSON attributes validated') > 0, 'JSON inbuilt variable substitution validation error'); assert(tr.succeeded, 'task should have succeeded'); done(); }); it('Validate File Encoding', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L1ValidateFileEncoding.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.stdout.search('UTF-8 with BOM validated') >= 0, 'Should have validated UTF-8 with BOM'); assert(tr.stdout.search('UTF-16LE with BOM validated') >= 0, 'Should have validated UTF-16LE with BOM'); assert(tr.stdout.search('UTF-16BE with BOM validated') >= 0, 'Should have validated UTF-16BE with BOM'); assert(tr.stdout.search('UTF-32LE with BOM validated') >= 0, 'Should have validated UTF-32LE with BOM'); assert(tr.stdout.search('UTF-32BE with BOM validated') >= 0, 'Should have validated UTF-32BE with BOM'); assert(tr.stdout.search('UTF-8 without BOM validated') >= 0, 'Should have validated UTF-8 without BOM'); assert(tr.stdout.search('UTF-16LE without BOM validated') >= 0, 'Should have validated UTF-16LE without BOM'); assert(tr.stdout.search('UTF-16BE without BOM validated') >= 0, 'Should have validated UTF-16BE without BOM'); assert(tr.stdout.search('UTF-32LE without BOM validated') >= 0, 'Should have validated UTF-32LE without BOM'); assert(tr.stdout.search('UTF-32BE without BOM validated') >= 0, 'Should have validated UTF-32BE without BOM'); assert(tr.stdout.search('Short File Buffer Error') >= 0, 'Should have validated short Buffer'); assert(tr.stdout.search('Unknown encoding type') >= 0, 'Should throw for Unknown File Buffer'); done(); }); it('Validate webdeployment-common.utility.copyDirectory()', (done:MochaDone) => { let tp = path.join(__dirname, "..", "node_modules", "webdeployment-common", "Tests", 'L0CopyDirectory.js'); let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(); assert(tr.stdout.search('## Copy Files Successful ##') >=0, 'should have copied the files'); assert(tr.stdout.search('## mkdir Successful ##') >= 0, 'should have created dir including dest folder'); done(); }); });
describe('Azure VMSS Deployment', function () { this.timeout(30000); before((done) => { done(); }); after(function () { }); if (tl.osType().match(/^Win/)) { it("should succeed if vmss image updated successfully", (done) => { let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); process.env["existingExtensionName"] = "extensionNameTest"; tr.run(); delete process.env["existingExtensionName"]; 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("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName 'cs.zip' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("storageAccounts.listKeys is called") > -1, "storage accounts should be listed"); assert(tr.stdout.indexOf("blobService.uploadBlobs is called with source C:\\users\\temp\\vstsvmss12345 and dest vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension extensionNameTest") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/file1") > -1, "vm extension should use correct file1"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/folder2/file2") > -1, "vm extension should use correct file2"); 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_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("should succeed if linux vmss image updated successfully", (done) => { process.env["_vmssOsType_"] = "Linux"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_vmssOsType_"]; 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("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.tar.gz of compression type targz from C:\\some\\dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: ./customScriptInvoker.sh 'cs.tar.gz' './\"set V'\"'\"'a\\\`r\\\$.sh\"' '\"first '\"'\"'arg'\"'\"'\" seco\\`nd\\$arg'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("blobService.uploadBlobs is called with source C:\\users\\temp\\vstsvmss12345 and dest vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.deleteMethod is called") == -1, "virtualMachineExtensions.deleteMethod function should not be called as no custom-script-linux extension is present"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss2 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/file1") > -1, "vm extension should use correct file1"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/folder2/file2") > -1, "vm extension should use correct file2"); assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called with RG: testrg2, VMSS: testvmss2 and imageurl : https://someurl") > -1, "virtualMachinesScaleSets.updateImage function should have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); 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, "updateImageOnWindowsAgent.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, "updateImageOnWindowsAgent.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, "updateImageOnWindowsAgent.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); }); it("should skip image update and update extension if image is already up-to-date", (done) => { process.env["imageUrlAlreadyUptoDate"] = "true"; process.env["existingExtensionName"] = "extensionNameTest"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["imageUrlAlreadyUptoDate"] = undefined; delete process.env["existingExtensionName"]; 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") > -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension extensionNameTest") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("VMSSImageAlreadyUptoDate") > -1, "message should point out that image is already upto date"); }, tr, done); }); it("should succeed even if listing old extensions fails", (done) => { process.env["extensionListFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["extensionListFailed"] = undefined; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate 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_GetVMSSExtensionsListFailed") >= -1, "ahould warn about list failure"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("should fail if installing extension fails", (done) => { process.env["extensionInstallFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["extensionInstallFailed"] = undefined; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension CustomScriptExtension") > -1, "virtualMachineExtensions.createOrUpdate 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 not have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_SettingVMExtensionFailed") > -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); it("should not remove extension if existing extensions are not custom script extension", (done) => { process.env["noExistingExtension"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["noExistingExtension"] = undefined; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.deleteMethod is called with resource testvmss1 and extension AzureVmssDeploymentTask") == -1, "virtualMachineExtensions.deleteMethod function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate 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_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("should update image but skip installing extension if image custom script is not specified", (done) => { process.env["customScriptNotSpecified"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["customScriptNotSpecified"] = undefined; 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") > -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") == -1, "virtualMachineExtensions.list function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension CustomScriptExtension") == -1, "virtualMachineExtensions.createOrUpdate function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "message should point out that image is already upto date"); }, tr, done); }); it("should use unarchived custom scripts if archiving fails", (done) => { process.env["_archivingFails_"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_archivingFails_"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName '' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("loc_mock_CustomScriptsArchivingFailed Error: Create archive failed with error - some error") > -1, "warning should be logged"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to coorect account and container"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("should use unarchived custom scripts if skipArchivingCustomScripts input is true", (done) => { process.env["_doNotArchive_"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_doNotArchive_"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir with'quote") == -1, "archive should not be created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName '' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("loc_mock_CustomScriptsArchivingFailed Error: Create archive failed with error - some error") >= -1, "warning should be logged"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to coorect account and container"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("should fail task if uploading custom scripts fails while listing keys", (done) => { process.env["_listAccessKeysFailed_"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_listAccessKeysFailed_"]; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("loc_mock_UploadingToStorageBlobsFailed You need permission to list keys") >= -1, "error should be logged"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); it("should fail task if uploading custom scripts fails", (done) => { process.env["_uploadingFails_"] = "true"; let tp = path.join(__dirname, "updateImageOnWindowsAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_archivingFails_"]; runValidations(() => { assert(tr.failed, "Should have succeeded"); assert(tr.stdout.indexOf("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("loc_mock_UploadingToStorageBlobsFailed Error while uploading blobs: some error") >= -1, "error should be logged"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); } else { it("[nix] should succeed if vmss image updated successfully", (done) => { let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); process.env["existingExtensionName"] = "extensionNameTest"; tr.run(); delete process.env["existingExtensionName"]; 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("Creating archive /users/temp/vstsvmss12345/cs.zip of compression type zip from /some/dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName 'cs.zip' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("storageAccounts.listKeys is called") > -1, "storage accounts should be listed"); assert(tr.stdout.indexOf("blobService.uploadBlobs is called with source /users/temp/vstsvmss12345 and dest vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension extensionNameTest") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/file1") > -1, "vm extension should use correct file1"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/folder2/file2") > -1, "vm extension should use correct file2"); 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_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should succeed if linux vmss image updated successfully", (done) => { process.env["_vmssOsType_"] = "Linux"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_vmssOsType_"]; 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("Creating archive /users/temp/vstsvmss12345/cs.tar.gz of compression type targz from /some/dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: ./customScriptInvoker.sh 'cs.tar.gz' './\"set V'\"'\"'a\\\`r\\\$.sh\"' '\"first '\"'\"'arg'\"'\"'\" seco\\`nd\\$arg'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("blobService.uploadBlobs is called with source /users/temp/vstsvmss12345 and dest vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to correct account and container"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.deleteMethod is called") == -1, "virtualMachineExtensions.deleteMethod function should not be called as no custom-script-linux extension is present"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss2 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/file1") > -1, "vm extension should use correct file1"); assert(tr.stdout.indexOf("custom script: teststorage1.blob.core.windows.net/vststasks/100-12345/200/5/folder1/folder2/file2") > -1, "vm extension should use correct file2"); assert(tr.stdout.indexOf("virtualMachinesScaleSets.updateImage is called with RG: testrg2, VMSS: testvmss2 and imageurl : https://someurl") > -1, "virtualMachinesScaleSets.updateImage function should have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should fail if failed to update VMSS image", (done) => { process.env["imageUpdateFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.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("[nix] should fail if failed to list VMSSs", (done) => { process.env["vmssListFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.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("[nix] should fail if failed to get matching VMSS", (done) => { process.env["noMatchingVmss"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.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); }); it("[nix] should skip image update and update extension if image is already up-to-date", (done) => { process.env["imageUrlAlreadyUptoDate"] = "true"; process.env["existingExtensionName"] = "extensionNameTest"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["imageUrlAlreadyUptoDate"] = undefined; delete process.env["existingExtensionName"]; 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") > -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension extensionNameTest") > -1, "virtualMachineExtensions.createOrUpdate function should have been called from azure-sdk"); assert(tr.stdout.indexOf("VMSSImageAlreadyUptoDate") > -1, "message should point out that image is already upto date"); }, tr, done); }); it("[nix] should succeed even if listing old extensions fails", (done) => { process.env["extensionListFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["extensionListFailed"] = undefined; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.deleteMethod is called with resource testvmss1 and extension AzureVmssDeploymentTask") == -1, "virtualMachineExtensions.deleteMethod function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate 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_GetVMSSExtensionsListFailed") >= -1, "ahould warn about list failure"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should fail if installing extension fails", (done) => { process.env["extensionInstallFailed"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["extensionInstallFailed"] = undefined; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension CustomScriptExtension") > -1, "virtualMachineExtensions.createOrUpdate 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 not have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_SettingVMExtensionFailed") > -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); it("[nix] should not remove extension if existing extensions are not custom script extension", (done) => { process.env["noExistingExtension"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["noExistingExtension"] = undefined; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") > -1, "virtualMachineExtensions.list function should have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.deleteMethod is called with resource testvmss1 and extension AzureVmssDeploymentTask") == -1, "virtualMachineExtensions.deleteMethod function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension AzureVmssDeploymentTask") > -1, "virtualMachineExtensions.createOrUpdate 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_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should update image but skip installing extension if image custom script is not specified", (done) => { process.env["customScriptNotSpecified"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); process.env["customScriptNotSpecified"] = undefined; 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") > -1, "virtualMachinesScaleSets.updateImage function should not be called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.list is called") == -1, "virtualMachineExtensions.list function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("virtualMachineExtensions.createOrUpdate is called with resource testvmss1 and extension CustomScriptExtension") == -1, "virtualMachineExtensions.createOrUpdate function should not have been called from azure-sdk"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "message should point out that image is already upto date"); }, tr, done); }); it("[nix] should use unarchived custom scripts if archiving fails", (done) => { process.env["_archivingFails_"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_archivingFails_"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("Creating archive /users/temp/vstsvmss12345/cs.zip of compression type zip from /some/dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName '' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("loc_mock_CustomScriptsArchivingFailed Error: Create archive failed with error - some error") >= -1, "warning should be logged"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to coorect account and container"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should use unarchived custom scripts if skipArchivingCustomScripts input is true", (done) => { process.env["_doNotArchive_"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_doNotArchive_"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("Creating archive C:\\users\\temp\\vstsvmss12345\\cs.zip of compression type zip from C:\\some\\dir with'quote") == -1, "archive should not be created"); assert(tr.stdout.indexOf("Invoker command: powershell ./100-12345/200/5/customScriptInvoker.ps1 -zipName '' -script '.\\\\\"\"\"de`$p``l o''y.ps1\"\"\"' -scriptArgs '\"\"\"first ''arg''\"\"\" seco``nd`$arg' -prefixPath '100-12345/200/5'") > -1, "invoker command should be correct"); assert(tr.stdout.indexOf("loc_mock_CustomScriptsArchivingFailed Error: Create archive failed with error - some error") >= -1, "warning should be logged"); assert(tr.stdout.indexOf("loc_mock_DestinationBlobContainer teststorage1.blob.core.windows.net/vststasks") > -1, "scripts should be uploaded to coorect account and container"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") > -1, "new extension should be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") > -1, "VMSS image should be updated"); }, tr, done); }); it("[nix] should fail task if uploading custom scripts fails", (done) => { process.env["_listAccessKeysFailed_"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_listAccessKeysFailed_"]; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("Creating archive /users/temp/vstsvmss12345/cs.zip of compression type zip from /some/dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("loc_mock_UploadingToStorageBlobsFailed You need permission to list keys") >= -1, "error should be logged"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); it("[nix] should fail task if uploading custom scripts fails", (done) => { process.env["_uploadingFails_"] = "true"; let tp = path.join(__dirname, "updateImageOnLinuxAgent.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["_archivingFails_"]; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("Creating archive /users/temp/vstsvmss12345/cs.zip of compression type zip from /some/dir") > -1, "archive should be correctly created"); assert(tr.stdout.indexOf("loc_mock_UploadingToStorageBlobsFailed Error while uploading blobs: some error") >= -1, "error should be logged"); assert(tr.stdout.indexOf("loc_mock_CustomScriptExtensionInstalled") == -1, "new extension should not be installed"); assert(tr.stdout.indexOf("loc_mock_UpdatedVMSSImage") == -1, "VMSS image should not be updated"); }, tr, done); }); } });
describe('VsTestPlatformToolInstaller Suite', function() { this.timeout(10000); if (!tl.osType().match(/^Win/)) { return; } before((done) => { done(); }); beforeEach((done) => { // Clear all inputs and other environment variables delete process.env[constants.vsTestToolsInstallerInstalledToolLocation]; delete process.env[constants.versionSelector]; delete process.env[constants.testPlatformVersion]; delete process.env[constants.downloadPath]; delete process.env[testConstants.expectedTestPlatformVersion]; delete process.env[testConstants.findLocalToolFirstCallReturnValue]; delete process.env[testConstants.findLocalToolSecondCallReturnValue]; delete process.env[testConstants.listPackagesReturnCode]; delete process.env[testConstants.listPackagesOutput]; delete process.env[constants.username]; delete process.env[constants.password]; delete process.env[testConstants.feedId]; delete process.env[constants.packageFeedSelector]; delete process.env[constants.customFeed]; delete process.env[testConstants.packageSource]; delete process.env[testConstants.configFile]; process.env[constants.packageFeedSelector] = constants.nugetOrg; process.env[testConstants.packageSource] = constants.defaultPackageSource; process.env[testConstants.writeNugetConfigReturnCode] = '0'; process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.downloadPath] = `${process.env[constants.agentTempDirectory]}\\VsTest`; done(); }); after(function () { // add code for cleanup if any }); // *************************************************** Nuget Org Tests ****************************************************** it('Get latest pre-release version cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache miss and download success', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[testConstants.expectedTestPlatformVersion]} from ${process.env[testConstants.packageSource]} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Caching the downloaded folder temp\\VsTest\\${constants.packageId}.${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have cached ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version listing failed but a stable version found in cache', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = 'x'; process.env[testConstants.listPackagesReturnCode] = '1'; process.env[testConstants.downloadPackageReturnCode] = '0'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\15.6.0`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[testConstants.findLocalToolFirstCallReturnValue]}.`), `Should have set variable to ${process.env[testConstants.findLocalToolFirstCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version listing failed but no stable version found in cache', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.listPackagesReturnCode] = '1'; process.env[testConstants.downloadPackageReturnCode] = '0'; process.env[testConstants.expectedTestPlatformVersion] = 'x'; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); it('Get latest pre-release version cache miss and download failed but fallback cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '1'; process.env[testConstants.findLocalToolSecondCallReturnValue] = `VsTest\\15.6.0`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[testConstants.expectedTestPlatformVersion]} from ${process.env[testConstants.packageSource]} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`TestPlatformDownloadFailed`), `Download should have failed`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[testConstants.findLocalToolSecondCallReturnValue]}.`), `Should have set variable to ${process.env[testConstants.findLocalToolSecondCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache miss and download failed and fallback cache miss', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '1'; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[testConstants.expectedTestPlatformVersion]} from ${process.env[testConstants.packageSource]} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`TestPlatformDownloadFailed`), `Download should have failed`); process.env[testConstants.expectedTestPlatformVersion] = 'x'; assert(tr.stdOutContained(`Cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); it('Get latest stable version cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestStable'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestStableVersion`), `Should have looked for latest stable version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest stable version listing empty and cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'latestStable'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = 'x'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\15.6.0`; process.env[testConstants.listPackagesOutput] = ''; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestStableVersion`), `Should have looked for latest stable version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[testConstants.findLocalToolFirstCallReturnValue]}.`), `Should have set variable to ${process.env[testConstants.findLocalToolFirstCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specific version cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'specificVersion'; process.env[constants.testPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specific version cache miss and download success', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.versionSelector] = 'specificVersion'; process.env[constants.testPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.downloadPackageReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[testConstants.expectedTestPlatformVersion]} from ${process.env[testConstants.packageSource]} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Caching the downloaded folder temp\\VsTest\\${constants.packageId}.${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have cached ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); // ***************************************************** Custom Feed Tests ************************************************************* it('Get latest pre-release version cache hit from custom feed no password', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somecustomfeed'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache hit from custom feed and password provided', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.password] = 'pattoken'; process.env[testConstants.feedId] = 'somefeedid'; process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somefeedid'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[testConstants.configFile] = `${process.env[constants.agentTempDirectory]}\\somefeedid.config`; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache hit from custom feed username and password provided', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.username] = 'someuser'; process.env[constants.password] = 'pattoken'; process.env[testConstants.feedId] = 'somefeedid'; process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somefeedid'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[testConstants.configFile] = `${process.env[constants.agentTempDirectory]}\\somefeedid.config`; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(constants.emptyNugetConfig), `Should have written skeleton nuget config file contents.`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Deleted file ${process.env[testConstants.configFile]}`), `Should have cleaned up the temp config file.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache miss and download success for custom feed with password', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.password] = 'pattoken'; process.env[testConstants.feedId] = 'somefeedid'; process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somefeedid'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[testConstants.configFile] = `${process.env[constants.agentTempDirectory]}\\somefeedid.config`; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[testConstants.expectedTestPlatformVersion]} from ${process.env[testConstants.packageSource]} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Caching the downloaded folder temp\\VsTest\\${constants.packageId}.${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have cached ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache hit from custom feed, password provided but writing config fails', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.password] = 'pattoken'; process.env[testConstants.feedId] = 'somefeedid'; process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somefeedid'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[testConstants.configFile] = `${process.env[constants.agentTempDirectory]}\\somefeedid.config`; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = 'x'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.writeNugetConfigReturnCode] = '1'; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`ConfigFileWriteFailed`), `Config file write should have failed and error message for it shown.`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache hit from custom feed, password provided but writing config fails and fallback cache lookup fails', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.password] = 'pattoken'; process.env[testConstants.feedId] = 'somefeedid'; process.env[constants.packageFeedSelector] = constants.customFeed; process.env[constants.customFeed] = 'somecustomfeed'; process.env[testConstants.packageSource] = 'somefeedid'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[testConstants.configFile] = `${process.env[constants.agentTempDirectory]}\\somefeedid.config`; process.env[constants.testPlatformVersion] = ''; process.env[testConstants.expectedTestPlatformVersion] = 'x'; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.writeNugetConfigReturnCode] = '1'; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`ConfigFileWriteFailed`), `Config file write should have failed and error message for it shown.`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); // ***************************************************** Network Share Tests ************************************************************* it('Get specified package from path provided from network share cache hit', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.netShare; process.env[testConstants.packageSource] = '\\somesharepath'; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[testConstants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; process.env[constants.netShare] = `\\\\somesharepath\\Microsoft.Testplatform.${process.env[testConstants.expectedTestPlatformVersion]}.nupkg`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specified package from path provided from network share cache miss and copy successful', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.netShare; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.netShare] = `\\\\somesharepath\\Microsoft.Testplatform.${process.env[testConstants.expectedTestPlatformVersion]}.nupkg`; process.env[testConstants.packageSource] = process.env[constants.netShare]; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specified package from path provided from network share cache miss share and copy unsuccessful but fallback cache lookup successful', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.netShare; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.netShare] = `\\\\somesharepath\\Microsoft.Testplatform.${process.env[testConstants.expectedTestPlatformVersion]}.nupkg`; process.env[testConstants.packageSource] = process.env[constants.netShare]; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '1'; process.env[testConstants.findLocalToolFirstCallReturnValue] = ``; process.env[testConstants.findLocalToolSecondCallReturnValue] = `VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specified package from path provided from network share cache miss and copy unsuccessful and fallback cache lookup unsuccessful', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.netShare; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.netShare] = `\\\\somesharepath\\Microsoft.Testplatform.${process.env[testConstants.expectedTestPlatformVersion]}.nupkg`; process.env[testConstants.packageSource] = process.env[constants.netShare]; process.env[testConstants.listPackagesReturnCode] = '0'; process.env[testConstants.downloadPackageReturnCode] = '1'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.failed, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[testConstants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[testConstants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[testConstants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); it('Get specified package from path provided from network share invalid filename', (done: MochaDone) => { // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.packageFeedSelector] = constants.netShare; process.env[testConstants.packageSource] = '\\somesharepath'; process.env[testConstants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.netShare] = `\\\\somesharepath\\Miiiicrosoft.Testplatform.${process.env[testConstants.expectedTestPlatformVersion]}.nupkg`; process.env[testConstants.listPackagesReturnCode] = '0'; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`UnexpectedFileName`)); done(); }); });
describe('DotNetCoreInstaller', function() { this.timeout(30000); before((done) => { done(); }); after(function() { }); if(tl.osType().match(/^Win/)) { it("[windows]should succeed if sdk installed successfully", (done) => { let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall sdk 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncs and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") > -1, "should install fresh if cache miss"); assert(tr.stdout.indexOf("Downloading tool from https://primary-url") > -1, "should download from correct url"); assert(tr.stdout.indexOf("Extracting zip archieve from C:\\agent\\_temp\\someArchieve") > -1, "Should extract downloaded archieve corectly"); assert(tr.stdout.indexOf("Caching dir C:\\agent\\_temp\\someDir for tool dncs version 1.0.4") > -1, "should cache correctly"); assert(tr.stdout.indexOf("loc_mock_SuccessfullyInstalled sdk 1.0.4") > -1, "should print installed tool info"); assert(tr.stdout.indexOf("prepending path: C:\\agent\\_tools\\cacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); it("[windows]should succeed if runtime installed successfully", (done) => { process.env["__package_type__"] = "runtime"; let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__package_type__"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall runtime 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncr and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") > -1, "should install fresh if cache miss"); assert(tr.stdout.indexOf("Downloading tool from https://primary-runtime-url") > -1, "should download from correct url"); assert(tr.stdout.indexOf("Extracting zip archieve from C:\\agent\\_temp\\someArchieve") > -1, "Should extract downloaded archieve corectly"); assert(tr.stdout.indexOf("Caching dir C:\\agent\\_temp\\someDir for tool dncr version 1.0.4") > -1, "should cache correctly"); assert(tr.stdout.indexOf("loc_mock_SuccessfullyInstalled runtime 1.0.4") > -1, "should print installed tool info"); assert(tr.stdout.indexOf("prepending path: C:\\agent\\_tools\\cacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); it("[windows]should not install again if cache hit", (done) => { process.env["__cache_hit__"] = "true"; let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__cache_hit__"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall sdk 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncs and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") == -1, "should not install fresh"); assert(tr.stdout.indexOf("loc_mock_GettingDownloadUrls") == -1, "should not download"); assert(tr.stdout.indexOf("loc_mock_UsingCachedTool") > -1, "should print that cached dir is being used"); assert(tr.stdout.indexOf("Caching dir C:\\agent\\_temp\\someDir for tool dncs version 1.0.4") == -1, "should not update cache again"); assert(tr.stdout.indexOf("prepending path: C:\\agent\\_tools\\oldCacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); it("[windows]should download using legacy url if primary url does not work", (done) => { process.env["__primary_url_failed__"] = "true"; let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__primary_url_failed__"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_PrimaryUrlDownloadFailed 404 not found https://primary-url") >= -1, "should print primary url failure error") assert(tr.stdout.indexOf("Downloading tool from https://legacy-url") > -1, "should download from legacy url"); }, tr, done); }); it("[windows]should fail if explicit version is not used", (done) => { process.env["__implicit_version__"] = "true"; let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__implicit_version__"]; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("loc_mock_ImplicitVersionNotSupported") > -1, "should print error message"); }, tr, done); }); it("[windows]should fail if getting download script fails", (done) => { process.env["__get_dlurls_failed__"] = "true"; let tp = path.join(__dirname, "InstallWindows.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__get_dlurls_failed__"]; runValidations(() => { assert(tr.failed, "Should have failed"); assert(tr.stdout.indexOf("loc_mock_getDownloadUrlsFailed install-script failed to get donwload urls") > -1, "should print error message"); assert(tr.stdout.indexOf("loc_mock_DownloadingPrimaryUrl") == -1, "should not proceed with downloading"); }, tr, done); }); } else { it("[nix]should succeed if sdk installed successfully", (done) => { let tp = path.join(__dirname, "InstallNix.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall sdk 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncs and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") > -1, "should install fresh if cache miss"); assert(tr.stdout.indexOf("Changing attribute for file /somedir/currdir/externals/install-dotnet.sh to 777") > -1, "should iset executable attribute for install script"); assert(tr.stdout.indexOf("Downloading tool from https://primary-url") > -1, "should download from correct url"); assert(tr.stdout.indexOf("Extracting tar archieve from /agent/_temp/someArchieve") > -1, "Should extract downloaded archieve corectly"); assert(tr.stdout.indexOf("Caching dir /agent/_temp/someDir for tool dncs version 1.0.4") > -1, "should cache correctly"); assert(tr.stdout.indexOf("loc_mock_SuccessfullyInstalled sdk 1.0.4") > -1, "should print installed tool info"); assert(tr.stdout.indexOf("prepending path: /agent/_tools/cacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); it("[nix]should succeed if runtime installed successfully", (done) => { process.env["__package_type__"] = "runtime"; let tp = path.join(__dirname, "InstallNix.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__package_type__"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall runtime 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncr and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") > -1, "should install fresh if cache miss"); assert(tr.stdout.indexOf("Downloading tool from https://primary-runtime-url") > -1, "should download from correct url"); assert(tr.stdout.indexOf("Extracting tar archieve from /agent/_temp/someArchieve") > -1, "Should extract downloaded archieve corectly"); assert(tr.stdout.indexOf("Caching dir /agent/_temp/someDir for tool dncr version 1.0.4") > -1, "should cache correctly"); assert(tr.stdout.indexOf("loc_mock_SuccessfullyInstalled runtime 1.0.4") > -1, "should print installed tool info"); assert(tr.stdout.indexOf("prepending path: /agent/_tools/cacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); it("[nix]should not install again if cache hit", (done) => { process.env["__cache_hit__"] = "true"; let tp = path.join(__dirname, "InstallNix.js"); let tr = new ttm.MockTestRunner(tp); tr.run(); delete process.env["__cache_hit__"]; runValidations(() => { assert(tr.succeeded, "Should have succeeded"); assert(tr.stdout.indexOf("loc_mock_ToolToInstall sdk 1.0.4") > -1, "should print to-be-installed info"); assert(tr.stdout.indexOf("Checking local tool for dncs and version 1.0.4") > -1, "should check for local cached tool"); assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") == -1, "should not install fresh"); assert(tr.stdout.indexOf("loc_mock_GettingDownloadUrls") == -1, "should not download"); assert(tr.stdout.indexOf("loc_mock_UsingCachedTool") > -1, "should print that cached dir is being used"); assert(tr.stdout.indexOf("Caching dir /agent/_temp/someDir for tool dncs version 1.0.4") == -1, "should not update cache again"); assert(tr.stdout.indexOf("prepending path: /agent/_tools/oldCacheDir") > -1, "should pre-prend to PATH"); }, tr, done); }); } });
describe('VsTestPlatformToolInstaller Suite', function() { this.timeout(10000); if (!tl.osType().match(/^Win/)) { return; } before((done) => { done(); }); beforeEach((done) => { // Clear all inputs and other environment variables delete process.env[constants.vsTestToolsInstallerInstalledToolLocation]; delete process.env[constants.versionSelector]; delete process.env[constants.testPlatformVersion]; delete process.env[constants.downloadPath]; delete process.env[constants.expectedTestPlatformVersion]; delete process.env[constants.findLocalToolFirstCallReturnValue]; delete process.env[constants.findLocalToolSecondCallReturnValue]; delete process.env[constants.listPackagesReturnCode]; delete process.env[constants.listPackagesOutput]; done(); }); after(function () { //console.log('after'); }); it('Get latest pre-release version cache hit', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version cache hit'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[constants.expectedTestPlatformVersion]}`; process.env[constants.listPackagesReturnCode] = 0; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[constants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[constants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache miss and download success', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version cache miss and download success'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.listPackagesReturnCode] = 0; process.env[constants.downloadPackageReturnCode] = 0; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[constants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[constants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[constants.expectedTestPlatformVersion]} from ${constants.packageSource} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Caching the downloaded folder temp\\VsTest\\${constants.packageName}.${process.env[constants.expectedTestPlatformVersion]}.`), `Should have cached ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version listing failed but a stable version found in cache', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version listing failed but a stable version found in cache'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = 'x'; process.env[constants.listPackagesReturnCode] = 1; process.env[constants.downloadPackageReturnCode] = 0; process.env[constants.findLocalToolFirstCallReturnValue] = `VsTest\\15.6.0`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[constants.expectedTestPlatformVersion]}`), `Should have been a cache hit for ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[constants.findLocalToolFirstCallReturnValue]}.`), `Should have set variable to ${process.env[constants.findLocalToolFirstCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version listing failed but no stable version found in cache', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version listing failed but no stable version found in cache'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.listPackagesReturnCode] = 1; process.env[constants.downloadPackageReturnCode] = 0; process.env[constants.expectedTestPlatformVersion] = 'x'; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache miss for ${process.env[constants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); it('Get latest pre-release version cache miss and download failed but fallback cache hit', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version cache miss and download failed but fallback cache hit'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.listPackagesReturnCode] = 0; process.env[constants.downloadPackageReturnCode] = 1; process.env[constants.findLocalToolSecondCallReturnValue] = `VsTest\\15.6.0`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[constants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[constants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[constants.expectedTestPlatformVersion]} from ${constants.packageSource} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`TestPlatformDownloadFailed`), `Download should have failed`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[constants.findLocalToolSecondCallReturnValue]}.`), `Should have set variable to ${process.env[constants.findLocalToolSecondCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest pre-release version cache miss and download failed and fallback cache miss', (done: MochaDone) => { console.log('TestCaseName: Get latest pre-release version cache miss and download failed and fallback cache miss'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestPreRelease'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.listPackagesReturnCode] = 0; process.env[constants.downloadPackageReturnCode] = 1; // Start the run tr.run(); // Asserts assert(tr.stderr.length !== 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.failed, `Task should have failed`); assert(tr.stdOutContained(`LookingForLatestPreReleaseVersion`), `Should have looked for latest pre-release version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[constants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[constants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[constants.expectedTestPlatformVersion]} from ${constants.packageSource} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`TestPlatformDownloadFailed`), `Download should have failed`); process.env[constants.expectedTestPlatformVersion] = 'x'; assert(tr.stdOutContained(`Cache miss for ${process.env[constants.expectedTestPlatformVersion]}`), `Should have been a cache miss for ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained('NoPackageFoundInCache'), `Should warn no stable package found in cache`); assert(tr.stdOutContained('FailedToAcquireTestPlatform'), `Should fail with failed to acquire test platform`); done(); }); it('Get latest stable version cache hit', (done: MochaDone) => { console.log('TestCaseName: Get latest stable version cache hit'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestStable'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0'; process.env[constants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[constants.expectedTestPlatformVersion]}`; process.env[constants.listPackagesReturnCode] = 0; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestStableVersion`), `Should have looked for latest stable version.`); assert(tr.stdOutContained(`Found the latest version to be ${process.env[constants.expectedTestPlatformVersion]}.`), `Should have found latest version to be ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[constants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get latest stable version listing empty and cache hit', (done: MochaDone) => { console.log('TestCaseName: Get latest stable version listing empty and cache hit'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'latestStable'; process.env[constants.testPlatformVersion] = ''; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = 'x'; process.env[constants.listPackagesReturnCode] = 0; process.env[constants.findLocalToolFirstCallReturnValue] = `VsTest\\15.6.0`; process.env[constants.listPackagesOutput] = ''; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`LookingForLatestStableVersion`), `Should have looked for latest stable version.`); assert(tr.stdOutContained(`FailedToListAvailablePackagesFromNuget`), `Listing packages should have failed.`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[constants.expectedTestPlatformVersion]}`), `Should have been a cache hit for ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to ${process.env[constants.findLocalToolFirstCallReturnValue]}.`), `Should have set variable to ${process.env[constants.findLocalToolFirstCallReturnValue]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specific version cache hit', (done: MochaDone) => { console.log('TestCaseName: Get specific version cache hit'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'specificVersion'; process.env[constants.testPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.findLocalToolFirstCallReturnValue] = `VsTest\\${process.env[constants.expectedTestPlatformVersion]}`; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Cache hit for ${process.env[constants.expectedTestPlatformVersion]}`), `Expected a cache hit.`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); it('Get specific version cache miss and download success', (done: MochaDone) => { console.log('TestCaseName: Get specific version cache miss and download success'); // Setup the mock runner const tp = path.join(__dirname, 'TestSetup.js'); const tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp); // Set the inputs process.env[constants.agentTempDirectory] = 'temp'; process.env[constants.versionSelector] = 'specificVersion'; process.env[constants.testPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.downloadPath] = 'temp\\VsTest'; process.env[constants.expectedTestPlatformVersion] = '15.6.0-preview-20171108-02'; process.env[constants.downloadPackageReturnCode] = 0; // Start the run tr.run(); // Asserts assert(tr.stderr.length === 0 || tr.errorIssues.length, 'should not have written to stderr'); assert(tr.succeeded, `Task should have succeeded`); assert(tr.stdOutContained(`Looking for version ${process.env[constants.expectedTestPlatformVersion]} in the tools cache.`), `Should have looked for ${process.env[constants.expectedTestPlatformVersion]} in the cache.`); assert(tr.stdOutContained(`Could not find Microsoft.TestPlatform.${process.env[constants.expectedTestPlatformVersion]} in the tools cache. Fetching it from nuget.`), `Should have encountered a cache miss for ${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained(`Downloading Test Platform version ${process.env[constants.expectedTestPlatformVersion]} from ${constants.packageSource} to ${process.env[constants.downloadPath]}.`), `Should have attempted download of version ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Caching the downloaded folder temp\\VsTest\\${constants.packageName}.${process.env[constants.expectedTestPlatformVersion]}.`), `Should have cached ${process.env[constants.expectedTestPlatformVersion]}`); assert(tr.stdOutContained(`Set variable VsTestToolsInstallerInstalledToolLocation value to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`), `Should have set variable to VsTest\\${process.env[constants.expectedTestPlatformVersion]}.`); assert(tr.stdOutContained('InstallationSuccessful')); done(); }); });