Skip to content

Commit 3902596

Browse files
committed
Use real zip file for VariantAnalysisManager download tests
Now that we're unzipping results, we also have to use something closer to a zip file when testing download functionality for the `variantAnalysisManager`. The `variantAnalysisManager` has access to the `variantAnalysisResultsManager` so we could've stubbed the result manager's `download` method instead of going as far as using a zip fixture. However, since the results manager is private it seems bad to make it public in order to stub one of its methods. So using realistic data in the setup seems like a good compromise.
1 parent c400485 commit 3902596

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/variant-analysis-manager.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import * as config from '../../../config';
77
import * as ghApiClient from '../../../remote-queries/gh-api/gh-api-client';
88
import { Credentials } from '../../../authentication';
99
import * as fs from 'fs-extra';
10+
import * as path from 'path';
1011

1112
import { VariantAnalysisManager } from '../../../remote-queries/variant-analysis-manager';
1213
import {
1314
VariantAnalysis as VariantAnalysisApiResponse,
15+
VariantAnalysisRepoTask,
1416
VariantAnalysisScannedRepository as ApiVariantAnalysisScannedRepository
1517
} from '../../../remote-queries/gh-api/variant-analysis';
1618
import { createMockApiResponse } from '../../factories/remote-queries/gh-api/variant-analysis-api-response';
@@ -72,6 +74,7 @@ describe('Variant Analysis Manager', async function() {
7274

7375
describe('when credentials are valid', async () => {
7476
let getOctokitStub: sinon.SinonStub;
77+
let arrayBuffer: ArrayBuffer;
7578

7679
beforeEach(async () => {
7780
const mockCredentials = {
@@ -80,16 +83,18 @@ describe('Variant Analysis Manager', async function() {
8083
})
8184
} as unknown as Credentials;
8285
sandbox.stub(Credentials, 'initialize').resolves(mockCredentials);
86+
87+
const sourceFilePath = path.join(__dirname, '../../../../src/vscode-tests/cli-integration/data/variant-analysis-results.zip');
88+
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
8389
});
8490

8591
describe('when the artifact_url is missing', async () => {
8692
beforeEach(async () => {
8793
const dummyRepoTask = createMockVariantAnalysisRepoTask();
8894
delete dummyRepoTask.artifact_url;
89-
getVariantAnalysisRepoStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepo').resolves(dummyRepoTask);
9095

91-
const dummyResult = new ArrayBuffer(24);
92-
getVariantAnalysisRepoResultStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepoResult').resolves(dummyResult);
96+
getVariantAnalysisRepoStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepo').resolves(dummyRepoTask);
97+
getVariantAnalysisRepoResultStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepoResult').resolves(arrayBuffer);
9398
});
9499

95100
it('should not try to download the result', async () => {
@@ -104,12 +109,13 @@ describe('Variant Analysis Manager', async function() {
104109
});
105110

106111
describe('when the artifact_url is present', async () => {
112+
let dummyRepoTask: VariantAnalysisRepoTask;
113+
107114
beforeEach(async () => {
108-
const dummyRepoTask = createMockVariantAnalysisRepoTask();
109-
getVariantAnalysisRepoStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepo').resolves(dummyRepoTask);
115+
dummyRepoTask = createMockVariantAnalysisRepoTask();
110116

111-
const dummyResult = new ArrayBuffer(24);
112-
getVariantAnalysisRepoResultStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepoResult').resolves(dummyResult);
117+
getVariantAnalysisRepoStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepo').resolves(dummyRepoTask);
118+
getVariantAnalysisRepoResultStub = sandbox.stub(ghApiClient, 'getVariantAnalysisRepoResult').resolves(arrayBuffer);
113119
});
114120

115121
it('should return early if variant analysis is cancelled', async () => {

0 commit comments

Comments
 (0)