Skip to content

Commit e2e7074

Browse files
authored
Move test specification into fixture dirs (#134)
Remove the single authoritative sdk-test-config.json in favor of moving the individual cases into the fixture directory for the test it describes. This allows new tests to be created by adding the appropriate files into a sub-directory of integration-tests/js-compute only. This will also avoid a common source of merge conflicts, as multiple PRs adding tests will no longer interact through the sdk-test-config.json file.
1 parent 5d61f76 commit e2e7074

File tree

18 files changed

+343
-370
lines changed

18 files changed

+343
-370
lines changed

.github/actions/compute-sdk-test/dist/main.js

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7039,6 +7039,8 @@ var __webpack_exports__ = {};
70397039

70407040
// EXTERNAL MODULE: external "fs"
70417041
var external_fs_ = __nccwpck_require__(5747);
7042+
;// CONCATENATED MODULE: external "fs/promises"
7043+
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("fs/promises");
70427044
// EXTERNAL MODULE: external "path"
70437045
var external_path_ = __nccwpck_require__(5622);
70447046
;// CONCATENATED MODULE: external "node:child_process"
@@ -7386,6 +7388,7 @@ const compareDownstreamResponse = async (configResponse, actualResponse) => {
73867388

73877389

73887390

7391+
73897392
better_logging(console, {
73907393
format: ctx => {
73917394

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

74127415

74137416

7414-
74157417
// Get our config from the Github Action
74167418
const integrationTestBase = `./integration-tests/js-compute`;
74177419
const fixtureBase = `${integrationTestBase}/fixtures`;
7418-
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;
7419-
7420-
console.info(`Parsing SDK Test config: ${configRelativePath}`);
7421-
const configAbsolutePath = external_path_.resolve(configRelativePath);
7422-
const config = JSON.parse(external_fs_.readFileSync(configAbsolutePath));
7423-
console.info('Running the SDK Config:');
7424-
console.log(`${JSON.stringify(config, null, 2)}`);
74257420

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

7442-
external_node_child_process_namespaceObject.execSync(
7443-
`./integration-tests/js-compute/build-one.sh ${testName}`,
7444-
{
7445-
stdio: 'inherit'
7437+
try {
7438+
external_node_child_process_namespaceObject.execSync(`./integration-tests/js-compute/build-one.sh ${testName}`);
7439+
} catch(e) {
7440+
console.error(`Failed to compile ${testName}`);
7441+
console.log(e.stdout.toString("utf-8"));
7442+
process.exit(1);
7443+
}
7444+
7445+
try {
7446+
external_node_child_process_namespaceObject.execSync(`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`);
7447+
} catch(e) {
7448+
console.error(`Failed to compile ${testName}`);
7449+
console.log(e.stdout.toString("utf-8"));
7450+
process.exit(1);
7451+
}
7452+
}
7453+
7454+
async function discoverTests(fixturesPath) {
7455+
let tests = {};
7456+
7457+
// discover all of our test cases
7458+
let fixtures = await promises_namespaceObject.readdir(fixturesPath, { withFileTypes: true });
7459+
for (const ent of fixtures) {
7460+
if (!ent.isDirectory()) {
7461+
continue;
74467462
}
7447-
);
74487463

7449-
external_node_child_process_namespaceObject.execSync(
7450-
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
7451-
{
7452-
stdio: 'inherit'
7464+
let jsonText;
7465+
try {
7466+
jsonText = await promises_namespaceObject.readFile(`${fixturesPath}/${ent.name}/tests.json`);
7467+
} catch(err) {
7468+
continue;
74537469
}
7454-
);
7470+
7471+
tests[ent.name] = JSON.parse(jsonText);
7472+
}
7473+
7474+
return tests;
74557475
}
74567476

7477+
74577478
// Our main task, in which we compile and run tests
74587479
const mainAsyncTask = async () => {
7459-
// Iterate through our config and compile our wasm modules
7460-
const modules = config.modules;
7461-
const moduleKeys = Object.keys(modules);
74627480

74637481
const backendAddr = '127.0.0.1:8082';
74647482

7483+
const testCases = await discoverTests(fixtureBase);
7484+
const testNames = Object.keys(testCases);
7485+
74657486
// build all the tests
7466-
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
7487+
testNames.forEach(testName => buildTest(testName, backendAddr));
74677488
buildTest('backend', backendAddr);
74687489

74697490
// Start up the local backend
@@ -7495,16 +7516,16 @@ const mainAsyncTask = async () => {
74957516
});
74967517

74977518
// Iterate through the module tests, and run the Viceroy tests
7498-
for (const moduleKey of moduleKeys) {
7499-
const testBase = `${fixtureBase}/${moduleKey}`;
7519+
for (const testName of testNames) {
7520+
const testBase = `${fixtureBase}/${testName}`;
75007521

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

7505-
const module = modules[moduleKey];
7506-
const moduleTestKeys = Object.keys(module.tests);
7507-
console.info(`Running tests for the module: ${moduleKey} ...`);
7526+
const tests = testCases[testName];
7527+
const moduleTestKeys = Object.keys(tests);
7528+
console.info(`Running tests for the module: ${testName} ...`);
75087529

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

75177538
for (const testKey of moduleTestKeys) {
7518-
const test = module.tests[testKey];
7539+
const test = tests[testKey];
75197540

7520-
// Check if this module should be tested in viceroy
7541+
// Check if this case should be tested in viceroy
75217542
if (!test.environments.includes("viceroy")) {
75227543
continue;
75237544
}
@@ -7617,13 +7638,13 @@ const mainAsyncTask = async () => {
76177638
}
76187639

76197640
// Check if we have C@E Environement tests
7620-
let shouldRunComputeTests = moduleKeys.some(moduleKey => {
7621-
const module = modules[moduleKey];
7622-
const moduleTestKeys = Object.keys(module.tests);
7641+
let shouldRunComputeTests = testNames.some(testName => {
7642+
const tests = testCases[testName];
7643+
const moduleTestKeys = Object.keys(tests);
76237644

76247645
return moduleTestKeys.some(testKey => {
7646+
const test = tests[testKey];
76257647

7626-
const test = module.tests[testKey];
76277648
// Check if this module should be tested in viceroy
76287649
if (test.environments.includes("c@e")) {
76297650
return true;
@@ -7644,6 +7665,7 @@ mainAsyncTask().then(() => {
76447665
process.exit(0);
76457666
}).catch((error) => {
76467667
console.error(error.message);
7668+
console.dir(error);
76477669
process.exit(1);
76487670
});
76497671

.github/actions/compute-sdk-test/main.js

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Node & 3P Modules
22
import fs from 'fs';
3+
import fsPromises from 'fs/promises';
34
import path from 'path';
45
import childProcess from 'node:child_process';
56
import fetch from 'node-fetch';
@@ -31,17 +32,9 @@ import UpstreamServer from './src/upstream-server.js';
3132
import compareUpstreamRequest from './src/compare-upstream-request.js';
3233
import compareDownstreamResponse from './src/compare-downstream-response.js';
3334

34-
3535
// Get our config from the Github Action
3636
const integrationTestBase = `./integration-tests/js-compute`;
3737
const fixtureBase = `${integrationTestBase}/fixtures`;
38-
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;
39-
40-
console.info(`Parsing SDK Test config: ${configRelativePath}`);
41-
const configAbsolutePath = path.resolve(configRelativePath);
42-
const config = JSON.parse(fs.readFileSync(configAbsolutePath));
43-
console.info('Running the SDK Config:');
44-
console.log(`${JSON.stringify(config, null, 2)}`);
4538

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

62-
childProcess.execSync(
63-
`./integration-tests/js-compute/build-one.sh ${testName}`,
64-
{
65-
stdio: 'inherit'
55+
try {
56+
childProcess.execSync(`./integration-tests/js-compute/build-one.sh ${testName}`);
57+
} catch(e) {
58+
console.error(`Failed to compile ${testName}`);
59+
console.log(e.stdout.toString("utf-8"));
60+
process.exit(1);
61+
}
62+
63+
try {
64+
childProcess.execSync(`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`);
65+
} catch(e) {
66+
console.error(`Failed to compile ${testName}`);
67+
console.log(e.stdout.toString("utf-8"));
68+
process.exit(1);
69+
}
70+
}
71+
72+
async function discoverTests(fixturesPath) {
73+
let tests = {};
74+
75+
// discover all of our test cases
76+
let fixtures = await fsPromises.readdir(fixturesPath, { withFileTypes: true });
77+
for (const ent of fixtures) {
78+
if (!ent.isDirectory()) {
79+
continue;
6680
}
67-
);
6881

69-
childProcess.execSync(
70-
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
71-
{
72-
stdio: 'inherit'
82+
let jsonText;
83+
try {
84+
jsonText = await fsPromises.readFile(`${fixturesPath}/${ent.name}/tests.json`);
85+
} catch(err) {
86+
continue;
7387
}
74-
);
88+
89+
tests[ent.name] = JSON.parse(jsonText);
90+
}
91+
92+
return tests;
7593
}
7694

95+
7796
// Our main task, in which we compile and run tests
7897
const mainAsyncTask = async () => {
79-
// Iterate through our config and compile our wasm modules
80-
const modules = config.modules;
81-
const moduleKeys = Object.keys(modules);
8298

8399
const backendAddr = '127.0.0.1:8082';
84100

101+
const testCases = await discoverTests(fixtureBase);
102+
const testNames = Object.keys(testCases);
103+
85104
// build all the tests
86-
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
105+
testNames.forEach(testName => buildTest(testName, backendAddr));
87106
buildTest('backend', backendAddr);
88107

89108
// Start up the local backend
@@ -115,16 +134,16 @@ const mainAsyncTask = async () => {
115134
});
116135

117136
// Iterate through the module tests, and run the Viceroy tests
118-
for (const moduleKey of moduleKeys) {
119-
const testBase = `${fixtureBase}/${moduleKey}`;
137+
for (const testName of testNames) {
138+
const testBase = `${fixtureBase}/${testName}`;
120139

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

125-
const module = modules[moduleKey];
126-
const moduleTestKeys = Object.keys(module.tests);
127-
console.info(`Running tests for the module: ${moduleKey} ...`);
144+
const tests = testCases[testName];
145+
const moduleTestKeys = Object.keys(tests);
146+
console.info(`Running tests for the module: ${testName} ...`);
128147

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

137156
for (const testKey of moduleTestKeys) {
138-
const test = module.tests[testKey];
157+
const test = tests[testKey];
139158

140-
// Check if this module should be tested in viceroy
159+
// Check if this case should be tested in viceroy
141160
if (!test.environments.includes("viceroy")) {
142161
continue;
143162
}
@@ -237,13 +256,13 @@ const mainAsyncTask = async () => {
237256
}
238257

239258
// Check if we have C@E Environement tests
240-
let shouldRunComputeTests = moduleKeys.some(moduleKey => {
241-
const module = modules[moduleKey];
242-
const moduleTestKeys = Object.keys(module.tests);
259+
let shouldRunComputeTests = testNames.some(testName => {
260+
const tests = testCases[testName];
261+
const moduleTestKeys = Object.keys(tests);
243262

244263
return moduleTestKeys.some(testKey => {
264+
const test = tests[testKey];
245265

246-
const test = module.tests[testKey];
247266
// Check if this module should be tested in viceroy
248267
if (test.environments.includes("c@e")) {
249268
return true;
@@ -264,6 +283,7 @@ mainAsyncTask().then(() => {
264283
process.exit(0);
265284
}).catch((error) => {
266285
console.error(error.message);
286+
console.dir(error);
267287
process.exit(1);
268288
});
269289

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"POST /hello": {
3+
"environments": ["viceroy", "c@e"],
4+
"downstream_request": {
5+
"method": "POST",
6+
"pathname": "/hello"
7+
},
8+
"downstream_response": {
9+
"status": 200,
10+
"headers": {
11+
"FooName": "FooValue",
12+
"BarName": "BarValue"
13+
},
14+
"body": "pong"
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"GET /": {
3+
"environments": ["viceroy", "c@e"],
4+
"downstream_request": {
5+
"method": "GET",
6+
"pathname": "/"
7+
},
8+
"downstream_response": {
9+
"status": 200,
10+
"body": [
11+
"11223344",
12+
"5566778899001122\n\n"
13+
]
14+
}
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"POST /": {
3+
"environments": ["viceroy", "c@e"],
4+
"downstream_request": {
5+
"method": "POST",
6+
"pathname": "/",
7+
"body": "What is the Fastly Twitter?"
8+
},
9+
"downstream_response": {
10+
"status": 200,
11+
"body": "https://twitter.com/fastly"
12+
}
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"GET /": {
3+
"environments": ["viceroy"],
4+
"downstream_request": {
5+
"method": "GET",
6+
"pathname": "/"
7+
},
8+
"downstream_response": {
9+
"status": 200,
10+
"body": "localhost"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)