Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FtpUploadV1] Migrated legacy tests #14116

Merged
merged 13 commits into from
Dec 23, 2020
141 changes: 137 additions & 4 deletions Tasks/FtpUploadV1/Tests/L0.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,149 @@
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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000);

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);
max-zaytsev marked this conversation as resolved.
Show resolved Hide resolved

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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();
});

it('check args: no preservePaths', (done: Mocha.Done) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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();
});

after(() => {
it('check args: no trustSSL', (done: Mocha.Done) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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('Does a basic hello world test', function(done: MochaDone) {
// TODO - add real tests
it('check args: no host name on server URL', (done: Mocha.Done) => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT || '') || 20000);

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();
});
});
40 changes: 40 additions & 0 deletions Tasks/FtpUploadV1/Tests/L0NoClean.ts
Original file line number Diff line number Diff line change
@@ -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 = <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();
38 changes: 38 additions & 0 deletions Tasks/FtpUploadV1/Tests/L0NoFilePatterns.ts
Original file line number Diff line number Diff line change
@@ -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 = <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();
47 changes: 47 additions & 0 deletions Tasks/FtpUploadV1/Tests/L0NoHostName.ts
Original file line number Diff line number Diff line change
@@ -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 = <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();
41 changes: 41 additions & 0 deletions Tasks/FtpUploadV1/Tests/L0NoOverwrite.ts
Original file line number Diff line number Diff line change
@@ -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 = <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();
42 changes: 42 additions & 0 deletions Tasks/FtpUploadV1/Tests/L0NoPreservePaths.ts
Original file line number Diff line number Diff line change
@@ -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 = <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();
Loading