Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 56 additions & 34 deletions .github/actions/compute-sdk-test/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7039,6 +7039,8 @@ var __webpack_exports__ = {};

// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(5747);
;// CONCATENATED MODULE: external "fs/promises"
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("fs/promises");
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(5622);
;// CONCATENATED MODULE: external "node:child_process"
Expand Down Expand Up @@ -7386,6 +7388,7 @@ const compareDownstreamResponse = async (configResponse, actualResponse) => {




better_logging(console, {
format: ctx => {

Expand All @@ -7411,17 +7414,9 @@ better_logging(console, {




// Get our config from the Github Action
const integrationTestBase = `./integration-tests/js-compute`;
const fixtureBase = `${integrationTestBase}/fixtures`;
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;

console.info(`Parsing SDK Test config: ${configRelativePath}`);
const configAbsolutePath = external_path_.resolve(configRelativePath);
const config = JSON.parse(external_fs_.readFileSync(configAbsolutePath));
console.info('Running the SDK Config:');
console.log(`${JSON.stringify(config, null, 2)}`);

async function spawnViceroy(testName, viceroyAddr) {
const wasmPath = `${fixtureBase}/${testName}/${testName}.wasm`;
Expand All @@ -7439,31 +7434,57 @@ async function spawnViceroy(testName, viceroyAddr) {
function buildTest(testName, backendAddr) {
console.info(`Compiling the fixture for: ${testName} ...`);

external_node_child_process_namespaceObject.execSync(
`./integration-tests/js-compute/build-one.sh ${testName}`,
{
stdio: 'inherit'
try {
external_node_child_process_namespaceObject.execSync(`./integration-tests/js-compute/build-one.sh ${testName}`);
} catch(e) {
console.error(`Failed to compile ${testName}`);
console.log(e.stdout.toString("utf-8"));
process.exit(1);
}

try {
external_node_child_process_namespaceObject.execSync(`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`);
} catch(e) {
console.error(`Failed to compile ${testName}`);
console.log(e.stdout.toString("utf-8"));
process.exit(1);
}
}

async function discoverTests(fixturesPath) {
let tests = {};

// discover all of our test cases
let fixtures = await promises_namespaceObject.readdir(fixturesPath, { withFileTypes: true });
for (const ent of fixtures) {
if (!ent.isDirectory()) {
continue;
}
);

external_node_child_process_namespaceObject.execSync(
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
{
stdio: 'inherit'
let jsonText;
try {
jsonText = await promises_namespaceObject.readFile(`${fixturesPath}/${ent.name}/tests.json`);
} catch(err) {
continue;
}
);

tests[ent.name] = JSON.parse(jsonText);
}

return tests;
}


// Our main task, in which we compile and run tests
const mainAsyncTask = async () => {
// Iterate through our config and compile our wasm modules
const modules = config.modules;
const moduleKeys = Object.keys(modules);

const backendAddr = '127.0.0.1:8082';

const testCases = await discoverTests(fixtureBase);
const testNames = Object.keys(testCases);

// build all the tests
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
testNames.forEach(testName => buildTest(testName, backendAddr));
buildTest('backend', backendAddr);

// Start up the local backend
Expand Down Expand Up @@ -7495,16 +7516,16 @@ const mainAsyncTask = async () => {
});

// Iterate through the module tests, and run the Viceroy tests
for (const moduleKey of moduleKeys) {
const testBase = `${fixtureBase}/${moduleKey}`;
for (const testName of testNames) {
const testBase = `${fixtureBase}/${testName}`;

// created/used by ./integration-tests/js-compute/build-one.sh
const fastlyTomlPath = `${testBase}/fastly.toml`;
const wasmPath = `${testBase}/${moduleKey}.wasm`;
const wasmPath = `${testBase}/${testName}.wasm`;

const module = modules[moduleKey];
const moduleTestKeys = Object.keys(module.tests);
console.info(`Running tests for the module: ${moduleKey} ...`);
const tests = testCases[testName];
const moduleTestKeys = Object.keys(tests);
console.info(`Running tests for the module: ${testName} ...`);

// Spawn a new viceroy instance for the module
viceroy = new src_viceroy();
Expand All @@ -7515,9 +7536,9 @@ const mainAsyncTask = async () => {
})

for (const testKey of moduleTestKeys) {
const test = module.tests[testKey];
const test = tests[testKey];

// Check if this module should be tested in viceroy
// Check if this case should be tested in viceroy
if (!test.environments.includes("viceroy")) {
continue;
}
Expand Down Expand Up @@ -7617,13 +7638,13 @@ const mainAsyncTask = async () => {
}

// Check if we have C@E Environement tests
let shouldRunComputeTests = moduleKeys.some(moduleKey => {
const module = modules[moduleKey];
const moduleTestKeys = Object.keys(module.tests);
let shouldRunComputeTests = testNames.some(testName => {
const tests = testCases[testName];
const moduleTestKeys = Object.keys(tests);

return moduleTestKeys.some(testKey => {
const test = tests[testKey];

const test = module.tests[testKey];
// Check if this module should be tested in viceroy
if (test.environments.includes("c@e")) {
return true;
Expand All @@ -7644,6 +7665,7 @@ mainAsyncTask().then(() => {
process.exit(0);
}).catch((error) => {
console.error(error.message);
console.dir(error);
process.exit(1);
});

Expand Down
88 changes: 54 additions & 34 deletions .github/actions/compute-sdk-test/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Node & 3P Modules
import fs from 'fs';
import fsPromises from 'fs/promises';
import path from 'path';
import childProcess from 'node:child_process';
import fetch from 'node-fetch';
Expand Down Expand Up @@ -31,17 +32,9 @@ import UpstreamServer from './src/upstream-server.js';
import compareUpstreamRequest from './src/compare-upstream-request.js';
import compareDownstreamResponse from './src/compare-downstream-response.js';


// Get our config from the Github Action
const integrationTestBase = `./integration-tests/js-compute`;
const fixtureBase = `${integrationTestBase}/fixtures`;
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;

console.info(`Parsing SDK Test config: ${configRelativePath}`);
const configAbsolutePath = path.resolve(configRelativePath);
const config = JSON.parse(fs.readFileSync(configAbsolutePath));
console.info('Running the SDK Config:');
console.log(`${JSON.stringify(config, null, 2)}`);

async function spawnViceroy(testName, viceroyAddr) {
const wasmPath = `${fixtureBase}/${testName}/${testName}.wasm`;
Expand All @@ -59,31 +52,57 @@ async function spawnViceroy(testName, viceroyAddr) {
function buildTest(testName, backendAddr) {
console.info(`Compiling the fixture for: ${testName} ...`);

childProcess.execSync(
`./integration-tests/js-compute/build-one.sh ${testName}`,
{
stdio: 'inherit'
try {
childProcess.execSync(`./integration-tests/js-compute/build-one.sh ${testName}`);
} catch(e) {
console.error(`Failed to compile ${testName}`);
console.log(e.stdout.toString("utf-8"));
process.exit(1);
}

try {
childProcess.execSync(`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`);
} catch(e) {
console.error(`Failed to compile ${testName}`);
console.log(e.stdout.toString("utf-8"));
process.exit(1);
}
}

async function discoverTests(fixturesPath) {
let tests = {};

// discover all of our test cases
let fixtures = await fsPromises.readdir(fixturesPath, { withFileTypes: true });
for (const ent of fixtures) {
if (!ent.isDirectory()) {
continue;
}
);

childProcess.execSync(
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
{
stdio: 'inherit'
let jsonText;
try {
jsonText = await fsPromises.readFile(`${fixturesPath}/${ent.name}/tests.json`);
} catch(err) {
continue;
}
);

tests[ent.name] = JSON.parse(jsonText);
}

return tests;
}


// Our main task, in which we compile and run tests
const mainAsyncTask = async () => {
// Iterate through our config and compile our wasm modules
const modules = config.modules;
const moduleKeys = Object.keys(modules);

const backendAddr = '127.0.0.1:8082';

const testCases = await discoverTests(fixtureBase);
const testNames = Object.keys(testCases);

// build all the tests
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
testNames.forEach(testName => buildTest(testName, backendAddr));
buildTest('backend', backendAddr);

// Start up the local backend
Expand Down Expand Up @@ -115,16 +134,16 @@ const mainAsyncTask = async () => {
});

// Iterate through the module tests, and run the Viceroy tests
for (const moduleKey of moduleKeys) {
const testBase = `${fixtureBase}/${moduleKey}`;
for (const testName of testNames) {
const testBase = `${fixtureBase}/${testName}`;

// created/used by ./integration-tests/js-compute/build-one.sh
const fastlyTomlPath = `${testBase}/fastly.toml`;
const wasmPath = `${testBase}/${moduleKey}.wasm`;
const wasmPath = `${testBase}/${testName}.wasm`;

const module = modules[moduleKey];
const moduleTestKeys = Object.keys(module.tests);
console.info(`Running tests for the module: ${moduleKey} ...`);
const tests = testCases[testName];
const moduleTestKeys = Object.keys(tests);
console.info(`Running tests for the module: ${testName} ...`);

// Spawn a new viceroy instance for the module
viceroy = new Viceroy();
Expand All @@ -135,9 +154,9 @@ const mainAsyncTask = async () => {
})

for (const testKey of moduleTestKeys) {
const test = module.tests[testKey];
const test = tests[testKey];

// Check if this module should be tested in viceroy
// Check if this case should be tested in viceroy
if (!test.environments.includes("viceroy")) {
continue;
}
Expand Down Expand Up @@ -237,13 +256,13 @@ const mainAsyncTask = async () => {
}

// Check if we have C@E Environement tests
let shouldRunComputeTests = moduleKeys.some(moduleKey => {
const module = modules[moduleKey];
const moduleTestKeys = Object.keys(module.tests);
let shouldRunComputeTests = testNames.some(testName => {
const tests = testCases[testName];
const moduleTestKeys = Object.keys(tests);

return moduleTestKeys.some(testKey => {
const test = tests[testKey];

const test = module.tests[testKey];
// Check if this module should be tested in viceroy
if (test.environments.includes("c@e")) {
return true;
Expand All @@ -264,6 +283,7 @@ mainAsyncTask().then(() => {
process.exit(0);
}).catch((error) => {
console.error(error.message);
console.dir(error);
process.exit(1);
});

Expand Down
17 changes: 17 additions & 0 deletions integration-tests/js-compute/fixtures/async-select/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"POST /hello": {
"environments": ["viceroy", "c@e"],
"downstream_request": {
"method": "POST",
"pathname": "/hello"
},
"downstream_response": {
"status": 200,
"headers": {
"FooName": "FooValue",
"BarName": "BarValue"
},
"body": "pong"
}
}
}
16 changes: 16 additions & 0 deletions integration-tests/js-compute/fixtures/byte-repeater/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"GET /": {
"environments": ["viceroy", "c@e"],
"downstream_request": {
"method": "GET",
"pathname": "/"
},
"downstream_response": {
"status": 200,
"body": [
"11223344",
"5566778899001122\n\n"
]
}
}
}
14 changes: 14 additions & 0 deletions integration-tests/js-compute/fixtures/edge-dictionary/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"POST /": {
"environments": ["viceroy", "c@e"],
"downstream_request": {
"method": "POST",
"pathname": "/",
"body": "What is the Fastly Twitter?"
},
"downstream_response": {
"status": 200,
"body": "https://twitter.com/fastly"
}
}
}
13 changes: 13 additions & 0 deletions integration-tests/js-compute/fixtures/env/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"GET /": {
"environments": ["viceroy"],
"downstream_request": {
"method": "GET",
"pathname": "/"
},
"downstream_response": {
"status": 200,
"body": "localhost"
}
}
}
Loading