diff --git a/Tasks/FtpUploadV1/Tests/L0.ts b/Tasks/FtpUploadV1/Tests/L0.ts index cd6e81b4ddf3..13a8d5dc2ad4 100644 --- a/Tasks/FtpUploadV1/Tests/L0.ts +++ b/Tasks/FtpUploadV1/Tests/L0.ts @@ -1,16 +1,129 @@ import fs = require('fs'); import assert = require('assert'); import path = require('path'); +import * as ttm from 'azure-pipelines-task-lib/mock-test'; describe('FtpUploadV1 Suite', function () { - before(() => { + this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000); + + it('check args: no serverEndpoint', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoServerEndpoint.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: serverEndpoint'), 'Should have printed: Input required: serverEndpoint'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no rootFolder', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoRootFolder.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: rootFolder'), 'Should have printed: Input required: rootFolder'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no filePatterns', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoFilePatterns.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: filePatterns'), 'Should have printed: Input required: filePatterns'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no remotePath', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoRemotePath.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: remotePath'), 'Should have printed: Input required: remotePath'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no clean', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoClean.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: clean'), 'Should have printed: Input required: clean'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no overwrite', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoOverwrite.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: overwrite'), 'Should have printed: Input required: overwrite'); + assert(tr.failed, 'task should have failed'); + + done(); }); - after(() => { + it('check args: no preservePaths', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoPreservePaths.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('Input required: preservePaths'), 'Should have printed: Input required: preservePaths'); + assert(tr.failed, 'task should have failed'); + + done(); }); - it('Does a basic hello world test', function(done: MochaDone) { - // TODO - add real tests + it('check args: no trustSSL', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoTrustSSL.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.invokedToolCount === 0, 'should not run anything'); + assert(tr.stdOutContained('Input required: trustSSL'), 'Should have printed: Input required: trustSSL'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no protocol on server URL (ftp:// or ftps://)', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoProtocol.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('loc_mock_FTPNoProtocolSpecified'), 'Should have printed: loc_mock_FTPNoProtocolSpecified'); + assert(tr.failed, 'task should have failed'); + + done(); + }); + + it('check args: no host name on server URL', (done: Mocha.Done) => { + const tp = path.join(__dirname, 'L0NoHostName.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run(); + + assert(tr.stdOutContained('loc_mock_FTPNoHostSpecified'), 'Should have printed: loc_mock_FTPNoHostSpecified'); + assert(tr.failed, 'task should have failed'); + done(); }); }); diff --git a/Tasks/FtpUploadV1/Tests/L0NoClean.ts b/Tasks/FtpUploadV1/Tests/L0NoClean.ts new file mode 100644 index 000000000000..e0c4ad749695 --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoClean.ts @@ -0,0 +1,40 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoFilePatterns.ts b/Tasks/FtpUploadV1/Tests/L0NoFilePatterns.ts new file mode 100644 index 000000000000..8e3444ba1f04 --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoFilePatterns.ts @@ -0,0 +1,38 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoHostName.ts b/Tasks/FtpUploadV1/Tests/L0NoHostName.ts new file mode 100644 index 000000000000..b7e3877412bb --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoHostName.ts @@ -0,0 +1,47 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('credsType', 'inputs'); +tr.setInput('serverUrl', 'ftps://'); +tr.setInput('username', 'username'); +tr.setInput('password', 'password'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); +tr.setInput('clean', 'true'); +tr.setInput('overwrite', 'true'); +tr.setInput('preservePaths', 'true'); +tr.setInput('trustSSL', 'true'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoOverwrite.ts b/Tasks/FtpUploadV1/Tests/L0NoOverwrite.ts new file mode 100644 index 000000000000..3bbddd96337d --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoOverwrite.ts @@ -0,0 +1,41 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); +tr.setInput('clean', 'true'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoPreservePaths.ts b/Tasks/FtpUploadV1/Tests/L0NoPreservePaths.ts new file mode 100644 index 000000000000..e62cc4cae38e --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoPreservePaths.ts @@ -0,0 +1,42 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); +tr.setInput('clean', 'true'); +tr.setInput('overwrite', 'true'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoProtocol.ts b/Tasks/FtpUploadV1/Tests/L0NoProtocol.ts new file mode 100644 index 000000000000..b94be5afef47 --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoProtocol.ts @@ -0,0 +1,47 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('credsType', 'inputs'); +tr.setInput('serverUrl', 'noprotocol.microsoft.com'); +tr.setInput('username', 'myUsername'); +tr.setInput('password', 'myPassword'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); +tr.setInput('clean', 'true'); +tr.setInput('overwrite', 'true'); +tr.setInput('preservePaths', 'true'); +tr.setInput('trustSSL', 'true'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoRemotePath.ts b/Tasks/FtpUploadV1/Tests/L0NoRemotePath.ts new file mode 100644 index 000000000000..d16cad0ee3ed --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoRemotePath.ts @@ -0,0 +1,39 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tests-Legacy/L0/FtpUpload/ftpUploadLinux.json b/Tasks/FtpUploadV1/Tests/L0NoRootFolder.ts similarity index 57% rename from Tests-Legacy/L0/FtpUpload/ftpUploadLinux.json rename to Tasks/FtpUploadV1/Tests/L0NoRootFolder.ts index f62a771c2890..07d04bbda4bf 100644 --- a/Tests-Legacy/L0/FtpUpload/ftpUploadLinux.json +++ b/Tasks/FtpUploadV1/Tests/L0NoRootFolder.ts @@ -1,7 +1,14 @@ -{ - "osType" : { - "osType" : "Linux" - }, +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { "getVariable": { "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", @@ -24,4 +31,7 @@ "rootFolder/c" ] } -} \ No newline at end of file +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tests-Legacy/L0/FtpUpload/ftpUploadWin.json b/Tasks/FtpUploadV1/Tests/L0NoServerEndpoint.ts similarity index 56% rename from Tests-Legacy/L0/FtpUpload/ftpUploadWin.json rename to Tasks/FtpUploadV1/Tests/L0NoServerEndpoint.ts index 26143150e05f..d466bcf5c551 100644 --- a/Tests-Legacy/L0/FtpUpload/ftpUploadWin.json +++ b/Tasks/FtpUploadV1/Tests/L0NoServerEndpoint.ts @@ -1,7 +1,14 @@ -{ - "osType" : { - "osType" : "Windows" - }, +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('credsType', 'serviceEndpoint'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { "getVariable": { "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", @@ -24,4 +31,7 @@ "rootFolder/c" ] } -} \ No newline at end of file +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tasks/FtpUploadV1/Tests/L0NoTrustSSL.ts b/Tasks/FtpUploadV1/Tests/L0NoTrustSSL.ts new file mode 100644 index 000000000000..dbf227e2e628 --- /dev/null +++ b/Tasks/FtpUploadV1/Tests/L0NoTrustSSL.ts @@ -0,0 +1,43 @@ +import ma = require('azure-pipelines-task-lib/mock-answer'); +import tmrm = require('azure-pipelines-task-lib/mock-run'); +import path = require('path'); + +let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js'); +let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); + +tr.setInput('serverEndpoint', 'ID1'); +tr.setInput('rootFolder', 'rootFolder'); +tr.setInput('filePatterns', '**'); +tr.setInput('remotePath', '/upload/'); +tr.setInput('clean', 'true'); +tr.setInput('overwrite', 'true'); +tr.setInput('preservePaths', 'true'); + +// provide answers for task mock +let a: ma.TaskLibAnswers = { + "getVariable": { + "ENDPOINT_URL_ID1": "ftp://valid.microsoft.com", + "ENDPOINT_AUTH_ID1": "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}", + "build.sourcesDirectory": "/" + }, + "exist" : { + "rootFolder": true + }, + "find": { + "rootFolder": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + }, + "match": { + "*": [ + "rootFolder/a", + "rootFolder/b", + "rootFolder/c" + ] + } +}; +tr.setAnswers(a); + +tr.run(); \ No newline at end of file diff --git a/Tests-Legacy/L0/FtpUpload/_suite.ts b/Tests-Legacy/L0/FtpUpload/_suite.ts deleted file mode 100644 index 7a1b37a160c3..000000000000 --- a/Tests-Legacy/L0/FtpUpload/_suite.ts +++ /dev/null @@ -1,261 +0,0 @@ -/// -/// -/// - -import Q = require('q'); -import assert = require('assert'); -import trm = require('../../lib/taskRunner'); -import path = require('path'); -import os = require('os'); -var shell = require('shelljs'); - -function setResponseFile(name: string) { - process.env['MOCK_RESPONSES'] = path.join(__dirname, name); - process.env['MOCK_NORMALIZE_SLASHES'] = true; -} - -var jobName = 'FtpUpload'; - -describe(jobName + ' Suite', function () { - this.timeout(10000); - - before((done) => { - // init here - done(); - }); - - after(function () { - - }); - - var responseFiles = ['ftpUploadWin.json', 'ftpUploadLinux.json']; - - responseFiles.forEach((responseFile) => { - var isWin = responseFile == 'ftpUploadWin.json'; - var os = isWin ? 'Windows' : 'Linux'; - - it(os + ' check args: no serverEndpoint', (done) => { - setResponseFile(responseFile); - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('credsType', 'serviceEndpoint'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: serverEndpoint') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no rootFolder', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: rootFolder') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no filePatterns', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: filePatterns') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no remotePath', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: remotePath') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no clean', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: clean') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no overwrite', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - tr.setInput('clean', 'true'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: overwrite') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: no preservePaths', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - tr.setInput('clean', 'true'); - tr.setInput('overwrite', 'true'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: preservePaths') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: trustSSL', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('serverEndpoint', 'ID1'); - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - tr.setInput('clean', 'true'); - tr.setInput('overwrite', 'true'); - tr.setInput('preservePaths', 'true'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('Input required: trustSSL') != -1, 'should have written to stderr'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: missing protocol on server URL (ftp:// or ftps://)', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('credsType', 'inputs'); - - tr.setInput('serverUrl', 'noprotocol.microsoft.com'); - tr.setInput('username', 'myUsername'); - tr.setInput('password', 'myPassword'); - - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - tr.setInput('clean', 'true'); - tr.setInput('overwrite', 'true'); - tr.setInput('preservePaths', 'true'); - tr.setInput('trustSSL', 'true'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('The FTP server URL must begin with ftp:// or ftps://') != -1, 'A protocol should have been required in the server URL.'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - - it(os + ' check args: missing host name on server URL', (done) => { - setResponseFile(responseFile); - - var tr = new trm.TaskRunner(jobName, true); - tr.setInput('credsType', 'inputs'); - - tr.setInput('serverUrl', 'ftps://'); - tr.setInput('username', 'myUsername'); - tr.setInput('password', 'myPassword'); - - tr.setInput('rootFolder', 'rootFolder'); - tr.setInput('filePatterns', '**'); - tr.setInput('remotePath', '/upload/'); - tr.setInput('clean', 'true'); - tr.setInput('overwrite', 'true'); - tr.setInput('preservePaths', 'true'); - tr.setInput('trustSSL', 'true'); - - tr.run() - .then(() => { - assert(tr.stderr.indexOf('The FTP server URL must include a host name') != -1, 'A host name should have been required in the server URL.'); - assert(tr.failed, 'task should have failed'); - done(); - }) - .fail((err) => { - console.log(err) - done(err); - }); - }); - }); -});