Skip to content

Commit bd67996

Browse files
committed
Add ballerina tests
1 parent 3a028bf commit bd67996

File tree

8 files changed

+146
-6
lines changed

8 files changed

+146
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as path from 'path';
7+
import * as vscode from 'vscode';
8+
import { FuncVersion, ProjectLanguage, funcVersionSetting, projectLanguageSetting } from '../../extension.bundle';
9+
import { allTemplateSources, isLongRunningVersion } from '../global.test';
10+
import { getRotatingAuthLevel } from '../nightly/getRotatingValue';
11+
import { runWithFuncSetting } from '../runWithSetting';
12+
import { CreateFunctionTestCase, FunctionTesterBase } from './FunctionTesterBase';
13+
14+
class BallerinaFunctionTester extends FunctionTesterBase {
15+
public language: ProjectLanguage = ProjectLanguage.Ballerina;
16+
17+
public getExpectedPaths(functionName: string): string[] {
18+
return [
19+
path.join(functionName + '.bal')
20+
];
21+
}
22+
}
23+
24+
for (const version of [FuncVersion.v2, FuncVersion.v3, FuncVersion.v4]) {
25+
for (const source of allTemplateSources) {
26+
addSuite(new BallerinaFunctionTester(version, source));
27+
}
28+
}
29+
30+
function addSuite(tester: FunctionTesterBase): void {
31+
const testCases: CreateFunctionTestCase[] = [
32+
{
33+
functionName: 'Blob trigger',
34+
inputs: [
35+
'AzureWebJobsStorage', // Use existing app setting
36+
'test-path/{name}'
37+
]
38+
},
39+
{
40+
functionName: 'CosmosDB trigger',
41+
inputs: [
42+
'AzureWebJobsStorage', // Use existing app setting
43+
'dbName',
44+
'collectionName'
45+
]
46+
},
47+
{
48+
functionName: 'HTTP trigger',
49+
inputs: [
50+
getRotatingAuthLevel()
51+
]
52+
},
53+
{
54+
functionName: 'Queue trigger',
55+
inputs: [
56+
'AzureWebJobsStorage', // Use existing app setting
57+
'testqueue'
58+
]
59+
},
60+
{
61+
functionName: 'Timer trigger',
62+
inputs: [
63+
'0 * * */3 * *'
64+
]
65+
}
66+
];
67+
68+
tester.addParallelSuite(testCases, {
69+
isLongRunning: isLongRunningVersion(tester.version),
70+
addTests: () => {
71+
// https://github.com/Microsoft/vscode-azurefunctions/blob/main/docs/api.md#create-local-function
72+
test('createFunction API (deprecated)', async () => {
73+
const templateId: string = `HttpTrigger-${tester.language}`;
74+
const functionName: string = 'createFunctionApi';
75+
const authLevel: string = 'Anonymous';
76+
// Intentionally testing weird casing for authLevel
77+
await runWithFuncSetting(projectLanguageSetting, tester.language, async () => {
78+
await runWithFuncSetting(funcVersionSetting, tester.version, async () => {
79+
await vscode.commands.executeCommand('azureFunctions.createFunction', tester.projectPath, templateId, functionName, { aUtHLevel: authLevel });
80+
});
81+
});
82+
await tester.validateFunction(tester.projectPath, functionName, [authLevel]);
83+
});
84+
}
85+
});
86+
}

test/nightly/createProjectAndDeploy.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode';
1212
import { copyFunctionUrl, createGenericClient, createNewProjectInternal, deployProductionSlot, FuncVersion, getRandomHexString, nonNullProp } from '../../extension.bundle';
1313
import { addParallelSuite, ParallelTest, runInSeries } from '../addParallelSuite';
1414
import { getTestWorkspaceFolder } from '../global.test';
15-
import { defaultTestFuncVersion, getCSharpValidateOptions, getJavaScriptValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from '../project/validateProject';
15+
import { defaultTestFuncVersion, getCSharpValidateOptions, getJavaScriptValidateOptions, getBallerinaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from '../project/validateProject';
1616
import { getRotatingAuthLevel, getRotatingLocation, getRotatingNodeVersion, getRotatingPythonVersion } from './getRotatingValue';
1717
import { resourceGroupsToDelete } from './global.nightly.test';
1818

@@ -24,6 +24,7 @@ interface CreateProjectAndDeployTestCase extends ICreateProjectAndDeployOptions
2424
const testCases: CreateProjectAndDeployTestCase[] = [
2525
{ title: 'JavaScript', ...getJavaScriptValidateOptions(true), deployInputs: [getRotatingNodeVersion()] },
2626
{ title: 'TypeScript', ...getTypeScriptValidateOptions(), deployInputs: [getRotatingNodeVersion()] },
27+
{ title: 'Ballerina', ...getBallerinaValidateOptions(), deployInputs: [/java.*11/i] },
2728
// All C# tests on mac and .NET 6 on windows are consistently timing out for some unknown reason. Will skip for now
2829
{ title: 'C# .NET Core 3.1', buildMachineOsToSkip: 'darwin', ...getCSharpValidateOptions('netcoreapp3.1'), createProjectInputs: [/net.*3/i], deployInputs: [/net.*3/i], createFunctionInputs: ['Company.Function'] },
2930
{ title: 'C# .NET 5', buildMachineOsToSkip: 'darwin', ...getCSharpValidateOptions('net5.0'), createProjectInputs: [/net.*5/i], deployInputs: [/net.*5/i], createFunctionInputs: ['Company.Function'] },

test/project/createAndValidateProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { TestActionContext, TestInput } from '@microsoft/vscode-azext-dev';
77
import * as path from 'path';
8-
import { createNewProjectInternal, getRandomHexString, hiddenStacksSetting, ProjectLanguage } from '../../extension.bundle';
8+
import { ProjectLanguage, createNewProjectInternal, getRandomHexString, hiddenStacksSetting } from '../../extension.bundle';
99
// eslint-disable-next-line no-restricted-imports
1010
import * as api from '../../src/vscode-azurefunctions.api';
1111
import { testFolderPath } from '../global.test';
@@ -33,7 +33,7 @@ export async function createAndValidateProject(context: TestActionContext, optio
3333

3434
// All languages except Java support creating a function after creating a project
3535
// Java needs to fix this issue first: https://github.com/Microsoft/vscode-azurefunctions/issues/81
36-
if (language !== ProjectLanguage.Java) {
36+
if (language !== (ProjectLanguage.Java)) {
3737
// don't create function
3838
inputs.push(/skip for now/i);
3939
}

test/project/createNewProject.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FuncVersion, JavaBuildTool, ProjectLanguage, TemplateSource } from '../
88
import { addParallelSuite, ParallelTest } from '../addParallelSuite';
99
import { allTemplateSources, runForTemplateSource, shouldSkipVersion } from '../global.test';
1010
import { createAndValidateProject, ICreateProjectTestOptions } from './createAndValidateProject';
11-
import { getCSharpValidateOptions, getCustomValidateOptions, getDotnetScriptValidateOptions, getFSharpValidateOptions, getJavaScriptValidateOptions, getJavaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions } from './validateProject';
11+
import { getBallerinaValidateOptions, getCSharpValidateOptions, getCustomValidateOptions, getDotnetScriptValidateOptions, getFSharpValidateOptions, getJavaScriptValidateOptions, getJavaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions } from './validateProject';
1212

1313
interface CreateProjectTestCase extends ICreateProjectTestOptions {
1414
description?: string;
@@ -59,6 +59,13 @@ for (const version of [FuncVersion.v2, FuncVersion.v3, FuncVersion.v4]) {
5959
inputs: javaBaseInputs.concat(/Maven/i),
6060
description: JavaBuildTool.maven
6161
});
62+
const ballerinaBaseInputs: (TestInput | string | RegExp)[] = [/JVM/i];
63+
64+
testCases.push({
65+
...getBallerinaValidateOptions(version),
66+
inputs: ballerinaBaseInputs,
67+
description: 'ballerina'
68+
});
6269
}
6370

6471
testCases.push({ ...getCustomValidateOptions(FuncVersion.v3) });

test/project/initProjectForVSCode.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
88
import * as path from 'path';
99
import { FuncVersion, getRandomHexString, initProjectForVSCode, JavaBuildTool, ProjectLanguage } from '../../extension.bundle';
1010
import { cleanTestWorkspace, testFolderPath } from '../global.test';
11-
import { getCSharpValidateOptions, getCustomValidateOptions, getFSharpValidateOptions, getJavaScriptValidateOptions, getJavaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from './validateProject';
11+
import { getBallerinaValidateOptions, getCSharpValidateOptions, getCustomValidateOptions, getFSharpValidateOptions, getJavaScriptValidateOptions, getJavaValidateOptions, getPowerShellValidateOptions, getPythonValidateOptions, getTypeScriptValidateOptions, IValidateProjectOptions, validateProject } from './validateProject';
1212

1313
suite('Init Project For VS Code', function (this: Mocha.Suite): void {
1414
this.timeout(30 * 1000);
@@ -116,6 +116,19 @@ suite('Init Project For VS Code', function (this: Mocha.Suite): void {
116116
await initAndValidateProject({ ...getJavaValidateOptions(appName, JavaBuildTool.gradle), mockFiles });
117117
});
118118

119+
test('Ballerina', async () => {
120+
const mockFiles: MockFile[] = [
121+
{
122+
fsPath: 'Ballerina.toml',
123+
contents: `[package]
124+
org = "testorg"
125+
name = "azf_test"
126+
version = "0.1.0"`
127+
}
128+
];
129+
await initAndValidateProject({ ...getBallerinaValidateOptions(), mockFiles });
130+
});
131+
119132
test('PowerShell', async () => {
120133
await initAndValidateProject({ ...getPowerShellValidateOptions(), mockFiles: [['HttpTriggerPS', 'run.ps1'], 'profile.ps1', 'requirements.psd1'] });
121134
});

test/project/validateProject.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ export function getJavaValidateOptions(appName: string, buildTool: string, versi
204204
};
205205
}
206206

207+
export function getBallerinaValidateOptions(version: FuncVersion = defaultTestFuncVersion): IValidateProjectOptions {
208+
return {
209+
language: ProjectLanguage.Ballerina,
210+
version,
211+
expectedSettings: {
212+
'azureFunctions.projectLanguage': ProjectLanguage.Ballerina,
213+
'azureFunctions.projectRuntime': version,
214+
'azureFunctions.preDeployTask': 'package (functions)',
215+
'azureFunctions.deploySubpath': 'target/azure_functions',
216+
'debug.internalConsoleOptions': 'neverOpen',
217+
},
218+
expectedExtensionRecs: [
219+
'WSO2.ballerina',
220+
],
221+
expectedDebugConfigs: [
222+
'Attach to Ballerina Functions'
223+
],
224+
expectedTasks: [
225+
'func: host start',
226+
'package (functions)'
227+
],
228+
expectedPaths: ['Ballerina.toml'],
229+
excludedPaths: [
230+
'.funcignore'
231+
],
232+
};
233+
}
234+
207235
export function getDotnetScriptValidateOptions(language: ProjectLanguage, version: FuncVersion = defaultTestFuncVersion): IValidateProjectOptions {
208236
return {
209237
language,

test/templateCount.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ function addSuite(source: TemplateSource | undefined): void {
4545
{ language: ProjectLanguage.PowerShell, version: FuncVersion.v2, expectedCount: 14 },
4646
{ language: ProjectLanguage.PowerShell, version: FuncVersion.v3, expectedCount: 14 },
4747
{ language: ProjectLanguage.PowerShell, version: FuncVersion.v4, expectedCount: 14 },
48-
{ language: ProjectLanguage.Java, version: FuncVersion.v2, expectedCount: 4 }
48+
{ language: ProjectLanguage.Java, version: FuncVersion.v2, expectedCount: 4 },
4949
// https://github.com/microsoft/vscode-azurefunctions/issues/1605
5050
// { language: ProjectLanguage.Java, version: FuncVersion.v3, expectedCount: 4}]
51+
{ language: ProjectLanguage.Ballerina, version: FuncVersion.v1, expectedCount: 5 },
52+
{ language: ProjectLanguage.Ballerina, version: FuncVersion.v2, expectedCount: 5 },
53+
{ language: ProjectLanguage.Ballerina, version: FuncVersion.v3, expectedCount: 5 },
54+
{ language: ProjectLanguage.Ballerina, version: FuncVersion.v4, expectedCount: 5 }
5155
];
5256

5357
let testWorkspacePath: string;

0 commit comments

Comments
 (0)