@webscale-networks/cloudedge-handlers
Version:
Webscale Networks CloudEDGE Handlers for cloud-agnostic edge function execution
52 lines (48 loc) • 1.78 kB
JavaScript
const fs = require('fs');
const path = require('path');
jest.spyOn(console, 'log').mockImplementation(() => {});
// Run tests that assert each handler function obeys the constraints of the
// cloud provider.
function runCloudProviderTests(tests, moduleName, module, func) {
describe(moduleName + '.' + func.name, () => {
for (const testInstance of tests) {
test(testInstance.name, async () => {
await testInstance.expectFunction(
moduleName,
func.name,
func.type,
module[func.name],
)
});
}
});
};
// Runs the test found in 'tests.js' against each handler function listed in the
// handler file's manifest.json file.
describe('Webscale CloudEDGE handler AWS test suite', () => {
const rootDir = process.env['HANDLER_ROOT_DIR'];
if (!rootDir) {
expect(rootDir).not.toBeUndefined() ||
expect(rootDir).not.toBeNull();
}
const content = fs.readFileSync(path.join(rootDir, 'manifest.json'));
try {
const manifest = JSON.parse(content)
const tests = require(path.join(__dirname, 'tests.js')).tests;
for (const metadata of manifest) {
const module = require(path.join(rootDir, metadata.relativePath));
for (const func of metadata.functions) {
expect(['handleRequest', 'handleResponse', 'compute']).toContain(func.type);
runCloudProviderTests(
tests[func.type],
metadata.moduleName,
module,
func,
);
}
}
} catch(err) {
console.error(err);
expect(err).toBeNull();
}
});