Skip to content

Commit

Permalink
Update tests for GHEC-DR
Browse files Browse the repository at this point in the history
  • Loading branch information
koesie10 committed May 13, 2024
1 parent bc3670a commit 90e315a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
19 changes: 13 additions & 6 deletions lib/database-upload.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/database-upload.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions src/database-upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function mockHttpRequests(databaseUploadStatusCode: number) {
const requestSpy = sinon.stub(client, "request");

const url =
"POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name&commit_oid=:commit_oid";
"POST /repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name&commit_oid=:commit_oid";
const databaseUploadSpy = requestSpy.withArgs(url);
if (databaseUploadStatusCode < 300) {
databaseUploadSpy.resolves(undefined);
Expand All @@ -64,6 +64,8 @@ async function mockHttpRequests(databaseUploadStatusCode: number) {
}

sinon.stub(apiClient, "getApiClient").value(() => client);

return databaseUploadSpy;
}

test("Abort database upload if 'upload-database' input set to false", async (t) => {
Expand Down Expand Up @@ -116,7 +118,8 @@ test("Abort database upload if running against GHES", async (t) => {
loggedMessages.find(
(v: LoggedMessage) =>
v.type === "debug" &&
v.message === "Not running against github.com. Skipping upload.",
v.message ===
"Not running against github.com or GHEC-DR. Skipping upload.",
) !== undefined,
);
});
Expand Down Expand Up @@ -184,7 +187,7 @@ test("Don't crash if uploading a database fails", async (t) => {
});
});

test("Successfully uploading a database to api.github.com", async (t) => {
test("Successfully uploading a database to github.com", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
sinon
Expand Down Expand Up @@ -218,7 +221,7 @@ test("Successfully uploading a database to api.github.com", async (t) => {
});
});

test("Successfully uploading a database to uploads.github.com", async (t) => {
test("Successfully uploading a database to GHEC-DR", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);
sinon
Expand All @@ -227,7 +230,7 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
.returns("true");
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);

await mockHttpRequests(201);
const databaseUploadSpy = await mockHttpRequests(201);

setCodeQL({
async databaseBundle(_: string, outputFilePath: string) {
Expand All @@ -239,7 +242,11 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
await uploadDatabases(
testRepoName,
getTestConfig(tmpDir),
testApiDetails,
{
auth: "1234",
url: "https://tenant.ghe.com",
apiURL: undefined,
},
getRecordingLogger(loggedMessages),
);
t.assert(
Expand All @@ -249,5 +256,11 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
v.message === "Successfully uploaded database for javascript",
) !== undefined,
);
t.assert(
databaseUploadSpy.calledOnceWith(
sinon.match.string,
sinon.match.has("baseUrl", "https://uploads.tenant.ghe.com/"),
),
);
});
});

0 comments on commit 90e315a

Please sign in to comment.