Skip to content

Commit f089d52

Browse files
committed
Fix tests I think
1 parent c84c892 commit f089d52

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ext/vscode/src/services/AzureDevShowProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export interface AzureDevShowProvider {
3535
}
3636

3737
export class WorkspaceAzureDevShowProvider implements AzureDevShowProvider {
38-
public constructor(private readonly execAsyncFunction = execAsync) {
38+
public constructor(private readonly createAzureDevCliFunction = createAzureDevCli, private readonly execAsyncFunction = execAsync) {
3939
}
4040

4141
public async getShowResults(context: IActionContext, configurationFile: vscode.Uri, environmentName?: string): Promise<AzDevShowResults> {
42-
const azureCli = await createAzureDevCli(context);
42+
const azureCli = await this.createAzureDevCliFunction(context);
4343

4444
const configurationFileDirectory = path.dirname(configurationFile.fsPath);
4545

ext/vscode/src/test/suite/unit/azureDevShowProvider.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IActionContext } from '@microsoft/vscode-azext-utils';
1010
suite('AzureDevShowProvider Error Handling Tests', () => {
1111
let sandbox: sinon.SinonSandbox;
1212
let mockContext: IActionContext;
13+
let mockCreateAzureDevCli: sinon.SinonStub;
1314

1415
setup(() => {
1516
sandbox = sinon.createSandbox();
@@ -25,6 +26,12 @@ suite('AzureDevShowProvider Error Handling Tests', () => {
2526
},
2627
valuesToMask: [],
2728
} as unknown as IActionContext;
29+
30+
const mockAzureCli = {
31+
invocation: 'azd',
32+
spawnOptions: () => ({ cwd: '/test' })
33+
};
34+
mockCreateAzureDevCli = sandbox.stub().resolves(mockAzureCli);
2835
});
2936

3037
teardown(() => {
@@ -35,7 +42,7 @@ suite('AzureDevShowProvider Error Handling Tests', () => {
3542
const mockExecAsync = sandbox.stub().rejects(
3643
new Error('ERROR: parsing project file: unable to parse azure.yaml file. File is empty.')
3744
);
38-
const provider = new WorkspaceAzureDevShowProvider(mockExecAsync);
45+
const provider = new WorkspaceAzureDevShowProvider(mockCreateAzureDevCli, mockExecAsync);
3946

4047
const configUri = vscode.Uri.file('/test/azure.yaml');
4148

@@ -53,7 +60,7 @@ suite('AzureDevShowProvider Error Handling Tests', () => {
5360
const mockExecAsync = sandbox.stub().rejects(
5461
new Error('ERROR: parsing project file: invalid YAML syntax')
5562
);
56-
const provider = new WorkspaceAzureDevShowProvider(mockExecAsync);
63+
const provider = new WorkspaceAzureDevShowProvider(mockCreateAzureDevCli, mockExecAsync);
5764

5865
const configUri = vscode.Uri.file('/test/azure.yaml');
5966

@@ -70,7 +77,7 @@ suite('AzureDevShowProvider Error Handling Tests', () => {
7077
test('Other errors are re-thrown unchanged', async () => {
7178
const originalError = new Error('Some other error');
7279
const mockExecAsync = sandbox.stub().rejects(originalError);
73-
const provider = new WorkspaceAzureDevShowProvider(mockExecAsync);
80+
const provider = new WorkspaceAzureDevShowProvider(mockCreateAzureDevCli, mockExecAsync);
7481

7582
const configUri = vscode.Uri.file('/test/azure.yaml');
7683

@@ -94,7 +101,7 @@ suite('AzureDevShowProvider Error Handling Tests', () => {
94101
};
95102

96103
const mockExecAsync = sandbox.stub().resolves({ stdout: JSON.stringify(mockResults), stderr: '' });
97-
const provider = new WorkspaceAzureDevShowProvider(mockExecAsync);
104+
const provider = new WorkspaceAzureDevShowProvider(mockCreateAzureDevCli, mockExecAsync);
98105

99106
const configUri = vscode.Uri.file('/test/azure.yaml');
100107
const results = await provider.getShowResults(mockContext, configUri);

0 commit comments

Comments
 (0)