UNPKG

@webscale-networks/cloudedge-handlers

Version:

Webscale Networks CloudEDGE Handlers for cloud-agnostic edge function execution

50 lines (46 loc) 1.7 kB
const fs = require('fs'); const path = require('path'); // Run tests that assert each handler function conforms to Webscale's handler // interface. function runHandlerInterfaceTests(tests, moduleName, module, func) { describe(moduleName + '.' + func.name, () => { for (const testInstance of tests) { test(testInstance.name, async () => { await testInstance.expectFunction( 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 interface 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); runHandlerInterfaceTests( tests[func.type], metadata.moduleName, module, func, ); } } } catch(err) { console.error(err); expect(err).toBeNull(); } });