Remove unused return values for run methods
The `runRemoteQuery` and `runVariantAnalysis` were returning values which were only used in tests. This removes them and replaces the tests by expectations on the commands called by the methods.
This commit is contained in:
@@ -119,7 +119,7 @@ export class RemoteQueriesManager extends DisposableObject {
|
||||
uri: Uri | undefined,
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken
|
||||
): Promise<RemoteQuery | undefined> {
|
||||
): Promise<void> {
|
||||
const credentials = await Credentials.initialize(this.ctx);
|
||||
|
||||
const {
|
||||
@@ -136,7 +136,7 @@ export class RemoteQueriesManager extends DisposableObject {
|
||||
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, controllerRepo, base64Pack);
|
||||
|
||||
if (!apiResponse) {
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const workflowRunId = apiResponse.workflow_run_id;
|
||||
@@ -158,8 +158,6 @@ export class RemoteQueriesManager extends DisposableObject {
|
||||
|
||||
this.remoteQueryAddedEventEmitter.fire({ queryId, query });
|
||||
void commands.executeCommand('codeQL.monitorRemoteQuery', queryId, query);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public async monitorRemoteQuery(
|
||||
|
||||
@@ -69,7 +69,7 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
|
||||
uri: Uri | undefined,
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken,
|
||||
): Promise<VariantAnalysis> {
|
||||
): Promise<void> {
|
||||
const credentials = await Credentials.initialize(this.ctx);
|
||||
|
||||
const {
|
||||
@@ -122,8 +122,6 @@ export class VariantAnalysisManager extends DisposableObject implements VariantA
|
||||
|
||||
void commands.executeCommand('codeQL.openVariantAnalysisView', processedVariantAnalysis.id);
|
||||
void commands.executeCommand('codeQL.monitorVariantAnalysis', processedVariantAnalysis);
|
||||
|
||||
return processedVariantAnalysis;
|
||||
}
|
||||
|
||||
public async rehydrateVariantAnalysis(variantAnalysis: VariantAnalysis) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { assert, expect } from 'chai';
|
||||
import * as path from 'path';
|
||||
import * as sinon from 'sinon';
|
||||
import { CancellationTokenSource, ExtensionContext, extensions, QuickPickItem, Uri, window } from 'vscode';
|
||||
import { CancellationTokenSource, commands, ExtensionContext, extensions, QuickPickItem, Uri, window } from 'vscode';
|
||||
import * as os from 'os';
|
||||
import * as yaml from 'js-yaml';
|
||||
|
||||
@@ -92,8 +92,11 @@ describe('Remote queries', function() {
|
||||
|
||||
describe('runRemoteQuery', () => {
|
||||
let mockSubmitRemoteQueries: sinon.SinonStub;
|
||||
let executeCommandSpy: sinon.SinonStub;
|
||||
|
||||
beforeEach(() => {
|
||||
executeCommandSpy = sandbox.stub(commands, 'executeCommand').callThrough();
|
||||
|
||||
mockSubmitRemoteQueries = sandbox.stub(ghApiClient, 'submitRemoteQueries').resolves({
|
||||
workflow_run_id: 20,
|
||||
repositories_queried: ['octodemo/hello-world-1'],
|
||||
@@ -103,10 +106,10 @@ describe('Remote queries', function() {
|
||||
it('should run a remote query that is part of a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-qlpack/in-pack.ql');
|
||||
|
||||
const querySubmissionResult = await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(querySubmissionResult).to.be.ok;
|
||||
await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(mockSubmitRemoteQueries).to.have.been.calledOnce;
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorRemoteQuery', sinon.match.string, sinon.match.has('queryFilePath', fileUri.fsPath));
|
||||
|
||||
const request: RemoteQueriesSubmission = mockSubmitRemoteQueries.getCall(0).lastArg;
|
||||
|
||||
@@ -148,10 +151,10 @@ describe('Remote queries', function() {
|
||||
it('should run a remote query that is not part of a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-no-qlpack/in-pack.ql');
|
||||
|
||||
const querySubmissionResult = await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(querySubmissionResult).to.be.ok;
|
||||
await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(mockSubmitRemoteQueries).to.have.been.calledOnce;
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorRemoteQuery', sinon.match.string, sinon.match.has('queryFilePath', fileUri.fsPath));
|
||||
|
||||
const request: RemoteQueriesSubmission = mockSubmitRemoteQueries.getCall(0).lastArg;
|
||||
|
||||
@@ -196,10 +199,10 @@ describe('Remote queries', function() {
|
||||
it('should run a remote query that is nested inside a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-qlpack-nested/subfolder/in-pack.ql');
|
||||
|
||||
const querySubmissionResult = await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(querySubmissionResult).to.be.ok;
|
||||
await remoteQueriesManager.runRemoteQuery(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(mockSubmitRemoteQueries).to.have.been.calledOnce;
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorRemoteQuery', sinon.match.string, sinon.match.has('queryFilePath', fileUri.fsPath));
|
||||
|
||||
const request: RemoteQueriesSubmission = mockSubmitRemoteQueries.getCall(0).lastArg;
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ describe('Variant Analysis Manager', async function() {
|
||||
let mockGetRepositoryFromNwo: sinon.SinonStub;
|
||||
let mockSubmitVariantAnalysis: sinon.SinonStub;
|
||||
let mockApiResponse: VariantAnalysisApiResponse;
|
||||
let executeCommandSpy: sinon.SinonStub;
|
||||
|
||||
const baseDir = path.join(__dirname, '../../../../src/vscode-tests/cli-integration');
|
||||
function getFile(file: string): Uri {
|
||||
@@ -111,6 +112,8 @@ describe('Variant Analysis Manager', async function() {
|
||||
.onFirstCall().resolves({ repositories: ['github/vscode-codeql'] } as unknown as QuickPickItem)
|
||||
.onSecondCall().resolves('javascript' as unknown as QuickPickItem);
|
||||
|
||||
executeCommandSpy = sandbox.stub(commands, 'executeCommand').callThrough();
|
||||
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
const dummyRepository: Repository = {
|
||||
@@ -132,10 +135,9 @@ describe('Variant Analysis Manager', async function() {
|
||||
it('should run a variant analysis that is part of a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-qlpack/in-pack.ql');
|
||||
|
||||
const variantAnalysis = await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(variantAnalysis).to.be.ok;
|
||||
expect(variantAnalysis.id).to.be.equal(mockApiResponse.id);
|
||||
expect(variantAnalysis.status).to.be.equal(VariantAnalysisStatus.InProgress);
|
||||
await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorVariantAnalysis', sinon.match.has('id', mockApiResponse.id).and(sinon.match.has('status', VariantAnalysisStatus.InProgress)));
|
||||
|
||||
expect(showQuickPickSpy).to.have.been.calledOnce;
|
||||
|
||||
@@ -146,10 +148,9 @@ describe('Variant Analysis Manager', async function() {
|
||||
it('should run a remote query that is not part of a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-no-qlpack/in-pack.ql');
|
||||
|
||||
const variantAnalysis = await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(variantAnalysis).to.be.ok;
|
||||
expect(variantAnalysis.id).to.be.equal(mockApiResponse.id);
|
||||
expect(variantAnalysis.status).to.be.equal(VariantAnalysisStatus.InProgress);
|
||||
await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorVariantAnalysis', sinon.match.has('id', mockApiResponse.id).and(sinon.match.has('status', VariantAnalysisStatus.InProgress)));
|
||||
|
||||
expect(mockGetRepositoryFromNwo).to.have.been.calledOnce;
|
||||
expect(mockSubmitVariantAnalysis).to.have.been.calledOnce;
|
||||
@@ -158,10 +159,9 @@ describe('Variant Analysis Manager', async function() {
|
||||
it('should run a remote query that is nested inside a qlpack', async () => {
|
||||
const fileUri = getFile('data-remote-qlpack-nested/subfolder/in-pack.ql');
|
||||
|
||||
const variantAnalysis = await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
expect(variantAnalysis).to.be.ok;
|
||||
expect(variantAnalysis.id).to.be.equal(mockApiResponse.id);
|
||||
expect(variantAnalysis.status).to.be.equal(VariantAnalysisStatus.InProgress);
|
||||
await variantAnalysisManager.runVariantAnalysis(fileUri, progress, cancellationTokenSource.token);
|
||||
|
||||
expect(executeCommandSpy).to.have.been.calledWith('codeQL.monitorVariantAnalysis', sinon.match.has('id', mockApiResponse.id).and(sinon.match.has('status', VariantAnalysisStatus.InProgress)));
|
||||
|
||||
expect(mockGetRepositoryFromNwo).to.have.been.calledOnce;
|
||||
expect(mockSubmitVariantAnalysis).to.have.been.calledOnce;
|
||||
|
||||
Reference in New Issue
Block a user