Test that we only download results once per repo

To make us confident that we're not repeatedly downloading results.
This commit is contained in:
Elena Tanasoiu
2022-10-12 12:24:34 +01:00
parent 64994d7c03
commit 67a6ab5c8e

View File

@@ -1,6 +1,6 @@
import * as sinon from 'sinon'; import * as sinon from 'sinon';
import { expect } from 'chai'; import { expect } from 'chai';
import { CancellationTokenSource, extensions } from 'vscode'; import { CancellationTokenSource, commands, extensions } from 'vscode';
import { CodeQLExtensionInterface } from '../../../extension'; import { CodeQLExtensionInterface } from '../../../extension';
import { logger } from '../../../logging'; import { logger } from '../../../logging';
import * as config from '../../../config'; import * as config from '../../../config';
@@ -115,7 +115,7 @@ describe('Variant Analysis Monitor', async function() {
describe('when there are successfully scanned repos', async () => { describe('when there are successfully scanned repos', async () => {
beforeEach(async function() { beforeEach(async function() {
scannedRepos = createMockScannedRepos(['pending', 'in_progress', 'succeeded']); scannedRepos = createMockScannedRepos(['pending', 'pending', 'in_progress', 'in_progress', 'succeeded', 'succeeded', 'succeeded']);
mockApiResponse = createMockApiResponse('completed', scannedRepos); mockApiResponse = createMockApiResponse('completed', scannedRepos);
mockGetVariantAnalysis = sandbox.stub(ghApiClient, 'getVariantAnalysis').resolves(mockApiResponse); mockGetVariantAnalysis = sandbox.stub(ghApiClient, 'getVariantAnalysis').resolves(mockApiResponse);
}); });
@@ -127,6 +127,21 @@ describe('Variant Analysis Monitor', async function() {
expect(result.status).to.equal('CompletedSuccessfully'); expect(result.status).to.equal('CompletedSuccessfully');
expect(result.scannedReposDownloaded).to.eql(scannedRepoIds); expect(result.scannedReposDownloaded).to.eql(scannedRepoIds);
}); });
it('should trigger a download extension command for each repo', async () => {
const succeededRepos = scannedRepos.filter(r => r.analysis_status === 'succeeded');
const commandSpy = sandbox.spy(commands, 'executeCommand');
await variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis, cancellationTokenSource.token);
expect(commandSpy).to.have.callCount(succeededRepos.length);
succeededRepos.forEach((succeededRepo, index) => {
expect(commandSpy.getCall(index).args[0]).to.eq('codeQL.autoDownloadVariantAnalysisResult');
expect(commandSpy.getCall(index).args[1]).to.eq(succeededRepo);
expect(commandSpy.getCall(index).args[2]).to.eq(mockApiResponse);
});
});
}); });
describe('when there are only in progress repos', async () => { describe('when there are only in progress repos', async () => {