|
| 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 | +} |
0 commit comments