diff --git a/Tasks/JavaToolInstallerV0/Tests/L0.ts b/Tasks/JavaToolInstallerV0/Tests/L0.ts index 8d6e7be6a061..b392114a571d 100644 --- a/Tasks/JavaToolInstallerV0/Tests/L0.ts +++ b/Tasks/JavaToolInstallerV0/Tests/L0.ts @@ -21,7 +21,7 @@ describe('JavaToolInstaller L0 Suite', function () { it('should run successfully when fetching JDK files from azure storage', function () { this.timeout(20000); - const testPath: string = path.join(__dirname, 'L0DownloadArtifactsFromAzureStorage.js'); + const testPath: string = path.join(__dirname, 'L0DownloadsJdkFromAzureStorage.js'); const testRunner: ttm.MockTestRunner = new ttm.MockTestRunner(testPath); testRunner.run(); @@ -29,6 +29,18 @@ describe('JavaToolInstaller L0 Suite', function () { assert(testRunner.succeeded, 'task should have succeeded.'); }); + it('should run successfully when fetching JDK files from azure storage from subfolder', function () { + this.timeout(20000); + + const testPath: string = path.join(__dirname, 'L0DownloadsJdkFromAzureStorageSubFolder.js'); + const testRunner: ttm.MockTestRunner = new ttm.MockTestRunner(testPath); + + testRunner.run(); + + assert((testRunner.stdOutContained('jdkFileName: DestinationDirectory\\JDKname.tar.gz') || testRunner.stdOutContained('jdkFileName: DestinationDirectory/JDKname.tar.gz')) , 'JDK archive should unpack in the right destination directory'); + assert(testRunner.succeeded, 'task should have succeeded.'); + }); + it('should fail when JavaToolInstaller is run with to destination folder specified', function () { this.timeout(20000); diff --git a/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorage.ts b/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorage.ts index e82008057c4b..c2e7c681bda9 100644 --- a/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorage.ts +++ b/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorage.ts @@ -1,5 +1,6 @@ import ma = require('azure-pipelines-task-lib/mock-answer'); import tmrm = require('azure-pipelines-task-lib/mock-run'); +import msRestAzure = require('azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-common'); import path = require('path'); import mockTask = require('azure-pipelines-task-lib/mock-task'); @@ -12,10 +13,13 @@ tr.setInput("jdkArchitectureOption", "x64"); tr.setInput("azureResourceManagerEndpoint", "ARM1"); tr.setInput("azureStorageAccountName", "storage1"); tr.setInput("azureContainerName", "container1"); -tr.setInput("azureCommonVirtualFile", ""); -tr.setInput("jdkDestinationDirectory", "javaJDK"); +tr.setInput("azureCommonVirtualFile", "JDKname.tar.gz"); +tr.setInput("jdkDestinationDirectory", "DestinationDirectory"); tr.setInput("cleanDestinationDirectory", "false"); +process.env['AGENT_TOOLSDIRECTORY'] = '/tool'; +process.env['AGENT_VERSION'] = '2.194.0'; + process.env['ENDPOINT_URL_ID1'] = 'http://url'; process.env['ENDPOINT_AUTH_PARAMETER_connection1_username'] = 'dummyusername'; process.env['ENDPOINT_AUTH_PARAMETER_connection1_password'] = 'dummypassword'; @@ -29,7 +33,19 @@ process.env['ENDPOINT_DATA_ARM1_environmentAuthorityUrl'] = 'dummyurl'; process.env['ENDPOINT_DATA_ARM1_activeDirectoryServiceEndpointResourceId'] = 'dummyResourceId'; process.env['ENDPOINT_DATA_ARM1_subscriptionId'] = 'dummySubscriptionId'; -tr.registerMock("azure-pipelines-tasks-azure-arm-rest/azure-arm-storage", { +const a: ma.TaskLibAnswers = { + "stats": { + "DestinationDirectory\\JDKname.tar.gz": true, + "DestinationDirectory/JDKname.tar.gz": true, + }, + "find": { + "DestinationDirectory": ["rootJDK/", "rootJDK/secondlevelJDK2"], + }, +}; + +tr.setAnswers(a); + +tr.registerMock("azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-storage", { StorageManagementClient: function (A, B) { return { storageAccounts: { @@ -56,10 +72,48 @@ tr.registerMock("azure-pipelines-tasks-azure-arm-rest/azure-arm-storage", { } }); -tr.registerMock("azure-pipelines-tasks-azure-arm-rest/azure-arm-common", { +tr.registerMock("azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-common", { ApplicationTokenCredentials: function(A,B,C,D,E,F,G) { return {}; } }); +tr.registerMock('./AzureStorageArtifacts/AzureStorageArtifactDownloader',{ + AzureStorageArtifactDownloader: function(A,B,C) { + return { + downloadArtifacts: function(A,B) { + return "pathFromDownloader"; + } + } + } +}) + +const mtl = require("azure-pipelines-tool-lib/tool") +const mtlClone = Object.assign({}, mtl); + +mtlClone.prependPath = function(variable1: string, variable2: string) { + return {}; +}; + +tr.registerMock("azure-pipelines-tool-lib/tool", mtlClone); + +const mfs = require('fs') +const mfsClone = Object.assign({}, mfs); + +mfsClone.lstatSync = function(variable: string) { + return { + isDirectory: function() { + return true; + } + }; +}; + +mfsClone.existsSync = function (variable: string) { + if (variable === "DestinationDirectory\\econdlevelJDK2" || variable === "DestinationDirectory/econdlevelJDK2") { + return false; + } else return true; +} + +tr.registerMock('fs', mfsClone); + tr.run(); diff --git a/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorageSubFolder.ts b/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorageSubFolder.ts new file mode 100644 index 000000000000..028d013e8d46 --- /dev/null +++ b/Tasks/JavaToolInstallerV0/Tests/L0DownloadsJdkFromAzureStorageSubFolder.ts @@ -0,0 +1,120 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import msRestAzure = require('azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-common'); +import path = require('path'); +import mockTask = require('azure-pipelines-task-lib/mock-task'); + + +const taskPath = path.join(__dirname, '..', 'javatoolinstaller.js'); +const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput("versionSpec", "8.1"); +tr.setInput("jdkSourceOption", "AzureStorage") +tr.setInput("jdkArchitectureOption", "x64"); +tr.setInput("azureResourceManagerEndpoint", "ARM1"); +tr.setInput("azureStorageAccountName", "storage1"); +tr.setInput("azureContainerName", "container1"); +tr.setInput("azureCommonVirtualFile", "folder/JDKname.tar.gz"); +tr.setInput("jdkDestinationDirectory", "DestinationDirectory"); +tr.setInput("cleanDestinationDirectory", "true"); + +process.env['AGENT_TOOLSDIRECTORY'] = '/tool'; +process.env['AGENT_VERSION'] = '2.194.0'; + +process.env['ENDPOINT_URL_ID1'] = 'http://url'; +process.env['ENDPOINT_AUTH_PARAMETER_connection1_username'] = 'dummyusername'; +process.env['ENDPOINT_AUTH_PARAMETER_connection1_password'] = 'dummypassword'; +process.env['ENDPOINT_DATA_ID1_acceptUntrustedCerts'] = 'true'; + +process.env['ENDPOINT_URL_ARM1'] = 'http://url'; +process.env['ENDPOINT_AUTH_PARAMETER_connection1_serviceprincipalid'] = 'dummyid'; +process.env['ENDPOINT_AUTH_PARAMETER_connection1_serviceprincipalkey'] = 'dummykey'; +process.env['ENDPOINT_AUTH_PARAMETER_connection1_tenantid'] = 'dummyTenantid'; +process.env['ENDPOINT_DATA_ARM1_environmentAuthorityUrl'] = 'dummyurl'; +process.env['ENDPOINT_DATA_ARM1_activeDirectoryServiceEndpointResourceId'] = 'dummyResourceId'; +process.env['ENDPOINT_DATA_ARM1_subscriptionId'] = 'dummySubscriptionId'; + +const a: ma.TaskLibAnswers = { + "stats": { + "DestinationDirectory\\JDKname.tar.gz": true, + "DestinationDirectory/JDKname.tar.gz": true, + }, + "find": { + "DestinationDirectory": ["rootJDK/", "rootJDK/secondlevelJDK2"], + }, +}; + +tr.setAnswers(a); + +tr.registerMock("azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-storage", { + StorageManagementClient: function (A, B) { + return { + storageAccounts: { + get: function (A) { + return { + properties: { + primaryEndpoints: { + blob: "primaryBlobUrl" + } + }, + id: "StorageAccountUrl" + } + }, + listkeys: function (A, B, C) { + return ["accesskey1", "accessKey2"]; + } + } + } + }, + StorageAccounts: { + getResourceGroupNameFromUri: function (A) { + return "storageAccountResouceGroupName"; + } + } +}); + +tr.registerMock("azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-common", { + ApplicationTokenCredentials: function(A,B,C,D,E,F,G) { + return {}; + } +}); + +tr.registerMock('./AzureStorageArtifacts/AzureStorageArtifactDownloader',{ + AzureStorageArtifactDownloader: function(A,B,C) { + return { + downloadArtifacts: function(A,B) { + return "pathFromDownloader"; + } + } + } +}) + +const mtl = require("azure-pipelines-tool-lib/tool") +const mtlClone = Object.assign({}, mtl); + +mtlClone.prependPath = function(variable1: string, variable2: string) { + return {}; +}; + +tr.registerMock("azure-pipelines-tool-lib/tool", mtlClone); + +const mfs = require('fs') +const mfsClone = Object.assign({}, mfs); + +mfsClone.lstatSync = function(variable: string) { + return { + isDirectory: function() { + return true; + } + }; +}; + +mfsClone.existsSync = function (variable: string) { + if (variable === "DestinationDirectory\\econdlevelJDK2" || variable === "DestinationDirectory/econdlevelJDK2" ) { + return false; + } else return true; +} + +tr.registerMock('fs', mfsClone); + +tr.run(); diff --git a/Tasks/JavaToolInstallerV0/javatoolinstaller.ts b/Tasks/JavaToolInstallerV0/javatoolinstaller.ts index 00d1dd6badee..90563ffa12eb 100644 --- a/Tasks/JavaToolInstallerV0/javatoolinstaller.ts +++ b/Tasks/JavaToolInstallerV0/javatoolinstaller.ts @@ -64,7 +64,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom await taskutils.sleepFor(250); //Wait for the file to be released before extracting it. let jdkArchiveName = path.basename(fileNameAndPath); jdkFileName = path.join(extractLocation, jdkArchiveName); - toolLib.debug('jdkFileName: ${jdkFileName}'); + toolLib.debug(`jdkFileName: ${jdkFileName}`); } else { // get from local directory console.log(taskLib.loc('RetrievingJdkFromLocalPath'));