Skip to content

Commit f49a03c

Browse files
authored
Start abstracting the test suite a bit (#135)
1 parent 3ec6905 commit f49a03c

File tree

2 files changed

+62
-32
lines changed

2 files changed

+62
-32
lines changed

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

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,57 @@ import Viceroy from './src/viceroy.js';
3131
import UpstreamServer from './src/upstream-server.js';
3232
import compareUpstreamRequest from './src/compare-upstream-request.js';
3333
import compareDownstreamResponse from './src/compare-downstream-response.js';
34+
import tests from './src/test-suite.js';
3435

35-
// Get our config from the Github Action
36-
const integrationTestBase = `./integration-tests/js-compute`;
37-
const fixtureBase = `${integrationTestBase}/fixtures`;
3836

39-
async function spawnViceroy(testName, viceroyAddr) {
40-
const wasmPath = `${fixtureBase}/${testName}/${testName}.wasm`;
41-
const fastlyTomlPath = `${fixtureBase}/${testName}/fastly.toml`;
37+
async function spawnViceroy(config, testName, viceroyAddr) {
38+
console.info(`Spawning a viceroy instance for ${testName} on ${viceroyAddr}`);
4239

4340
let viceroy = new Viceroy();
44-
await viceroy.spawn(wasmPath, {
45-
config: fastlyTomlPath,
41+
42+
await viceroy.spawn(config.wasmPath(testName), {
43+
config: config.fastlyTomlPath(testName),
4644
addr: viceroyAddr
4745
});
4846

4947
return viceroy;
5048
}
5149

52-
function buildTest(testName, backendAddr) {
50+
function buildTest(config, testName, backendAddr) {
5351
console.info(`Compiling the fixture for: ${testName} ...`);
5452

5553
try {
56-
childProcess.execSync(`./integration-tests/js-compute/build-one.sh ${testName}`);
54+
childProcess.execSync(`${config.buildScript} ${testName}`);
5755
} catch(e) {
5856
console.error(`Failed to compile ${testName}`);
59-
console.log(e.stdout.toString("utf-8"));
57+
console.info(e.stdout.toString("utf-8"));
6058
process.exit(1);
6159
}
6260

6361
try {
64-
childProcess.execSync(`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`);
62+
childProcess.execSync(`${config.replaceHostScript} ${testName} http://${backendAddr}`);
6563
} catch(e) {
6664
console.error(`Failed to compile ${testName}`);
67-
console.log(e.stdout.toString("utf-8"));
65+
console.info(e.stdout.toString("utf-8"));
6866
process.exit(1);
6967
}
7068
}
7169

72-
async function discoverTests(fixturesPath) {
70+
async function discoverTests(config) {
71+
console.info(`Looking for tests in ${config.fixtureBase}`);
72+
7373
let tests = {};
7474

7575
// discover all of our test cases
76-
let fixtures = await fsPromises.readdir(fixturesPath, { withFileTypes: true });
76+
let fixtures = await fsPromises.readdir(config.fixtureBase, { withFileTypes: true });
7777
for (const ent of fixtures) {
7878
if (!ent.isDirectory()) {
7979
continue;
8080
}
8181

8282
let jsonText;
8383
try {
84-
jsonText = await fsPromises.readFile(`${fixturesPath}/${ent.name}/tests.json`);
84+
jsonText = await fsPromises.readFile(config.testJsonPath(ent.name));
8585
} catch(err) {
8686
continue;
8787
}
@@ -96,18 +96,21 @@ async function discoverTests(fixturesPath) {
9696
// Our main task, in which we compile and run tests
9797
const mainAsyncTask = async () => {
9898

99+
// Get our config from the Github Action
100+
const config = new tests.TestConfig('./integration-tests/js-compute');
101+
99102
const backendAddr = '127.0.0.1:8082';
100103

101-
const testCases = await discoverTests(fixtureBase);
104+
const testCases = await discoverTests(config);
102105
const testNames = Object.keys(testCases);
103106

104107
// build all the tests
105-
testNames.forEach(testName => buildTest(testName, backendAddr));
106-
buildTest('backend', backendAddr);
108+
testNames.forEach(testName => buildTest(config, testName, backendAddr));
109+
buildTest(config, 'backend', backendAddr);
107110

108111
// Start up the local backend
109112
console.info(`Starting the generic backend on ${backendAddr}`);
110-
let backend = await spawnViceroy('backend', backendAddr);
113+
let backend = await spawnViceroy(config, 'backend', backendAddr);
111114

112115
console.info(`Running the Viceroy environment tests ...`);
113116

@@ -135,23 +138,13 @@ const mainAsyncTask = async () => {
135138

136139
// Iterate through the module tests, and run the Viceroy tests
137140
for (const testName of testNames) {
138-
const testBase = `${fixtureBase}/${testName}`;
139-
140-
// created/used by ./integration-tests/js-compute/build-one.sh
141-
const fastlyTomlPath = `${testBase}/fastly.toml`;
142-
const wasmPath = `${testBase}/${testName}.wasm`;
143-
144141
const tests = testCases[testName];
145142
const moduleTestKeys = Object.keys(tests);
146143
console.info(`Running tests for the module: ${testName} ...`);
147144

148145
// Spawn a new viceroy instance for the module
149-
viceroy = new Viceroy();
150146
const viceroyAddr = '127.0.0.1:8080';
151-
await viceroy.spawn(wasmPath, {
152-
config: fastlyTomlPath,
153-
addr: viceroyAddr
154-
})
147+
viceroy = await spawnViceroy(config, testName, viceroyAddr);
155148

156149
for (const testKey of moduleTestKeys) {
157150
const test = tests[testKey];
@@ -161,7 +154,7 @@ const mainAsyncTask = async () => {
161154
continue;
162155
}
163156

164-
console.log(`Running the test ${testKey} ...`);
157+
console.info(`Running the test ${testKey} ...`);
165158

166159
// Prepare our upstream server for this specific test
167160
isDownstreamResponseHandled = false;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
class TestConfig {
3+
4+
constructor(testBase) {
5+
this.testBase = testBase;
6+
}
7+
8+
get fixtureBase() {
9+
return `${this.testBase}/fixtures`;
10+
}
11+
12+
get buildScript() {
13+
return `${this.testBase}/build-one.sh`;
14+
}
15+
16+
get replaceHostScript() {
17+
return `${this.testBase}/replace-host.sh`;
18+
}
19+
20+
wasmPath(testName) {
21+
return `${this.fixtureBase}/${testName}/${testName}.wasm`;
22+
}
23+
24+
fastlyTomlPath(testName) {
25+
return `${this.fixtureBase}/${testName}/fastly.toml`;
26+
}
27+
28+
fastlyTomlInPath(testName) {
29+
return `${this.fixtureBase}/${testName}/fastly.toml.in`;
30+
}
31+
32+
testJsonPath(testName) {
33+
return `${this.fixtureBase}/${testName}/tests.json`;
34+
}
35+
};
36+
37+
export default { TestConfig };

0 commit comments

Comments
 (0)