Skip to content

Commit 6c376d8

Browse files
committed
Add integration test for ensuring the graphql query succeeds
1 parent 82ada54 commit 6c376d8

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,17 @@ jobs:
118118
- name: Run integration tests (Linux)
119119
if: matrix.os == 'ubuntu-latest'
120120
working-directory: extensions/ql-vscode
121+
env:
122+
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
121123
run: |
122124
sudo apt-get install xvfb
123125
/usr/bin/xvfb-run npm run integration
124126
125127
- name: Run integration tests (Windows)
126128
if: matrix.os == 'windows-latest'
127129
working-directory: extensions/ql-vscode
130+
env:
131+
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
128132
run: |
129133
npm run integration
130134

extensions/ql-vscode/src/authentication.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ export class Credentials {
3535
return c;
3636
}
3737

38-
private async createOctokit(createIfNone: boolean): Promise<Octokit.Octokit | undefined> {
38+
static async initializeOverride(overrideToken: string) {
39+
const c = new Credentials();
40+
c.octokit = await c.createOctokit(false, overrideToken);
41+
return c;
42+
}
43+
44+
private async createOctokit(createIfNone: boolean, overrideToken?: string): Promise<Octokit.Octokit | undefined> {
45+
if (overrideToken) {
46+
return new Octokit.Octokit({ auth: overrideToken });
47+
}
48+
3949
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone });
4050

4151
if (session) {

extensions/ql-vscode/src/vscode-tests/no-workspace/data/remote-queries/queries/MRVA Integration test 1-6sBi6oaky_fxqXW2NA4bx/query-result.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"nwo": "github/vscode-codeql",
66
"resultCount": 15,
7+
"starCount": 1,
78
"fileSizeInBytes": 191025,
89
"downloadLink": {
910
"id": "171543249",
@@ -15,6 +16,7 @@
1516
{
1617
"nwo": "other/hucairz",
1718
"resultCount": 15,
19+
"starCount": 1,
1820
"fileSizeInBytes": 191025,
1921
"downloadLink": {
2022
"id": "11111111",
@@ -26,6 +28,7 @@
2628
{
2729
"nwo": "hucairz/i-dont-exist",
2830
"resultCount": 5,
31+
"starCount": 1,
2932
"fileSizeInBytes": 81237,
3033
"downloadLink": {
3134
"id": "999999",

extensions/ql-vscode/src/vscode-tests/no-workspace/data/remote-queries/queries/MRVA Integration test 2-UL-vbKAjP8ffObxjsp7hN/query-result.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"nwo": "github/vscode-codeql",
66
"resultCount": 5,
7+
"starCount": 1,
78
"fileSizeInBytes": 81237,
89
"downloadLink": {
910
"id": "171544171",

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/gh-actions-api-client.test.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { fail } from 'assert';
12
import { expect } from 'chai';
23
import * as sinon from 'sinon';
34
import { Credentials } from '../../../authentication';
4-
import { cancelRemoteQuery } from '../../../remote-queries/gh-actions-api-client';
5+
import { cancelRemoteQuery, getStargazers } from '../../../remote-queries/gh-actions-api-client';
56
import { RemoteQuery } from '../../../remote-queries/remote-query';
67

7-
describe('gh-actions-api-client', () => {
8+
describe('gh-actions-api-client mock responses', () => {
89
let sandbox: sinon.SinonSandbox;
910
let mockCredentials: Credentials;
1011
let mockResponse: sinon.SinonStub<any, Promise<{ status: number }>>;
@@ -50,3 +51,44 @@ describe('gh-actions-api-client', () => {
5051
}
5152
});
5253
});
54+
55+
describe('gh-actions-api-client real responses', function() {
56+
this.timeout(10000);
57+
58+
it('should get the stargazers for projects', async () => {
59+
if (skip()) {
60+
return;
61+
}
62+
63+
const credentials = await Credentials.initializeOverride(process.env.VSCODE_CODEQL_GITHUB_TOKEN!);
64+
const stargazers = await getStargazers(credentials, [
65+
'github/codeql',
66+
'github/vscode-codeql',
67+
'rails/rails',
68+
'angular/angular',
69+
'github/hucairz' // This one should not be in the list
70+
],
71+
// choose a page size that is small enough to ensure we make multiple requests
72+
2);
73+
74+
const stargazersKeys = Object.keys(stargazers).sort();
75+
expect(stargazersKeys).to.deep.eq([
76+
'angular/angular',
77+
'github/codeql',
78+
'github/vscode-codeql',
79+
'rails/rails',
80+
]);
81+
});
82+
83+
function skip() {
84+
if (!process.env.VSCODE_CODEQL_GITHUB_TOKEN) {
85+
if (process.env.CI) {
86+
fail('The VSCODE_CODEQL_GITHUB_TOKEN must be set to a valid GITHUB token on CI');
87+
} else {
88+
console.log('Skipping gh-actions-api-client real responses tests. To run these tests, set the value VSCODE_CODEQL_GITHUB_TOKEN to a GitHub token.');
89+
}
90+
return true;
91+
}
92+
return false;
93+
}
94+
});

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/remote-query-history.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,20 @@ describe('Remote queries and query history manager', function() {
253253
expect(trimmed[0]).to.deep.eq([{
254254
nwo: 'github/vscode-codeql',
255255
status: 'InProgress',
256+
resultCount: 15,
257+
starCount: 1
256258
}]);
257259

258260
expect(trimmed[1]).to.deep.eq([{
259261
nwo: 'github/vscode-codeql',
260262
status: 'InProgress',
263+
resultCount: 15,
264+
starCount: 1
261265
}, {
262266
nwo: 'other/hucairz',
263267
status: 'InProgress',
268+
resultCount: 15,
269+
starCount: 1
264270
}]);
265271

266272
// there is a third call. It is non-deterministic if
@@ -270,9 +276,13 @@ describe('Remote queries and query history manager', function() {
270276
expect(trimmed[3]).to.deep.eq([{
271277
nwo: 'github/vscode-codeql',
272278
status: 'Completed',
279+
resultCount: 15,
280+
starCount: 1
273281
}, {
274282
nwo: 'other/hucairz',
275283
status: 'Completed',
284+
resultCount: 15,
285+
starCount: 1
276286
}]);
277287

278288
expect(publisher).to.have.callCount(4);

0 commit comments

Comments
 (0)