Update tests

This commit is contained in:
Tom Hu
2021-04-15 22:25:03 -04:00
parent 83cbbf806b
commit 444b352d52
3 changed files with 28 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
import validateUploader from './validate';
import validateUploader, {retrieveChecksum} from './validate';
const request = require('requestretry');
@@ -16,19 +16,24 @@ const bashScript = (async () => {
}
});
test('validChecksums', async () => {
test('valid checksums', async () => {
const valid = await validateUploader(await bashScript());
expect(valid).toBeTruthy();
});
test('invalidChecksums', async () => {
test('invalid checksums', async () => {
const script = await bashScript();
const valid = await validateUploader(script.substring(0, script.length - 1));
expect(valid).toBeFalsy();
});
test('invalidVersion', async () => {
test('invalid script version', async () => {
const script = await bashScript();
const valid = await validateUploader(script.substring(0, 20));
expect(valid).toBeFalsy();
});
test('invalid public checksum file', async () => {
const checksum = await retrieveChecksum('foo', 'bar');
expect(checksum).toBeFalsy();
});

View File

@@ -26,21 +26,21 @@ const validateUploader = async (body) => {
return true;
};
const retrieveChecksum = async (version, encryption) => {
export const retrieveChecksum = async (version, encryption) => {
const url = `https://raw.githubusercontent.com/codecov/codecov-bash/${version}/SHA${encryption}SUM`;
try {
const response = await request({
maxAttempts: 10,
timeout: 3000,
url: url,
});
return response.body;
} catch (err) {
const response = await request({
maxAttempts: 10,
timeout: 3000,
url: url,
});
if (response.statusCode != 200) {
core.warning(
`Codecov could not retrieve checksum SHA${encryption} at ${url}`,
);
return false;
return '';
}
return response.body;
};
const calculateChecksum = (body, i) => {