Skip to content

Commit b56f93b

Browse files
author
Tatyana Kostromskaya
authored
Add unit test
1 parent cecd581 commit b56f93b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/units/toolTests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ describe('Tool Tests', function () {
132132
});
133133
});
134134

135+
it('different content-length and file size on disk', async function() {
136+
const headers: nock.ReplyHeaders = { 'content-length': '200' };
137+
nock('https://microsoft.com')
138+
.get('/bytes/36')
139+
.reply(200, {
140+
username: 'bad',
141+
password: 'size'
142+
}, headers);
143+
144+
return new Promise<void>(async(resolve, reject)=> {
145+
try {
146+
let errorCodeUrl: string = "https://microsoft.com/bytes/36";
147+
let downPath: string = await toolLib.downloadTool(errorCodeUrl);
148+
149+
reject('content-length of file and size of file on disk should not match, but they do');
150+
}
151+
catch (err){
152+
assert.equal(err.message, `Content-Length (200 bytes) did not match downloaded file size (36 bytes).`);
153+
resolve();
154+
}
155+
});
156+
});
157+
135158
it('works with redirect code 302', async function () {
136159
nock('https://microsoft.com')
137160
.get('/redirect-to')

tool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ export async function downloadTool(
259259
if (!isNaN(downloadedContentLength) &&
260260
!isNaN(fileSizeInBytes) &&
261261
fileSizeInBytes !== downloadedContentLength) {
262-
reject(new Error(`Content-Length (${downloadedContentLength} bytes) did not match downloaded file size (${fileSizeInBytes} bytes).`));
262+
let err: Error = new Error(`Content-Length (${downloadedContentLength} bytes) did not match downloaded file size (${fileSizeInBytes} bytes).`);
263+
reject(err);
263264
}
264265

265266
resolve(destPath);

0 commit comments

Comments
 (0)