Skip to content

Commit 444b352

Browse files
committed
Update tests
1 parent 83cbbf8 commit 444b352

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

dist/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49215,6 +49215,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4921549215
}
4921649216
};
4921749217
exports.__esModule = true;
49218+
exports.retrieveChecksum = void 0;
4921849219
var crypto = __webpack_require__(417);
4921949220
var core = __webpack_require__(470);
4922049221
var request = __webpack_require__(335);
@@ -49233,7 +49234,7 @@ var validateUploader = function (body) { return __awaiter(void 0, void 0, void 0
4923349234
case 1:
4923449235
if (!(_i < _a.length)) return [3 /*break*/, 4];
4923549236
i = _a[_i];
49236-
return [4 /*yield*/, retrieveChecksum(version, i)];
49237+
return [4 /*yield*/, exports.retrieveChecksum(version, i)];
4923749238
case 2:
4923849239
publicChecksum = _b.sent();
4923949240
uploaderChecksum = calculateChecksum(body, i);
@@ -49252,30 +49253,27 @@ var validateUploader = function (body) { return __awaiter(void 0, void 0, void 0
4925249253
});
4925349254
}); };
4925449255
var retrieveChecksum = function (version, encryption) { return __awaiter(void 0, void 0, void 0, function () {
49255-
var url, response, err_1;
49256+
var url, response;
4925649257
return __generator(this, function (_a) {
4925749258
switch (_a.label) {
4925849259
case 0:
4925949260
url = "https://raw.githubusercontent.com/codecov/codecov-bash/" + version + "/SHA" + encryption + "SUM";
49260-
_a.label = 1;
49261-
case 1:
49262-
_a.trys.push([1, 3, , 4]);
4926349261
return [4 /*yield*/, request({
4926449262
maxAttempts: 10,
4926549263
timeout: 3000,
4926649264
url: url,
4926749265
})];
49268-
case 2:
49266+
case 1:
4926949267
response = _a.sent();
49268+
if (response.statusCode != 200) {
49269+
core.warning("Codecov could not retrieve checksum SHA" + encryption + " at " + url);
49270+
return [2 /*return*/, ''];
49271+
}
4927049272
return [2 /*return*/, response.body];
49271-
case 3:
49272-
err_1 = _a.sent();
49273-
core.warning("Codecov could not retrieve checksum SHA" + encryption + " at " + url);
49274-
return [2 /*return*/, false];
49275-
case 4: return [2 /*return*/];
4927649273
}
4927749274
});
4927849275
}); };
49276+
exports.retrieveChecksum = retrieveChecksum;
4927949277
var calculateChecksum = function (body, i) {
4928049278
var shasum = crypto.createHash("sha" + i);
4928149279
shasum.update(body);

src/validate.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateUploader from './validate';
1+
import validateUploader, {retrieveChecksum} from './validate';
22

33
const request = require('requestretry');
44

@@ -16,19 +16,24 @@ const bashScript = (async () => {
1616
}
1717
});
1818

19-
test('validChecksums', async () => {
19+
test('valid checksums', async () => {
2020
const valid = await validateUploader(await bashScript());
2121
expect(valid).toBeTruthy();
2222
});
2323

24-
test('invalidChecksums', async () => {
24+
test('invalid checksums', async () => {
2525
const script = await bashScript();
2626
const valid = await validateUploader(script.substring(0, script.length - 1));
2727
expect(valid).toBeFalsy();
2828
});
2929

30-
test('invalidVersion', async () => {
30+
test('invalid script version', async () => {
3131
const script = await bashScript();
3232
const valid = await validateUploader(script.substring(0, 20));
3333
expect(valid).toBeFalsy();
3434
});
35+
36+
test('invalid public checksum file', async () => {
37+
const checksum = await retrieveChecksum('foo', 'bar');
38+
expect(checksum).toBeFalsy();
39+
});

src/validate.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ const validateUploader = async (body) => {
2626
return true;
2727
};
2828

29-
const retrieveChecksum = async (version, encryption) => {
29+
export const retrieveChecksum = async (version, encryption) => {
3030
const url = `https://raw.githubusercontent.com/codecov/codecov-bash/${version}/SHA${encryption}SUM`;
31-
try {
32-
const response = await request({
33-
maxAttempts: 10,
34-
timeout: 3000,
35-
url: url,
36-
});
37-
return response.body;
38-
} catch (err) {
31+
const response = await request({
32+
maxAttempts: 10,
33+
timeout: 3000,
34+
url: url,
35+
});
36+
37+
if (response.statusCode != 200) {
3938
core.warning(
4039
`Codecov could not retrieve checksum SHA${encryption} at ${url}`,
4140
);
42-
return false;
41+
return '';
4342
}
43+
return response.body;
4444
};
4545

4646
const calculateChecksum = (body, i) => {

0 commit comments

Comments
 (0)