-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathcreateFunction.CSharp.test.ts
More file actions
189 lines (180 loc) · 7.39 KB
/
createFunction.CSharp.test.ts
File metadata and controls
189 lines (180 loc) · 7.39 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
183
184
185
186
187
188
189
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import * as vscode from 'vscode';
import { durableUtils, FuncVersion, funcVersionSetting, ProjectLanguage, projectLanguageSetting, TemplateSource } from '../../extension.bundle';
import { allTemplateSources, isLongRunningVersion } from '../global.test';
import { getRotatingAuthLevel } from '../nightly/getRotatingValue';
import { runWithFuncSetting } from '../runWithSetting';
import { CreateFunctionTestCase, FunctionTesterBase } from './FunctionTesterBase';
class CSharpFunctionTester extends FunctionTesterBase {
public language: ProjectLanguage = ProjectLanguage.CSharp;
private _targetFramework: string;
private _isIsolated: boolean;
public constructor(version: FuncVersion, targetFramework: string, source: TemplateSource, isIsolated: boolean) {
super(version, source);
this._targetFramework = targetFramework;
this._isIsolated = isIsolated;
}
public getExpectedPaths(functionName: string): string[] {
return [functionName + '.cs'];
}
protected async initializeTestFolder(testFolder: string): Promise<void> {
await super.initializeTestFolder(testFolder);
await AzExtFsExtra.writeFile(path.join(testFolder, 'test.csproj'), `<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>${this._targetFramework}</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="${this._isIsolated ? 'Microsoft.Azure.Functions.Worker.Sdk' : 'Microsoft.NET.Sdk.Functions'}" Version="1.0.0" />
<PackageReference Include="${durableUtils.dotnetInProcDfBasePackage}" Version="2.9.2" />
</ItemGroup>
</Project>`);
}
}
for (const source of allTemplateSources) {
addSuite(FuncVersion.v2, 'netcoreapp2.1', source);
addSuite(FuncVersion.v3, 'netcoreapp3.1', source);
addSuite(FuncVersion.v4, 'net6.0', source, true);
addSuite(FuncVersion.v4, 'net6.0', source, false);
addSuite(FuncVersion.v4, 'net7.0', source, true);
}
function addSuite(version: FuncVersion, targetFramework: string, source: TemplateSource, isIsolated?: boolean): void {
const testCases: CreateFunctionTestCase[] = [
{
functionName: 'Azure Blob Storage trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testpath'
]
},
{
functionName: 'Azure Cosmos DB trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testDB',
'testCollection'
]
},
{
functionName: 'Durable Functions Orchestration',
inputs: [
'TestCompany.TestFunction'
],
// skip: isIsolated
},
{
functionName: 'Azure Event Grid trigger',
inputs: [
'TestCompany.TestFunction'
]
},
{
functionName: 'EventGridCloudEventTrigger',
inputs: [
'TestCompany.TestFunction'
],
skip: isIsolated,
},
{
functionName: 'Azure Event Hub trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testEventHub'
]
},
{
functionName: 'IoT Hub (Event Hub)',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testmessages/testevents'
],
skip: isIsolated
},
{
functionName: 'HTTP trigger',
inputs: [
'TestCompany.TestFunction',
getRotatingAuthLevel()
]
},
{
functionName: 'HTTP trigger with OpenAPI',
inputs: [
'TestCompany.TestFunction',
getRotatingAuthLevel()
],
skip: version === FuncVersion.v2 || isIsolated
},
{
functionName: 'Azure Queue Storage trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testqueue'
]
},
{
functionName: 'Azure Service Bus Queue trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testQueue'
]
},
{
functionName: 'Azure Service Bus Topic trigger',
inputs: [
'TestCompany.TestFunction',
'AzureWebJobsStorage', // Use existing app setting
'testTopic',
'testSubscription'
]
},
{
functionName: 'Timer trigger',
inputs: [
'TestCompany.TestFunction',
'0 * * * */6 *'
]
}
];
const tester: CSharpFunctionTester = new CSharpFunctionTester(version, targetFramework, source, !!isIsolated);
let title: string = tester.suiteName + ` ${targetFramework}`;
if (isIsolated) {
title += ' Isolated';
}
tester.addParallelSuite(testCases, {
title,
timeoutMS: 60 * 1000,
isLongRunning: isLongRunningVersion(version),
suppressParallel: true, // lots of errors like "The process cannot access the file because it is being used by another process" 😢
addTests: () => {
if (version === FuncVersion.v2) {
// https://github.com/Microsoft/vscode-azurefunctions/blob/main/docs/api.md#create-local-function
test('createFunction API (deprecated)', async () => {
// Intentionally testing IoTHub trigger since a partner team plans to use that
const templateId: string = 'Azure.Function.CSharp.IotHubTrigger.2.x';
const functionName: string = 'createFunctionApi';
const namespace: string = 'TestCompany.TestFunction';
const iotPath: string = 'messages/events';
const connection: string = 'IoTHub_Setting';
await runWithFuncSetting(projectLanguageSetting, ProjectLanguage.CSharp, async () => {
await runWithFuncSetting(funcVersionSetting, FuncVersion.v2, async () => {
// Intentionally testing weird casing
await vscode.commands.executeCommand('azureFunctions.createFunction', tester.projectPath, templateId, functionName, { namEspace: namespace, PaTh: iotPath, ConneCtion: connection });
});
});
await tester.validateFunction(tester.projectPath, functionName, [namespace, iotPath, connection]);
});
}
}
});
}