Add integration test for ensuring the graphql query succeeds

This commit is contained in:
Andrew Eisenberg 2022-05-18 13:52:36 -07:00
Родитель 82ada54103
Коммит 6c376d8721
6 изменённых файлов: 73 добавлений и 3 удалений

4
.github/workflows/main.yml поставляемый
Просмотреть файл

@ -118,6 +118,8 @@ jobs:
- name: Run integration tests (Linux)
if: matrix.os == 'ubuntu-latest'
working-directory: extensions/ql-vscode
env:
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
run: |
sudo apt-get install xvfb
/usr/bin/xvfb-run npm run integration
@ -125,6 +127,8 @@ jobs:
- name: Run integration tests (Windows)
if: matrix.os == 'windows-latest'
working-directory: extensions/ql-vscode
env:
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
run: |
npm run integration

Просмотреть файл

@ -35,7 +35,17 @@ export class Credentials {
return c;
}
private async createOctokit(createIfNone: boolean): Promise<Octokit.Octokit | undefined> {
static async initializeOverride(overrideToken: string) {
const c = new Credentials();
c.octokit = await c.createOctokit(false, overrideToken);
return c;
}
private async createOctokit(createIfNone: boolean, overrideToken?: string): Promise<Octokit.Octokit | undefined> {
if (overrideToken) {
return new Octokit.Octokit({ auth: overrideToken });
}
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone });
if (session) {

Просмотреть файл

@ -4,6 +4,7 @@
{
"nwo": "github/vscode-codeql",
"resultCount": 15,
"starCount": 1,
"fileSizeInBytes": 191025,
"downloadLink": {
"id": "171543249",
@ -15,6 +16,7 @@
{
"nwo": "other/hucairz",
"resultCount": 15,
"starCount": 1,
"fileSizeInBytes": 191025,
"downloadLink": {
"id": "11111111",
@ -26,6 +28,7 @@
{
"nwo": "hucairz/i-dont-exist",
"resultCount": 5,
"starCount": 1,
"fileSizeInBytes": 81237,
"downloadLink": {
"id": "999999",

Просмотреть файл

@ -4,6 +4,7 @@
{
"nwo": "github/vscode-codeql",
"resultCount": 5,
"starCount": 1,
"fileSizeInBytes": 81237,
"downloadLink": {
"id": "171544171",

Просмотреть файл

@ -1,10 +1,11 @@
import { fail } from 'assert';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { Credentials } from '../../../authentication';
import { cancelRemoteQuery } from '../../../remote-queries/gh-actions-api-client';
import { cancelRemoteQuery, getStargazers } from '../../../remote-queries/gh-actions-api-client';
import { RemoteQuery } from '../../../remote-queries/remote-query';
describe('gh-actions-api-client', () => {
describe('gh-actions-api-client mock responses', () => {
let sandbox: sinon.SinonSandbox;
let mockCredentials: Credentials;
let mockResponse: sinon.SinonStub<any, Promise<{ status: number }>>;
@ -50,3 +51,44 @@ describe('gh-actions-api-client', () => {
}
});
});
describe('gh-actions-api-client real responses', function() {
this.timeout(10000);
it('should get the stargazers for projects', async () => {
if (skip()) {
return;
}
const credentials = await Credentials.initializeOverride(process.env.VSCODE_CODEQL_GITHUB_TOKEN!);
const stargazers = await getStargazers(credentials, [
'github/codeql',
'github/vscode-codeql',
'rails/rails',
'angular/angular',
'github/hucairz' // This one should not be in the list
],
// choose a page size that is small enough to ensure we make multiple requests
2);
const stargazersKeys = Object.keys(stargazers).sort();
expect(stargazersKeys).to.deep.eq([
'angular/angular',
'github/codeql',
'github/vscode-codeql',
'rails/rails',
]);
});
function skip() {
if (!process.env.VSCODE_CODEQL_GITHUB_TOKEN) {
if (process.env.CI) {
fail('The VSCODE_CODEQL_GITHUB_TOKEN must be set to a valid GITHUB token on CI');
} else {
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.');
}
return true;
}
return false;
}
});

Просмотреть файл

@ -253,14 +253,20 @@ describe('Remote queries and query history manager', function() {
expect(trimmed[0]).to.deep.eq([{
nwo: 'github/vscode-codeql',
status: 'InProgress',
resultCount: 15,
starCount: 1
}]);
expect(trimmed[1]).to.deep.eq([{
nwo: 'github/vscode-codeql',
status: 'InProgress',
resultCount: 15,
starCount: 1
}, {
nwo: 'other/hucairz',
status: 'InProgress',
resultCount: 15,
starCount: 1
}]);
// there is a third call. It is non-deterministic if
@ -270,9 +276,13 @@ describe('Remote queries and query history manager', function() {
expect(trimmed[3]).to.deep.eq([{
nwo: 'github/vscode-codeql',
status: 'Completed',
resultCount: 15,
starCount: 1
}, {
nwo: 'other/hucairz',
status: 'Completed',
resultCount: 15,
starCount: 1
}]);
expect(publisher).to.have.callCount(4);