Skip to content

Commit

Permalink
[cherrypick] DownloadPackageV1 - Fix successful result status on down…
Browse files Browse the repository at this point in the history
…load failure (#14568)

* Handle the case of pkg download error in DownloadPackageV1 task.

* Remove only token variable for DownloadPackageV1 tests.

* Bump patch version.
  • Loading branch information
ByAgenT authored Mar 11, 2021
1 parent 2625de6 commit f86124a
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 21 deletions.
15 changes: 15 additions & 0 deletions Tasks/DownloadPackageV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ describe("Download single file package suite", function() {

done();
});

it("tries to download npm package, but gets download error", (done: MochaDone) => {
this.timeout(1000);

let tp: string = path.join(__dirname, "L0DownloadNpmPackageDownloadError.js");

let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stderr.length === 0, "should not have written to stderr");
assert(tr.failed, "task should have failed");

done();
});
});

describe("Download multi file package suite", function() {
Expand Down
2 changes: 0 additions & 2 deletions Tasks/DownloadPackageV1/Tests/L0DownloadMultiFilePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ tr.setInput("verbosity", "verbose");
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
2 changes: 0 additions & 2 deletions Tasks/DownloadPackageV1/Tests/L0DownloadNpmPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
54 changes: 54 additions & 0 deletions Tasks/DownloadPackageV1/Tests/L0DownloadNpmPackageDownloadError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import tmrm = require("azure-pipelines-task-lib/mock-run");
import path = require("path");
import { WebApiMock } from "./helpers/webapimock";

let taskPath = path.join(__dirname, "..", "main.js");
let outputPath: string = path.join(__dirname, "out", "packageOutput");
let tempPath: string = path.join(__dirname, "temp");
let zipLocation: string = path.join(tempPath, "singlePackageName.tgz");
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// Set inputs
tr.setInput("packageType", "npm");
tr.setInput("feed", "feedId");
tr.setInput("view", "viewId");
tr.setInput("definition", "6f598cbe-a5e2-4f75-aa78-e0fd08301a15");
tr.setInput("version", "versionId");
tr.setInput("downloadPath", outputPath);
tr.setInput("extract", "true");
tr.setInput("verbosity", "verbose");

// Set variables.
process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";

// provide answers for task mock
tr.setAnswers({
exist: {
[outputPath]: true,
[tempPath]: true
},
rmRF: {
[zipLocation]: {
success: true
}
}
});

// Register connections mock
tr.registerMock("./connections", {
getConnection: function(): Promise<any> {
return Promise.resolve(new WebApiMock());
}
});

tr.registerMock("./package", {
download: async function(): Promise<any> {
throw "download error";
}
})


tr.run();
2 changes: 0 additions & 2 deletions Tasks/DownloadPackageV1/Tests/L0DownloadNugetPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ tr.setInput("verbosity", "verbose");
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ process.env["AGENT_TEMPDIRECTORY"] = tempPath;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://abc.visualstudio.com/";
process.env["AGENT_VERSION"] = "2.116.0";
process.env["HOME"] = "/users/test";
process.env["ENDPOINT_AUTH_SYSTEMVSSCONNECTION"] =
'{"scheme":"OAuth","parameters":{"AccessToken":"YWFtYWxsYWQ6ZXd0emE1bmN3MzN6c3lyM2NoN2prazUzejczamN6MnluNGtiNzd0ZXc0NnlhZzV2d3ZlcQ=="}}';

// provide answers for task mock
tr.setAnswers({
Expand Down
9 changes: 4 additions & 5 deletions Tasks/DownloadPackageV1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ async function main(): Promise<void> {
}

const packageFiles: PackageFile[] = await p.download(feed.feedId, feed.projectId, packageId, version, downloadPath, extractPackage);

return await Promise.all(
packageFiles.map(p => p.process()))
.then(() => tl.setResult(tl.TaskResult.Succeeded, ""))
.catch(error => tl.setResult(tl.TaskResult.Failed, error));

await Promise.all(packageFiles.map((p) => p.process()));
tl.setResult(tl.TaskResult.Succeeded, "");
} catch (error) {
tl.setResult(tl.TaskResult.Failed, error);
} finally {
logTelemetry({
PackageType: packageType,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadPackageV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 1,
"Minor": 183,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "Adds support to download Maven, Python, Universal and Npm packages.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadPackageV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 1,
"Minor": 183,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down

0 comments on commit f86124a

Please sign in to comment.