Clean up the database if it will be uploaded

This commit is contained in:
Henry Mercer
2025-08-07 11:47:45 +01:00
parent b1228d060c
commit c7884c6fd8
21 changed files with 123 additions and 135 deletions

View File

@@ -69,6 +69,17 @@ async function mockHttpRequests(databaseUploadStatusCode: number) {
return databaseUploadSpy;
}
function getCodeQL() {
return setCodeQL({
async databaseBundle(_: string, outputFilePath: string) {
fs.writeFileSync(outputFilePath, "");
},
async databaseCleanupCluster() {
// Do nothing, as we are not testing cleanup here.
},
});
}
test("Abort database upload if 'upload-database' input set to false", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
@@ -81,6 +92,7 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
const loggedMessages = [];
await uploadDatabases(
testRepoName,
getCodeQL(),
getTestConfig(tmpDir),
testApiDetails,
getRecordingLogger(loggedMessages),
@@ -111,6 +123,7 @@ test("Abort database upload if running against GHES", async (t) => {
const loggedMessages = [];
await uploadDatabases(
testRepoName,
getCodeQL(),
config,
testApiDetails,
getRecordingLogger(loggedMessages),
@@ -138,6 +151,7 @@ test("Abort database upload if not analyzing default branch", async (t) => {
const loggedMessages = [];
await uploadDatabases(
testRepoName,
getCodeQL(),
getTestConfig(tmpDir),
testApiDetails,
getRecordingLogger(loggedMessages),
@@ -163,15 +177,10 @@ test("Don't crash if uploading a database fails", async (t) => {
await mockHttpRequests(500);
setCodeQL({
async databaseBundle(_: string, outputFilePath: string) {
fs.writeFileSync(outputFilePath, "");
},
});
const loggedMessages = [] as LoggedMessage[];
await uploadDatabases(
testRepoName,
getCodeQL(),
getTestConfig(tmpDir),
testApiDetails,
getRecordingLogger(loggedMessages),
@@ -199,15 +208,10 @@ test("Successfully uploading a database to github.com", async (t) => {
await mockHttpRequests(201);
setCodeQL({
async databaseBundle(_: string, outputFilePath: string) {
fs.writeFileSync(outputFilePath, "");
},
});
const loggedMessages = [] as LoggedMessage[];
await uploadDatabases(
testRepoName,
getCodeQL(),
getTestConfig(tmpDir),
testApiDetails,
getRecordingLogger(loggedMessages),
@@ -233,15 +237,10 @@ test("Successfully uploading a database to GHEC-DR", async (t) => {
const databaseUploadSpy = await mockHttpRequests(201);
setCodeQL({
async databaseBundle(_: string, outputFilePath: string) {
fs.writeFileSync(outputFilePath, "");
},
});
const loggedMessages = [] as LoggedMessage[];
await uploadDatabases(
testRepoName,
getCodeQL(),
getTestConfig(tmpDir),
{
auth: "1234",