2023-01-10 22:26:27 +00:00
|
|
|
import { buildTestSpecs } from "./src/generator"
|
2023-01-13 18:23:58 +00:00
|
|
|
import { Version, versions } from "./versions"
|
|
|
|
import { promises as fs } from "fs";
|
2023-01-10 22:26:27 +00:00
|
|
|
import { run, RunFailure } from "./src/compose-runner"
|
|
|
|
import { stringify } from "csv-stringify/sync"
|
2023-01-13 18:23:58 +00:00
|
|
|
import { stringify as YAMLStringify } from "yaml"
|
|
|
|
import yargs from "yargs/yargs"
|
|
|
|
import path from "path";
|
2023-01-10 22:26:27 +00:00
|
|
|
|
2023-01-13 18:23:58 +00:00
|
|
|
(async () => {
|
|
|
|
const WorkerCount = parseInt(process.env.WORKER_COUNT || "1")
|
|
|
|
const argv = await yargs(process.argv.slice(2))
|
|
|
|
.options({
|
|
|
|
'name-filter': {
|
|
|
|
description: 'Only run named test',
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
'emit-only': {
|
|
|
|
alias: 'e',
|
|
|
|
description: 'Only print the compose.yaml file',
|
|
|
|
default: false,
|
|
|
|
type: 'boolean'
|
|
|
|
},
|
|
|
|
'extra-versions-dir': {
|
|
|
|
description: 'Look for extra versions in this directory. Version files must be in json format',
|
|
|
|
default: "",
|
|
|
|
type: 'string'
|
|
|
|
},
|
2023-02-01 23:17:22 +00:00
|
|
|
'extra-version': {
|
|
|
|
description: 'Paths to JSON files for additional versions to include in the test matrix',
|
|
|
|
default: [],
|
|
|
|
type: 'array'
|
|
|
|
},
|
2023-01-13 18:23:58 +00:00
|
|
|
})
|
|
|
|
.help()
|
|
|
|
.version(false)
|
|
|
|
.alias('help', 'h').argv;
|
|
|
|
const extraVersionsDir = argv.extraVersionsDir
|
|
|
|
const extraVersions: Array<Version> = []
|
|
|
|
if (extraVersionsDir !== "") {
|
|
|
|
try {
|
|
|
|
const files = await fs.readdir(extraVersionsDir);
|
|
|
|
for (const file of files) {
|
|
|
|
const contents = await fs.readFile(path.join(extraVersionsDir, file))
|
|
|
|
extraVersions.push(...JSON.parse(contents.toString()))
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error reading extra versions")
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 23:17:22 +00:00
|
|
|
for (let versionPath of argv.extraVersion.filter(p => p !== "")) {
|
|
|
|
const contents = await fs.readFile(versionPath);
|
|
|
|
extraVersions.push(JSON.parse(contents.toString()))
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:23:58 +00:00
|
|
|
let testSpecs = await buildTestSpecs(versions.concat(extraVersions))
|
|
|
|
|
|
|
|
const nameFilter = argv["name-filter"]
|
|
|
|
if (nameFilter !== "") {
|
|
|
|
testSpecs = testSpecs.filter((testSpec) => testSpec.name?.includes(nameFilter))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argv["emit-only"]) {
|
|
|
|
for (const testSpec of testSpecs) {
|
|
|
|
console.log("## " + testSpec.name)
|
|
|
|
console.log(YAMLStringify(testSpec))
|
|
|
|
console.log("\n\n")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2023-01-10 22:26:27 +00:00
|
|
|
|
|
|
|
console.log(`Running ${testSpecs.length} tests`)
|
|
|
|
const failures: Array<RunFailure> = []
|
|
|
|
const statuses: Array<string[]> = [["name", "outcome"]]
|
|
|
|
const workers = new Array(WorkerCount).fill({}).map(async () => {
|
|
|
|
while (true) {
|
|
|
|
const testSpec = testSpecs.pop()
|
|
|
|
if (testSpec == null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log("Running test spec: " + testSpec.name)
|
|
|
|
const failure = await run(testSpec.name || "unknown test", testSpec, { up: { exitCodeFrom: "dialer", renewAnonVolumes: true }, })
|
|
|
|
if (failure != null) {
|
|
|
|
failures.push(failure)
|
|
|
|
statuses.push([testSpec.name || "unknown test", "failure"])
|
|
|
|
} else {
|
|
|
|
statuses.push([testSpec.name || "unknown test", "success"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await Promise.all(workers)
|
|
|
|
|
|
|
|
console.log(`${failures.length} failures`, failures)
|
|
|
|
await fs.writeFile("results.csv", stringify(statuses))
|
|
|
|
|
2023-01-13 18:23:58 +00:00
|
|
|
console.log("Run complete")
|
2023-02-01 23:17:22 +00:00
|
|
|
})()
|