|
1 | 1 | import fs = require('fs'); |
2 | 2 | import assert = require('assert'); |
3 | 3 | import path = require('path'); |
| 4 | +import * as ttm from 'azure-pipelines-task-lib/mock-test'; |
4 | 5 |
|
5 | 6 | describe('FtpUploadV2 Suite', function () { |
6 | | - before(() => { |
| 7 | + this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT!) || 20000); |
| 8 | + |
| 9 | + it('check args: no serverEndpoint', (done: Mocha.Done) => { |
| 10 | + const tp = path.join(__dirname, 'L0NoServerEndpoint.js'); |
| 11 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 12 | + |
| 13 | + tr.run(); |
| 14 | + |
| 15 | + assert(tr.stdOutContained('Input required: serverEndpoint'), 'Should have printed: Input required: serverEndpoint'); |
| 16 | + assert(tr.failed, 'task should have failed'); |
| 17 | + |
| 18 | + done(); |
| 19 | + }); |
| 20 | + |
| 21 | + it('check args: no rootFolder', (done: Mocha.Done) => { |
| 22 | + const tp = path.join(__dirname, 'L0NoRootFolder.js'); |
| 23 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 24 | + |
| 25 | + tr.run(); |
| 26 | + |
| 27 | + assert(tr.stdOutContained('Input required: rootFolder'), 'Should have printed: Input required: rootFolder'); |
| 28 | + assert(tr.failed, 'task should have failed'); |
| 29 | + |
| 30 | + done(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('check args: no filePatterns', (done: Mocha.Done) => { |
| 34 | + const tp = path.join(__dirname, 'L0NoFilePatterns.js'); |
| 35 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 36 | + |
| 37 | + tr.run(); |
| 38 | + |
| 39 | + assert(tr.stdOutContained('Input required: filePatterns'), 'Should have printed: Input required: filePatterns'); |
| 40 | + assert(tr.failed, 'task should have failed'); |
| 41 | + |
| 42 | + done(); |
7 | 43 | }); |
8 | 44 |
|
9 | | - after(() => { |
| 45 | + it('check args: no remotePath', (done: Mocha.Done) => { |
| 46 | + const tp = path.join(__dirname, 'L0NoRemotePath.js'); |
| 47 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 48 | + |
| 49 | + tr.run(); |
| 50 | + |
| 51 | + assert(tr.stdOutContained('Input required: remotePath'), 'Should have printed: Input required: remotePath'); |
| 52 | + assert(tr.failed, 'task should have failed'); |
| 53 | + |
| 54 | + done(); |
10 | 55 | }); |
11 | 56 |
|
12 | | - it('Does a basic hello world test', function(done: MochaDone) { |
13 | | - // TODO - add real tests |
| 57 | + it('check args: no clean', (done: Mocha.Done) => { |
| 58 | + const tp = path.join(__dirname, 'L0NoClean.js'); |
| 59 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 60 | + |
| 61 | + tr.run(); |
| 62 | + |
| 63 | + assert(tr.stdOutContained('Input required: clean'), 'Should have printed: Input required: clean'); |
| 64 | + assert(tr.failed, 'task should have failed'); |
| 65 | + |
| 66 | + done(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('check args: no preservePaths', (done: Mocha.Done) => { |
| 70 | + const tp = path.join(__dirname, 'L0NoPreservePaths.js'); |
| 71 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 72 | + |
| 73 | + tr.run(); |
| 74 | + |
| 75 | + assert(tr.stdOutContained('Input required: preservePaths'), 'Should have printed: Input required: preservePaths'); |
| 76 | + assert(tr.failed, 'task should have failed'); |
| 77 | + |
| 78 | + done(); |
| 79 | + }); |
| 80 | + |
| 81 | + it('check args: no trustSSL', (done: Mocha.Done) => { |
| 82 | + const tp = path.join(__dirname, 'L0NoTrustSSL.js'); |
| 83 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 84 | + |
| 85 | + tr.run(); |
| 86 | + |
| 87 | + assert(tr.invokedToolCount === 0, 'should not run anything'); |
| 88 | + assert(tr.stdOutContained('Input required: trustSSL'), 'Should have printed: Input required: trustSSL'); |
| 89 | + assert(tr.failed, 'task should have failed'); |
| 90 | + |
| 91 | + done(); |
| 92 | + }); |
| 93 | + |
| 94 | + it('check args: no protocol on server URL (ftp:// or ftps://)', (done: Mocha.Done) => { |
| 95 | + const tp = path.join(__dirname, 'L0NoProtocol.js'); |
| 96 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 97 | + |
| 98 | + tr.run(); |
| 99 | + |
| 100 | + assert(tr.stdOutContained('loc_mock_FTPNoProtocolSpecified'), 'Should have printed: loc_mock_FTPNoProtocolSpecified'); |
| 101 | + assert(tr.failed, 'task should have failed'); |
| 102 | + |
| 103 | + done(); |
| 104 | + }); |
| 105 | + |
| 106 | + it('check args: no host name on server URL', (done: Mocha.Done) => { |
| 107 | + const tp = path.join(__dirname, 'L0NoHostName.js'); |
| 108 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 109 | + |
| 110 | + tr.run(); |
| 111 | + |
| 112 | + assert(tr.stdOutContained('loc_mock_FTPNoHostSpecified'), 'Should have printed: loc_mock_FTPNoHostSpecified'); |
| 113 | + assert(tr.failed, 'task should have failed'); |
| 114 | + |
| 115 | + done(); |
| 116 | + }); |
| 117 | + |
| 118 | + it('check args: no files found', (done: Mocha.Done) => { |
| 119 | + const tp = path.join(__dirname, 'L0NoFilesFound.js'); |
| 120 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 121 | + |
| 122 | + tr.run(); |
| 123 | + |
| 124 | + assert(tr.stdOutContained('loc_mock_NoFilesFound'), 'Should have printed: loc_mock_NoFilesFound'); |
| 125 | + assert(tr.failed, 'task should have failed'); |
| 126 | + |
| 127 | + done(); |
| 128 | + }); |
| 129 | + |
| 130 | + it('task should complete successfully', (done: Mocha.Done) => { |
| 131 | + const tp = path.join(__dirname, 'L0Successful.js'); |
| 132 | + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); |
| 133 | + |
| 134 | + tr.run(); |
| 135 | + console.info(tr.stdout); |
| 136 | + assert(tr.succeeded, 'task should succeed'); |
| 137 | + |
14 | 138 | done(); |
15 | 139 | }); |
16 | 140 | }); |
0 commit comments