Skip to content

Commit

Permalink
NuGetCommand multipleServiceConnection L0
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Spillman committed Jun 13, 2017
1 parent 2c15f68 commit 707c8fe
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tasks/NuGetCommand/Common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf
switch(scheme) {
case "token":
let token = externalAuth.parameters["apitoken"];
tl.debug("adding token auth entry for feed " + feedUri);
externalAuthArray.push(new auth.TokenExternalAuthInfo(<IPackageSource>
{
feedName: feedName,
Expand All @@ -67,6 +68,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf
case "usernamepassword":
let username = externalAuth.parameters["username"];
let password = externalAuth.parameters["password"];
tl.debug("adding password auth entry for feed " + feedUri);
externalAuthArray.push(new auth.UsernamePasswordExternalAuthInfo(<IPackageSource>
{
feedName: feedName,
Expand All @@ -77,6 +79,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf
break;
case "none":
let apiKey = externalAuth.parameters["nugetkey"];
tl.debug("adding apikey auth entry for feed " + feedUri);
externalAuthArray.push(new auth.ApiKeyExternalAuthInfo(<IPackageSource>
{
feedName: feedName,
Expand Down
18 changes: 18 additions & 0 deletions Tasks/NuGetCommand/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,22 @@ describe('NuGetCommand Suite', function () {
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it('restore single solution with nuget config and multiple service connections', (done: MochaDone) => {
this.timeout(1000);

let tp = path.join(__dirname, './RestoreTests/multipleServiceConnections.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run()
assert(tr.invokedToolCount == 1, 'should have run NuGet once');
assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe restore c:\\agent\\home\\directory\\single.sln -NonInteractive -ConfigFile c:\\agent\\home\\directory\\tempNuGet_.config'), 'it should have run NuGet with ConfigFile specified');
assert(tr.stdOutContained('setting console code page'), 'it should have run chcp');
assert(tr.stdOutContained('adding token auth entry for feed https://endpoint1.visualstudio.com/path'), 'it should have added auth entry for endpoint 1');
assert(tr.stdOutContained('adding token auth entry for feed https://endpoint2.visualstudio.com/path'), 'it should have added auth entry for endpoint 2');
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
assert(tr.succeeded, 'should have succeeded');
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import ma = require('vsts-task-lib/mock-answer');
import tmrm = require('vsts-task-lib/mock-run');
import path = require('path');
import util = require('../NugetMockHelper');

let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);

process.env['ENDPOINT_URL_ENDPOINT1'] = "https://endpoint1.visualstudio.com/path";
process.env['ENDPOINT_AUTH_ENDPOINT1'] = "{\"parameters\":{\"apitoken\":\"mytoken123\"},\"scheme\":\"token\"}";
process.env["ENDPOINT_AUTH_SCHEME_ENDPOINT1"] = "token";
process.env['ENDPOINT_AUTH_PARAMETER_ENDPOINT1_APITOKEN'] = "mytoken123";
process.env['ENDPOINT_URL_ENDPOINT2'] = "https://endpoint2.visualstudio.com/path";
process.env['ENDPOINT_AUTH_ENDPOINT2'] = "{\"parameters\":{\"apitoken\":\"mytoken123\"},\"scheme\":\"token\"}";
process.env["ENDPOINT_AUTH_SCHEME_ENDPOINT2"] = "token";
process.env['ENDPOINT_AUTH_PARAMETER_ENDPOINT1_APITOKEN'] = "mytoken123";

nmh.setNugetVersionInputDefault();
tmr.setInput('command', 'restore');
tmr.setInput('solution', 'single.sln');
tmr.setInput('selectOrConfig', 'config');
tmr.setInput('nugetConfigPath', 'c:\\agent\\home\\directory\\nuget.config');
tmr.setInput('externalEndpoints', "ENDPOINT1,ENDPOINT2");

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": {},
"checkPath": {
"c:\\agent\\home\\directory\\nuget.config": true,
"c:\\agent\\home\\directory\\single.sln": true
},
"which": {},
"exec": {
"c:\\from\\tool\\installer\\nuget.exe restore c:\\agent\\home\\directory\\single.sln -NonInteractive -ConfigFile c:\\agent\\home\\directory\\tempNuGet_.config": {
"code": 0,
"stdout": "NuGet output here",
"stderr": ""
}
},
"exist": {},
"stats": {
"c:\\agent\\home\\directory\\single.sln": {
"isFile": true
}
},
"rmRF": {
"c:\\agent\\home\\directory\\tempNuGet_.config": {
"success": true
}
},
"findMatch": {
"single.sln" : ["c:\\agent\\home\\directory\\single.sln"]
}
};
nmh.setAnswers(a);

nmh.registerNugetUtilityMock(["c:\\agent\\home\\directory\\single.sln"]);
nmh.registerDefaultNugetVersionMock();
nmh.registerNugetConfigMock();
nmh.registerToolRunnerMock();

tmr.run();

0 comments on commit 707c8fe

Please sign in to comment.