0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00
mongodb/jstests/libs/begin_golden_test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.4 KiB
JavaScript
Raw Normal View History

import {checkSbeStatus} from "jstests/libs/query/sbe_util.js";
// Run any set-up necessary for a golden jstest. This function should be called from the suite
// definition, so that individual tests don't need to remember to call it.
//
// In case the test name ends in "_md", the golden data will be outputted to a markdown file.
// However, if an explicit fileExtension is specified, it will always be used instead.
export function beginGoldenTest(relativePathToExpectedOutput, fileExtension = "") {
// Skip checking SBE status if there is no `db` object when nodb:"" is used.
if (typeof db !== 'undefined') {
let sbeStatus = checkSbeStatus(db);
if (fileExists(relativePathToExpectedOutput + "/" + sbeStatus + "/" + jsTestName())) {
relativePathToExpectedOutput += "/" + sbeStatus;
}
}
let outputName = jsTestName();
const testNameParts = jsTestName().split("_");
// If the test name ends in "_md" and no explicit file extension is specified, then remove the
// "_md" part and use it as the file extension.
// TODO SERVER-92693: Use only the file extension.
if (testNameParts.length > 0 && testNameParts[testNameParts.length - 1] === "md" &&
fileExtension === "") {
fileExtension = ".md";
outputName = testNameParts.slice(0, -1).join("_");
}
_openGoldenData(outputName + fileExtension, {relativePath: relativePathToExpectedOutput});
}