-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathcreateFunction.Script.v2.test.ts
More file actions
182 lines (170 loc) · 6.36 KB
/
createFunction.Script.v2.test.ts
File metadata and controls
182 lines (170 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as vscode from 'vscode';
import { FuncVersion, funcVersionSetting, ProjectLanguage, projectLanguageSetting } from '../../extension.bundle';
import { allTemplateSources, isLongRunningVersion } from '../global.test';
import { getRotatingAuthLevel } from '../nightly/getRotatingValue';
import { runWithFuncSetting } from '../runWithSetting';
import { CreateFunctionTestCase, FunctionTesterBase } from './FunctionTesterBase';
class JavaScriptFunctionTester extends FunctionTesterBase {
public language: ProjectLanguage = ProjectLanguage.JavaScript;
public getExpectedPaths(functionName: string): string[] {
return [
path.join(functionName, 'function.json'),
path.join(functionName, 'index.js')
];
}
}
class TypeScriptFunctionTester extends FunctionTesterBase {
public language: ProjectLanguage = ProjectLanguage.TypeScript;
public getExpectedPaths(functionName: string): string[] {
return [
path.join(functionName, 'function.json'),
path.join(functionName, 'index.ts')
];
}
}
class PythonFunctionTester extends FunctionTesterBase {
public language: ProjectLanguage = ProjectLanguage.Python;
public getExpectedPaths(functionName: string): string[] {
return [
path.join(functionName, 'function.json'),
path.join(functionName, '__init__.py')
];
}
}
class PowerShellFunctionTester extends FunctionTesterBase {
public language: ProjectLanguage = ProjectLanguage.PowerShell;
public getExpectedPaths(functionName: string): string[] {
return [
path.join(functionName, 'function.json'),
path.join(functionName, 'run.ps1')
];
}
}
for (const version of [FuncVersion.v2, FuncVersion.v3, FuncVersion.v4]) {
for (const source of allTemplateSources) {
addSuite(new JavaScriptFunctionTester(version, source));
addSuite(new TypeScriptFunctionTester(version, source));
addSuite(new PythonFunctionTester(version, source));
addSuite(new PowerShellFunctionTester(version, source));
}
}
function addSuite(tester: FunctionTesterBase): void {
const testCases: CreateFunctionTestCase[] = [
{
functionName: 'Azure Blob Storage trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'test-path/{name}'
]
},
{
functionName: 'Azure Cosmos DB trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'dbName',
'collectionName',
'testLeases',
'false' // 'create leases if doesn't exist'
]
},
{
functionName: 'Azure Event Grid trigger',
inputs: []
},
{
functionName: 'Azure Event Hub trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'eventHubName',
'testConsumerGroup'
]
},
{
functionName: 'HTTP trigger',
inputs: [
getRotatingAuthLevel()
]
},
{
functionName: 'Azure Queue Storage trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'testqueue'
]
},
{
functionName: 'Azure Service Bus Queue trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'testQueue'
]
},
{
functionName: 'Azure Service Bus Topic trigger',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'testTopic',
'testSubscription'
]
},
{
functionName: 'Timer trigger',
inputs: [
'0 * * */3 * *'
]
},
{
functionName: 'Durable Functions activity',
inputs: [],
skip: tester.language === ProjectLanguage.Custom
},
{
functionName: 'Durable Functions HTTP starter',
inputs: [
getRotatingAuthLevel()
],
skip: tester.language === ProjectLanguage.Custom
},
{
functionName: 'Durable Functions orchestrator',
inputs: [],
skip: tester.language === ProjectLanguage.Custom
},
{
functionName: 'IoT Hub (Event Hub)',
inputs: [
'AzureWebJobsStorage', // Use existing app setting
'testConsumerGroup'
],
skip: tester.language === ProjectLanguage.Python
},
{
functionName: 'SendGrid',
inputs: [],
skip: tester.language === ProjectLanguage.Python
}
];
tester.addParallelSuite(testCases, {
isLongRunning: isLongRunningVersion(tester.version),
addTests: () => {
// https://github.com/Microsoft/vscode-azurefunctions/blob/main/docs/api.md#create-local-function
test('createFunction API (deprecated)', async () => {
const templateId: string = `HttpTrigger-${tester.language}`;
const functionName: string = 'createFunctionApi';
const authLevel: string = 'Anonymous';
// Intentionally testing weird casing for authLevel
await runWithFuncSetting(projectLanguageSetting, tester.language, async () => {
await runWithFuncSetting(funcVersionSetting, tester.version, async () => {
await vscode.commands.executeCommand('azureFunctions.createFunction', tester.projectPath, templateId, functionName, { aUtHLevel: authLevel });
});
});
await tester.validateFunction(tester.projectPath, functionName, [authLevel]);
});
}
});
}