Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Command should not be called when exe returns with exit code for feature flag on', (done: MochaDone) => {
console.log('TestCaseName: Command should not be called when exe returns with exit code for feature flag on');
// 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.osType] = 'Windows_NT';
process.env[constants.testRunner] = 'VSTest';
process.env[constants.testResultsFiles] = '"n-files0.xml"';
process.env[constants.mergeTestResults] = 'false';
process.env[constants.failTaskOnFailedTests] = 'false';
process.env[constants.platform] = '';
process.env[constants.configuration] = '';
process.env[constants.testRunTitle] = '';
process.env[constants.publishRunAttachments] = 'false';
process.env[constants.searchFolder] = '';
process.env[constants.listPackagesReturnCode] = '0';
process.env[constants.agentTempDirectory] = __dirname;
process.env[constants.proxyUrl] = "http://example.org";
process.env[constants.proxyUserName] = "1";
it("it should read the existing settings.xml and not add any new entries.", (done: MochaDone) => {
this.timeout(1000);
let tp: string = path.join(__dirname, "L0AuthSettingsXmlExists.js");
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tl.cp(settingsFeedName1, settingsXmlPath);
tr.run();
assert.equal(tl.ls(null, [m2DirPath]).length, 1, "Should have one file.");
const settingsXmlStats = tl.stats(settingsXmlPath);
assert(settingsXmlStats && settingsXmlStats.isFile(), "settings.xml file should be present.");
const data = fs.readFileSync(settingsXmlPath, 'utf-8');
assert.equal(data.match(serversRegex).length, 1, "Only one entry should be present.");
assert.equal(data.match(serverRegex).length, 1, "Only one entry should be present.");
assert.equal(data.match(/feedName1<\/id>/gi).length, 1, "Only one id entry should be present.");
assert(tr.stderr.length === 0, "should not have written to stderr");
it('publish single package externally', (done: MochaDone) => {
this.timeout(1000);
let tp = path.join(__dirname, 'external.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run()
assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe push -NonInteractive c:\\agent\\home\\directory\\package.nupkg -Source https://example.feed.com -ApiKey secret'), 'should have pushed packages');
assert(tr.stdOutContained('setting console code page'), 'it should have run chcp');
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
assert(!tr.stdOutContained('adding package source uri'), "should not set package source in config");
assert(tr.succeeded, 'should have succeeded');
assert(tr.invokedToolCount == 1, 'should have run NuGet');
assert.equal(tr.warningIssues.length, 0, "should have no warnings");
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});
});
it('Do not align or sign if input single file does not exist', (done: MochaDone) => {
this.timeout(1000);
const tp: string = path.join(__dirname, 'L0AndroidSignAlignNoFileInput.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
assert(tr.invokedToolCount === 0, 'should not run anything');
assert(tr.errorIssues.length || tr.stderr.length > 0, 'should have written to stderr');
assert(tr.failed, 'task should have failed');
done();
});
it('Run should succeessfully patch', (done: MochaDone) => {
const tp = path.join(__dirname, 'TestSetup.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
process.env[shared.TestEnvVars.action] = shared.Actions.patch;
process.env[shared.TestEnvVars.kind] = 'replicaset';
process.env[shared.TestEnvVars.mergeStrategy] = 'merge';
process.env[shared.TestEnvVars.name] = 'r1';
process.env[shared.TestEnvVars.patch] = 'somePatch';
tr.run();
assert(tr.succeeded, 'task should have succeeded');
done();
});
it('fails when version is not found', function () {
const testFile = path.join(__dirname, 'L0FailsWhenVersionIsMissing.js');
const testRunner = new MockTestRunner(testFile);
testRunner.run();
const errorMessage = [
'loc_mock_VersionNotFound 3.x x64',
'loc_mock_ListAvailableVersions $(Agent.ToolsDirectory)',
'2.6.0 (x86)',
'2.7.13 (x86)',
'2.6.0 (x64)',
'2.7.13 (x64)',
'loc_mock_ToolNotFoundMicrosoftHosted Python https://aka.ms/hosted-agent-software',
'loc_mock_ToolNotFoundSelfHosted Python https://go.microsoft.com/fwlink/?linkid=871498',
].join(os.EOL);
assert(testRunner.createdErrorIssue(errorMessage));
assert(testRunner.failed, 'task should have failed');
it('test no json file fails', (done) => {
const testFile = path.join(__dirname, 'L0NoJsonFileAuth.js');
const testRunner = new ttm.MockTestRunner(testFile);
testRunner.run();
assert(testRunner.createdErrorIssue('Error: loc_mock_JsonKeyFileNotFound'), 'Did not print the expected message');
assert(testRunner.failed, 'task should have failed');
done();
});
it('copyFiles should create dest if it does not exist', (done:MochaDone) => {
process.env["__dest_path_exists__"] = "false";
let tp = path.join(__dirname, 'L0Utilities.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
process.env["__dest_path_exists__"] = "true";
assert(tr.stdout.indexOf("creating path: F:\\somedir\\tempdir\\100") != -1, "dest should be created");
assert(tr.stdout.indexOf("copying .\\DefaultTemplates\\default.windows.template.json to F:\\somedir\\tempdir\\100") != -1, "copy should be done");
done();
});
it('Download keystore file from SecureFile', (done: MochaDone) => {
this.timeout(1000);
const tp: string = path.join(__dirname, 'L0DownloadKeystoreFile.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
assert(tr.stderr.length === 0, 'should not have written to stderr');
assert(tr.succeeded, 'task should have succeeded');
done();
});
});
it('test uploads metadata', (done) => {
const testFile = path.join(__dirname, 'L0AttachMetadata.js');
const testRunner = new ttm.MockTestRunner(testFile);
testRunner.run();
assert(testRunner.stdOutContained('loc_mock_AttachingMetadataToRelease'), 'Did not have expected localized message');
assert(testRunner.succeeded, 'task should have succeeded');
done();
});