Skip to content

Commit 90e315a

Browse files
committed
Update tests for GHEC-DR
1 parent bc3670a commit 90e315a

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

lib/database-upload.test.js

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/database-upload.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database-upload.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function mockHttpRequests(databaseUploadStatusCode: number) {
5353
const requestSpy = sinon.stub(client, "request");
5454

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

6666
sinon.stub(apiClient, "getApiClient").value(() => client);
67+
68+
return databaseUploadSpy;
6769
}
6870

6971
test("Abort database upload if 'upload-database' input set to false", async (t) => {
@@ -116,7 +118,8 @@ test("Abort database upload if running against GHES", async (t) => {
116118
loggedMessages.find(
117119
(v: LoggedMessage) =>
118120
v.type === "debug" &&
119-
v.message === "Not running against github.com. Skipping upload.",
121+
v.message ===
122+
"Not running against github.com or GHEC-DR. Skipping upload.",
120123
) !== undefined,
121124
);
122125
});
@@ -184,7 +187,7 @@ test("Don't crash if uploading a database fails", async (t) => {
184187
});
185188
});
186189

187-
test("Successfully uploading a database to api.github.com", async (t) => {
190+
test("Successfully uploading a database to github.com", async (t) => {
188191
await withTmpDir(async (tmpDir) => {
189192
setupActionsVars(tmpDir, tmpDir);
190193
sinon
@@ -218,7 +221,7 @@ test("Successfully uploading a database to api.github.com", async (t) => {
218221
});
219222
});
220223

221-
test("Successfully uploading a database to uploads.github.com", async (t) => {
224+
test("Successfully uploading a database to GHEC-DR", async (t) => {
222225
await withTmpDir(async (tmpDir) => {
223226
setupActionsVars(tmpDir, tmpDir);
224227
sinon
@@ -227,7 +230,7 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
227230
.returns("true");
228231
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
229232

230-
await mockHttpRequests(201);
233+
const databaseUploadSpy = await mockHttpRequests(201);
231234

232235
setCodeQL({
233236
async databaseBundle(_: string, outputFilePath: string) {
@@ -239,7 +242,11 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
239242
await uploadDatabases(
240243
testRepoName,
241244
getTestConfig(tmpDir),
242-
testApiDetails,
245+
{
246+
auth: "1234",
247+
url: "https://tenant.ghe.com",
248+
apiURL: undefined,
249+
},
243250
getRecordingLogger(loggedMessages),
244251
);
245252
t.assert(
@@ -249,5 +256,11 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
249256
v.message === "Successfully uploaded database for javascript",
250257
) !== undefined,
251258
);
259+
t.assert(
260+
databaseUploadSpy.calledOnceWith(
261+
sinon.match.string,
262+
sinon.match.has("baseUrl", "https://uploads.tenant.ghe.com/"),
263+
),
264+
);
252265
});
253266
});

0 commit comments

Comments
 (0)