Skip to content

Commit 7992981

Browse files
authored
Use [ordered] in PowerShell identity tests (Azure#581)
* test ordered on the PS samples * update case sensitive samples * add readme known issue
1 parent b405662 commit 7992981

File tree

8 files changed

+19
-27
lines changed

8 files changed

+19
-27
lines changed

.vscode/launch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"name": "Attach to Function Host",
1919
"type": "coreclr",
2020
"request": "attach",
21-
"processName": "func.exe"
21+
"Windows": {
22+
"processName": "func.exe"
23+
},
24+
"processName": "func"
2225
}
2326
]
2427
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Databases on SQL Server, Azure SQL Database, or Azure SQL Managed Instance which
5050
* Have multiple functions, with dependent functions being triggered by the initial functions (through a trigger binding or other such method)
5151
* Use [dynamic (imperative)](https://learn.microsoft.com/azure/azure-functions/functions-bindings-expressions-patterns#binding-at-runtime) bindings (.NET only)
5252
* Use [IAsyncCollector](https://learn.microsoft.com/azure/azure-functions/functions-dotnet-class-library?tabs=v2%2Ccmd#writing-multiple-output-values) and call `FlushAsync` in the order desired (.NET only)
53+
- For PowerShell Functions that use hashtables must use the `[ordered]@` for the request query or request body assertion in order to upsert the data to the SQL table properly. An example can be found [here](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-powershell/AddProductsWithIdentityColumnArray/run.ps1).
5354

5455
### Input Bindings
5556
- Input bindings against tables with columns of data types 'DATETIME', 'DATETIME2', or 'SMALLDATETIME' will assume that the values are in UTC format.

samples/samples-powershell/AddProductWithIdentityColumn/run.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param($Request, $TriggerMetadata)
77
Write-Host "PowerShell function with SQL Output Binding processed a request."
88

99
# Update req_query with the query of the request
10-
$req_query = @{
10+
$req_query = [ordered]@{
1111
Name=$Request.QUERY.name;
1212
Cost=$Request.QUERY.cost;
1313
};

samples/samples-powershell/AddProductWithIdentityColumnIncluded/run.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param($Request, $TriggerMetadata)
77
Write-Host "PowerShell function with SQL Output Binding processed a request."
88

99
# Update req_query with the body of the request
10-
$req_query = @{
10+
$req_query = [ordered]@{
1111
ProductId= if($Request.QUERY.productId) { [int]$Request.QUERY.productId } else { $null };
1212
Name=$Request.QUERY.name;
1313
Cost=[int]$Request.QUERY.cost;

samples/samples-powershell/AddProductWithMultiplePrimaryColumnsAndIdentity/run.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ param($Request, $TriggerMetadata)
77
Write-Host "PowerShell function with SQL Output Binding processed a request."
88

99
# Update req_query with the body of the request
10-
$req_query = @{
11-
externalId=$Request.QUERY.externalId;
12-
name=$Request.QUERY.name;
13-
cost=$Request.QUERY.cost;
10+
$req_query = [ordered]@{
11+
ExternalId=$Request.QUERY.externalId;
12+
Name=$Request.QUERY.name;
13+
Cost=$Request.QUERY.cost;
1414
};
1515

1616
# Assign the value we want to pass to the SQL Output binding.

samples/samples-powershell/AddProductsWithIdentityColumnArray/run.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Write-Host "PowerShell function with SQL Output Binding processed a request."
99
# Update req_body with the body of the request
1010
# Note that this expects the body to be a JSON object or array of objects
1111
# which have a property matching each of the columns in the table to upsert to.
12-
$req_body = @(@{
13-
name="Cup";
14-
cost=2;
15-
}, @{
16-
name="Glasses";
17-
cost=12;
12+
$req_body = @([ordered]@{
13+
Name="Cup";
14+
Cost=2;
15+
}, [ordered]@{
16+
Name="Glasses";
17+
Cost=12;
1818
});
1919

2020
# Assign the value we want to pass to the SQL Output binding.

test/Integration/SqlOutputBindingIntegrationTests.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ public void AddProductNoPartialUpsertTest(SupportedLanguages lang)
220220
/// </summary>
221221
[Theory]
222222
[SqlInlineData()]
223-
// Currently PowerShell gives an error due to the deserialization of the object
224-
// Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/448
225-
[UnsupportedLanguages(SupportedLanguages.PowerShell)]
226223
public void AddProductWithIdentity(SupportedLanguages lang)
227224
{
228225
this.StartFunctionHost(nameof(AddProductWithIdentityColumn), lang);
@@ -243,9 +240,6 @@ public void AddProductWithIdentity(SupportedLanguages lang)
243240
/// </summary>
244241
[Theory]
245242
[SqlInlineData()]
246-
// Currently PowerShell gives an error due to the deserialization of the object
247-
// Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/448
248-
[UnsupportedLanguages(SupportedLanguages.PowerShell)]
249243
public void AddProductsWithIdentityColumnArray(SupportedLanguages lang)
250244
{
251245
this.StartFunctionHost(nameof(AddProductsWithIdentityColumnArray), lang);
@@ -261,9 +255,6 @@ public void AddProductsWithIdentityColumnArray(SupportedLanguages lang)
261255
/// </summary>
262256
[Theory]
263257
[SqlInlineData()]
264-
// Currently PowerShell gives an error due to the deserialization of the object
265-
// Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/448
266-
[UnsupportedLanguages(SupportedLanguages.PowerShell)]
267258
public void AddProductWithIdentity_MultiplePrimaryColumns(SupportedLanguages lang)
268259
{
269260
this.StartFunctionHost(nameof(AddProductWithMultiplePrimaryColumnsAndIdentity), lang);
@@ -343,9 +334,6 @@ public void AddProductWithIdentity_NoIdentityColumn(SupportedLanguages lang)
343334
/// </summary>
344335
[Theory]
345336
[SqlInlineData()]
346-
// Currently PowerShell gives an error due to the deserialization of the object
347-
// Issue link: https://github.com/Azure/azure-functions-sql-extension/issues/448
348-
[UnsupportedLanguages(SupportedLanguages.PowerShell)]
349337
public void AddProductWithIdentity_MissingPrimaryColumn(SupportedLanguages lang)
350338
{
351339
this.StartFunctionHost(nameof(AddProductWithMultiplePrimaryColumnsAndIdentity), lang);

test/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ To debug either any core extension code (anything under the `src` folder) OR fun
118118
To do this and be able to set breakpoints before the test runs you will need to follow these steps :
119119
120120
1. Go to [IntegrationTestBase.cs](./Integration/IntegrationTestBase.cs) and in `StartFunctionHost` add a `return;` on the first line - this is to skip having the test start up the function host itself (since you'll be doing it manually)
121-
2. `cd` to the directory containing the functions to run - this will be in the `test/bin/Debug/net6/SqlExtensionSamples/<LANG>` folder (e.g. `test/bin/Debug/net6/SqlExtensionSamples/samples-csharp`)
121+
2. `cd` to the directory containing the functions to run - this will be in the `test/bin/Debug/net6/SqlExtensionSamples/<LANG>` folder (e.g. `test/bin/Debug/net6/SqlExtensionSamples/CSharp`)
122122
3. Run `func host start --functions <FUNCTION_NAME>` - replacing `<FUNCTION_NAME>` with the name of the function you want to debug (e.g. `func host start --functions AddProduct`)
123-
4. Attach to the func.exe process
123+
4. Attach to the Function Host process
124124
* Visual Studio : Use `Attach to Process...`.
125125
* VS Code you can use `Attach to Function Host` debug target (at the root level of the project)
126126

0 commit comments

Comments
 (0)