diff --git a/app/v3-oldConfig/cosmosDBTrigger/function.json b/app/v3-oldConfig/cosmosDBTrigger/function.json index 702e4a80..aa0933fd 100644 --- a/app/v3-oldConfig/cosmosDBTrigger/function.json +++ b/app/v3-oldConfig/cosmosDBTrigger/function.json @@ -6,7 +6,7 @@ "direction": "in", "leaseCollectionName": "leases", "connectionStringSetting": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "collectionName": "e2eTestContainerTrigger", "createLeaseCollectionIfNotExists": true, "leaseCollectionPrefix": "2" diff --git a/app/v3-oldConfig/cosmosDBTriggerAndOutput/function.json b/app/v3-oldConfig/cosmosDBTriggerAndOutput/function.json index 19be81df..e351d266 100644 --- a/app/v3-oldConfig/cosmosDBTriggerAndOutput/function.json +++ b/app/v3-oldConfig/cosmosDBTriggerAndOutput/function.json @@ -6,7 +6,7 @@ "direction": "in", "leaseCollectionName": "leases", "connectionStringSetting": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "collectionName": "e2eTestContainerTriggerAndOutput", "createLeaseCollectionIfNotExists": true, "leaseCollectionPrefix": "1" @@ -16,7 +16,7 @@ "name": "$return", "direction": "out", "connectionStringSetting": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "collectionName": "e2eTestContainerTrigger" } ], diff --git a/app/v3-oldConfig/httpTriggerCosmosDBInput/function.json b/app/v3-oldConfig/httpTriggerCosmosDBInput/function.json index 5f0426c3..58d66595 100644 --- a/app/v3-oldConfig/httpTriggerCosmosDBInput/function.json +++ b/app/v3-oldConfig/httpTriggerCosmosDBInput/function.json @@ -17,7 +17,7 @@ "name": "inputDoc", "direction": "in", "connectionStringSetting": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "collectionName": "e2eTestContainerTriggerAndOutput", "partitionKey": "testPartKey", "id": "{Query.id}" diff --git a/app/v3-oldConfig/httpTriggerCosmosDBOutput/function.json b/app/v3-oldConfig/httpTriggerCosmosDBOutput/function.json index 9e9aeee4..0d1d8bbd 100644 --- a/app/v3-oldConfig/httpTriggerCosmosDBOutput/function.json +++ b/app/v3-oldConfig/httpTriggerCosmosDBOutput/function.json @@ -17,7 +17,7 @@ "name": "outputDoc", "direction": "out", "connectionStringSetting": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "collectionName": "e2eTestContainerTriggerAndOutput" } ], diff --git a/app/v3/cosmosDBTrigger/function.json b/app/v3/cosmosDBTrigger/function.json index 02e9d917..97b53e77 100644 --- a/app/v3/cosmosDBTrigger/function.json +++ b/app/v3/cosmosDBTrigger/function.json @@ -6,7 +6,7 @@ "direction": "in", "leaseContainerName": "leases", "connection": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "containerName": "e2eTestContainerTrigger", "createLeaseContainerIfNotExists": true, "leaseContainerPrefix": "2" diff --git a/app/v3/cosmosDBTriggerAndOutput/function.json b/app/v3/cosmosDBTriggerAndOutput/function.json index 7c9d7487..4ca8ac95 100644 --- a/app/v3/cosmosDBTriggerAndOutput/function.json +++ b/app/v3/cosmosDBTriggerAndOutput/function.json @@ -6,7 +6,7 @@ "direction": "in", "leaseContainerName": "leases", "connection": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "containerName": "e2eTestContainerTriggerAndOutput", "createLeaseContainerIfNotExists": true, "leaseContainerPrefix": "1" @@ -16,7 +16,7 @@ "name": "$return", "direction": "out", "connection": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "containerName": "e2eTestContainerTrigger" } ], diff --git a/app/v3/httpTriggerCosmosDBInput/function.json b/app/v3/httpTriggerCosmosDBInput/function.json index fb8d4232..a34f360a 100644 --- a/app/v3/httpTriggerCosmosDBInput/function.json +++ b/app/v3/httpTriggerCosmosDBInput/function.json @@ -17,7 +17,7 @@ "name": "inputDoc", "direction": "in", "connection": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "containerName": "e2eTestContainerTriggerAndOutput", "partitionKey": "testPartKey", "id": "{Query.id}" diff --git a/app/v3/httpTriggerCosmosDBOutput/function.json b/app/v3/httpTriggerCosmosDBOutput/function.json index fc540372..b2c45cc4 100644 --- a/app/v3/httpTriggerCosmosDBOutput/function.json +++ b/app/v3/httpTriggerCosmosDBOutput/function.json @@ -17,7 +17,7 @@ "name": "outputDoc", "direction": "out", "connection": "CosmosDBConnection", - "databaseName": "e2eTestDB", + "databaseName": "e2eTestCosmosDB", "containerName": "e2eTestContainerTriggerAndOutput" } ], diff --git a/app/v3/httpTriggerServiceBusOutput/function.json b/app/v3/httpTriggerServiceBusOutput/function.json index 628f9df7..c14d1fb2 100644 --- a/app/v3/httpTriggerServiceBusOutput/function.json +++ b/app/v3/httpTriggerServiceBusOutput/function.json @@ -16,8 +16,8 @@ "type": "serviceBus", "name": "outputMsg", "direction": "out", - "connection": "e2eTest_serviceBus", - "queueName": "e2eTestQueueOneTrigger" + "connection": "ServiceBusConnection", + "queueName": "e2e-test-queue-one-trigger" } ], "scriptFile": "../dist/httpTriggerServiceBusOutput/index.js" diff --git a/app/v3/httpTriggerServiceBusOutput/index.ts b/app/v3/httpTriggerServiceBusOutput/index.ts index 670c3093..1dee7499 100644 --- a/app/v3/httpTriggerServiceBusOutput/index.ts +++ b/app/v3/httpTriggerServiceBusOutput/index.ts @@ -1,14 +1,14 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context, HttpRequest } from '@azure/functions'; +import { AzureFunction, Context, HttpRequest } from '@azure/functions'; -// const httpTriggerServiceBusOutput: AzureFunction = async function ( -// context: Context, -// request: HttpRequest -// ): Promise { -// context.bindings.outputMsg = request.body.output; -// context.res = { body: 'done' }; -// }; +const httpTriggerServiceBusOutput: AzureFunction = async function ( + context: Context, + request: HttpRequest +): Promise { + context.bindings.outputMsg = request.body.output; + context.res = { body: 'done' }; +}; -// export default httpTriggerServiceBusOutput; +export default httpTriggerServiceBusOutput; diff --git a/app/v3/httpTriggerSqlInput/function.json b/app/v3/httpTriggerSqlInput/function.json index 088d52f3..986c8027 100644 --- a/app/v3/httpTriggerSqlInput/function.json +++ b/app/v3/httpTriggerSqlInput/function.json @@ -16,11 +16,11 @@ "type": "sql", "name": "inputItem", "direction": "in", - "connectionStringSetting": "e2eTest_sql", + "connectionStringSetting": "SqlConnection", "commandText": "select * from dbo.e2eSqlNonTriggerTable where id = @id", "commandType": "Text", "parameters": "@id={Query.id}" } ], "scriptFile": "../dist/httpTriggerSqlInput/index.js" -} +} \ No newline at end of file diff --git a/app/v3/httpTriggerSqlInput/index.ts b/app/v3/httpTriggerSqlInput/index.ts index 31a1c423..eb1de547 100644 --- a/app/v3/httpTriggerSqlInput/index.ts +++ b/app/v3/httpTriggerSqlInput/index.ts @@ -1,13 +1,13 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context, HttpRequest } from '@azure/functions'; +import { AzureFunction, Context, HttpRequest } from '@azure/functions'; -// const httpTriggerSqlInput: AzureFunction = async function (context: Context, _request: HttpRequest): Promise { -// context.log(`httpTriggerSqlInput was triggered`); -// context.res = { -// body: context.bindings.inputItem, -// }; -// }; +const httpTriggerSqlInput: AzureFunction = async function (context: Context, _request: HttpRequest): Promise { + context.log(`httpTriggerSqlInput was triggered`); + context.res = { + body: context.bindings.inputItem, + }; +}; -// export default httpTriggerSqlInput; +export default httpTriggerSqlInput; \ No newline at end of file diff --git a/app/v3/httpTriggerSqlOutput/function.json b/app/v3/httpTriggerSqlOutput/function.json index edc518e4..76edda65 100644 --- a/app/v3/httpTriggerSqlOutput/function.json +++ b/app/v3/httpTriggerSqlOutput/function.json @@ -16,9 +16,9 @@ "type": "sql", "name": "outputItem", "direction": "out", - "connectionStringSetting": "e2eTest_sql", + "connectionStringSetting": "SqlConnection", "commandText": "dbo.e2eSqlNonTriggerTable" } ], "scriptFile": "../dist/httpTriggerSqlOutput/index.js" -} +} \ No newline at end of file diff --git a/app/v3/httpTriggerSqlOutput/index.ts b/app/v3/httpTriggerSqlOutput/index.ts index 7b70adf4..f62e0c72 100644 --- a/app/v3/httpTriggerSqlOutput/index.ts +++ b/app/v3/httpTriggerSqlOutput/index.ts @@ -1,14 +1,14 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context, HttpRequest } from '@azure/functions'; +import { AzureFunction, Context, HttpRequest } from '@azure/functions'; -// const httpTriggerSqlOutput: AzureFunction = async function (context: Context, request: HttpRequest): Promise { -// context.log(`httpTriggerSqlOutput was triggered`); -// context.bindings.outputItem = request.body; -// context.res = { -// status: 201, -// }; -// }; +const httpTriggerSqlOutput: AzureFunction = async function (context: Context, request: HttpRequest): Promise { + context.log(`httpTriggerSqlOutput was triggered`); + context.bindings.outputItem = request.body; + context.res = { + status: 201, + }; +}; -// export default httpTriggerSqlOutput; +export default httpTriggerSqlOutput; \ No newline at end of file diff --git a/app/v3/serviceBusQueueManyTrigger/function.json b/app/v3/serviceBusQueueManyTrigger/function.json index f5e9f878..65e5addf 100644 --- a/app/v3/serviceBusQueueManyTrigger/function.json +++ b/app/v3/serviceBusQueueManyTrigger/function.json @@ -4,8 +4,8 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "queueName": "e2eTestQueueManyTrigger", - "connection": "e2eTest_serviceBus", + "queueName": "e2e-test-queue-many-trigger", + "connection": "ServiceBusConnection", "cardinality": "many" } ], diff --git a/app/v3/serviceBusQueueManyTrigger/index.ts b/app/v3/serviceBusQueueManyTrigger/index.ts index aed2e7d5..a2215ef9 100644 --- a/app/v3/serviceBusQueueManyTrigger/index.ts +++ b/app/v3/serviceBusQueueManyTrigger/index.ts @@ -1,12 +1,12 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusQueueTrigger: AzureFunction = async function (context: Context, messages: any): Promise { -// for (const message of messages) { -// context.log(`serviceBusQueueManyTrigger was triggered by "${message}"`); -// } -// }; +const serviceBusQueueTrigger: AzureFunction = async function (context: Context, messages: any): Promise { + for (const message of messages) { + context.log(`serviceBusQueueManyTrigger was triggered by "${message}"`); + } +}; -// export default serviceBusQueueTrigger; +export default serviceBusQueueTrigger; diff --git a/app/v3/serviceBusQueueManyTriggerAndOutput/function.json b/app/v3/serviceBusQueueManyTriggerAndOutput/function.json index 73885d79..e5d44e97 100644 --- a/app/v3/serviceBusQueueManyTriggerAndOutput/function.json +++ b/app/v3/serviceBusQueueManyTriggerAndOutput/function.json @@ -4,16 +4,16 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "queueName": "e2eTestQueueManyTriggerAndOutput", - "connection": "e2eTest_serviceBus", + "queueName": "e2e-test-queue-many-trigger-and-output", + "connection": "ServiceBusConnection", "cardinality": "many" }, { "name": "$return", "type": "serviceBus", "direction": "out", - "topicName": "e2eTestQueueManyTrigger", - "connection": "e2eTest_serviceBus" + "topicName": "e2e-test-queue-many-trigger", + "connection": "ServiceBusConnection" } ], "scriptFile": "../dist/serviceBusQueueManyTriggerAndOutput/index.js" diff --git a/app/v3/serviceBusQueueManyTriggerAndOutput/index.ts b/app/v3/serviceBusQueueManyTriggerAndOutput/index.ts index 2ee5ce3c..d649e246 100644 --- a/app/v3/serviceBusQueueManyTriggerAndOutput/index.ts +++ b/app/v3/serviceBusQueueManyTriggerAndOutput/index.ts @@ -1,16 +1,16 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusQueueTrigger: AzureFunction = async function (context: Context, messages: any): Promise { -// for (const message of messages) { -// context.log(`serviceBusQueueManyTriggerAndOutput was triggered by "${message}"`); -// } +const serviceBusQueueTrigger: AzureFunction = async function (context: Context, messages: any): Promise { + for (const message of messages) { + context.log(`serviceBusQueueManyTriggerAndOutput was triggered by "${message}"`); + } -// // do an extra stringify to make sure the values are JSON-parse-able otherwise it'll hit this bug: -// // https://github.com/Azure/azure-functions-eventhubs-extension/issues/118 -// return messages.map((m) => JSON.stringify(m)); -// }; + // do an extra stringify to make sure the values are JSON-parse-able otherwise it'll hit this bug: + // https://github.com/Azure/azure-functions-eventhubs-extension/issues/118 + return messages.map((m) => JSON.stringify(m)); +}; -// export default serviceBusQueueTrigger; +export default serviceBusQueueTrigger; diff --git a/app/v3/serviceBusQueueTrigger/function.json b/app/v3/serviceBusQueueTrigger/function.json index c0d50073..f569ab9a 100644 --- a/app/v3/serviceBusQueueTrigger/function.json +++ b/app/v3/serviceBusQueueTrigger/function.json @@ -4,8 +4,8 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "queueName": "e2eTestQueueOneTrigger", - "connection": "e2eTest_serviceBus" + "queueName": "e2e-test-queue-one-trigger", + "connection": "ServiceBusConnection" } ], "scriptFile": "../dist/serviceBusQueueTrigger/index.js" diff --git a/app/v3/serviceBusQueueTrigger/index.ts b/app/v3/serviceBusQueueTrigger/index.ts index e5e29d7b..0f274f64 100644 --- a/app/v3/serviceBusQueueTrigger/index.ts +++ b/app/v3/serviceBusQueueTrigger/index.ts @@ -1,10 +1,10 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusQueueTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { -// context.log(`serviceBusQueueTrigger was triggered by "${mySbMsg}"`); -// }; +const serviceBusQueueTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { + context.log(`serviceBusQueueTrigger was triggered by "${mySbMsg}"`); +}; -// export default serviceBusQueueTrigger; +export default serviceBusQueueTrigger; diff --git a/app/v3/serviceBusQueueTriggerAndOutput/function.json b/app/v3/serviceBusQueueTriggerAndOutput/function.json index 7e4f18f4..3edce73d 100644 --- a/app/v3/serviceBusQueueTriggerAndOutput/function.json +++ b/app/v3/serviceBusQueueTriggerAndOutput/function.json @@ -4,15 +4,15 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "queueName": "e2eTestQueueOneTriggerAndOutput", - "connection": "e2eTest_serviceBus" + "queueName": "e2e-test-queue-one-trigger-and-output", + "connection": "ServiceBusConnection" }, { "name": "$return", "type": "serviceBus", "direction": "out", - "topicName": "e2eTestQueueOneTrigger", - "connection": "e2eTest_serviceBus" + "topicName": "e2e-test-queue-one-trigger", + "connection": "ServiceBusConnection" } ], "scriptFile": "../dist/serviceBusQueueTriggerAndOutput/index.js" diff --git a/app/v3/serviceBusQueueTriggerAndOutput/index.ts b/app/v3/serviceBusQueueTriggerAndOutput/index.ts index ce3db961..f6086a03 100644 --- a/app/v3/serviceBusQueueTriggerAndOutput/index.ts +++ b/app/v3/serviceBusQueueTriggerAndOutput/index.ts @@ -1,11 +1,11 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusQueueTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { -// context.log(`serviceBusQueueTriggerAndOutput was triggered by "${mySbMsg}"`); -// return mySbMsg; -// }; +const serviceBusQueueTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { + context.log(`serviceBusQueueTriggerAndOutput was triggered by "${mySbMsg}"`); + return mySbMsg; +}; -// export default serviceBusQueueTrigger; +export default serviceBusQueueTrigger; diff --git a/app/v3/serviceBusTopicTrigger/function.json b/app/v3/serviceBusTopicTrigger/function.json index 3d6749f5..93c6c8ab 100644 --- a/app/v3/serviceBusTopicTrigger/function.json +++ b/app/v3/serviceBusTopicTrigger/function.json @@ -4,9 +4,9 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "topicName": "e2eTestTopicTrigger", - "subscriptionName": "e2etestsub", - "connection": "e2eTest_serviceBus" + "topicName": "e2e-test-topic-trigger", + "subscriptionName": "e2e-test-sub", + "connection": "ServiceBusConnection" } ], "scriptFile": "../dist/serviceBusTopicTrigger/index.js" diff --git a/app/v3/serviceBusTopicTrigger/index.ts b/app/v3/serviceBusTopicTrigger/index.ts index 8bbee113..8c4bb147 100644 --- a/app/v3/serviceBusTopicTrigger/index.ts +++ b/app/v3/serviceBusTopicTrigger/index.ts @@ -1,10 +1,10 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { -// context.log(`serviceBusTopicTrigger was triggered by "${mySbMsg}"`); -// }; +const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { + context.log(`serviceBusTopicTrigger was triggered by "${mySbMsg}"`); +}; -// export default serviceBusTopicTrigger; +export default serviceBusTopicTrigger; diff --git a/app/v3/serviceBusTopicTriggerAndOutput/function.json b/app/v3/serviceBusTopicTriggerAndOutput/function.json index 4240bdb4..48f1fbe5 100644 --- a/app/v3/serviceBusTopicTriggerAndOutput/function.json +++ b/app/v3/serviceBusTopicTriggerAndOutput/function.json @@ -4,16 +4,16 @@ "name": "mySbMsg", "type": "serviceBusTrigger", "direction": "in", - "topicName": "e2eTestTopicTriggerAndOutput", - "subscriptionName": "e2etestsub", - "connection": "e2eTest_serviceBus" + "topicName": "e2e-test-topic-trigger-and-output", + "subscriptionName": "e2e-test-sub", + "connection": "ServiceBusConnection" }, { "name": "$return", "type": "serviceBus", "direction": "out", - "topicName": "e2eTestTopicTrigger", - "connection": "e2eTest_serviceBus" + "topicName": "e2e-test-topic-trigger", + "connection": "ServiceBusConnection" } ], "scriptFile": "../dist/serviceBusTopicTriggerAndOutput/index.js" diff --git a/app/v3/serviceBusTopicTriggerAndOutput/index.ts b/app/v3/serviceBusTopicTriggerAndOutput/index.ts index abf91677..a7125402 100644 --- a/app/v3/serviceBusTopicTriggerAndOutput/index.ts +++ b/app/v3/serviceBusTopicTriggerAndOutput/index.ts @@ -1,11 +1,11 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { -// context.log(`serviceBusTopicTriggerAndOutput was triggered by "${mySbMsg}"`); -// return mySbMsg; -// }; +const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise { + context.log(`serviceBusTopicTriggerAndOutput was triggered by "${mySbMsg}"`); + return mySbMsg; +}; -// export default serviceBusTopicTrigger; +export default serviceBusTopicTrigger; diff --git a/app/v3/sqlTrigger/function.json b/app/v3/sqlTrigger/function.json index dce04990..c18873d9 100644 --- a/app/v3/sqlTrigger/function.json +++ b/app/v3/sqlTrigger/function.json @@ -5,8 +5,8 @@ "name": "changes", "direction": "in", "tableName": "dbo.e2eSqlTriggerTable", - "connectionStringSetting": "e2eTest_sql" + "connectionStringSetting": "SqlConnection" } ], "scriptFile": "../dist/sqlTrigger/index.js" -} +} \ No newline at end of file diff --git a/app/v3/sqlTrigger/index.ts b/app/v3/sqlTrigger/index.ts index ec3112e1..d6aeca95 100644 --- a/app/v3/sqlTrigger/index.ts +++ b/app/v3/sqlTrigger/index.ts @@ -1,27 +1,27 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { AzureFunction, Context } from '@azure/functions'; +import { AzureFunction, Context } from '@azure/functions'; -// const sqlTrigger: AzureFunction = async function (context: Context, changes: any[]): Promise { -// context.log(`sqlTrigger processed ${changes.length} changes`); -// for (const change of changes) { -// let operation: string; -// switch (change.Operation) { -// case 0: -// operation = 'insert'; -// break; -// case 1: -// operation = 'update'; -// break; -// case 2: -// operation = 'delete'; -// break; -// default: -// throw RangeError(`Unrecognized operation "${change.Operation}"`); -// } -// context.log(`sqlTrigger was triggered by operation "${operation}" for "${JSON.stringify(change.Item)}"`); -// } -// }; +const sqlTrigger: AzureFunction = async function (context: Context, changes: any[]): Promise { + context.log(`sqlTrigger processed ${changes.length} changes`); + for (const change of changes) { + let operation: string; + switch (change.Operation) { + case 0: + operation = 'insert'; + break; + case 1: + operation = 'update'; + break; + case 2: + operation = 'delete'; + break; + default: + throw RangeError(`Unrecognized operation "${change.Operation}"`); + } + context.log(`sqlTrigger was triggered by operation "${operation}" for "${JSON.stringify(change.Item)}"`); + } +}; -// export default sqlTrigger; +export default sqlTrigger; diff --git a/app/v4-oldConfig/src/functions/cosmosDBTrigger.ts b/app/v4-oldConfig/src/functions/cosmosDBTrigger.ts index 3b02a056..24fc610f 100644 --- a/app/v4-oldConfig/src/functions/cosmosDBTrigger.ts +++ b/app/v4-oldConfig/src/functions/cosmosDBTrigger.ts @@ -12,7 +12,7 @@ export async function cosmosDBTrigger(documents: unknown[], context: InvocationC app.cosmosDB('cosmosDBTrigger', { connectionStringSetting: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', collectionName: 'e2eTestContainerTrigger', createLeaseCollectionIfNotExists: true, leaseCollectionPrefix: '2', diff --git a/app/v4-oldConfig/src/functions/cosmosDBTriggerAndOutput.ts b/app/v4-oldConfig/src/functions/cosmosDBTriggerAndOutput.ts index ab00a27a..954f51cc 100644 --- a/app/v4-oldConfig/src/functions/cosmosDBTriggerAndOutput.ts +++ b/app/v4-oldConfig/src/functions/cosmosDBTriggerAndOutput.ts @@ -13,13 +13,13 @@ export async function cosmosDBTriggerAndOutput(documents: unknown[], context: In app.cosmosDB('cosmosDBTriggerAndOutput', { connectionStringSetting: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', collectionName: 'e2eTestContainerTriggerAndOutput', createLeaseCollectionIfNotExists: true, leaseCollectionPrefix: '1', return: output.cosmosDB({ connectionStringSetting: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', collectionName: 'e2eTestContainerTrigger', }), handler: cosmosDBTriggerAndOutput, diff --git a/app/v4-oldConfig/src/functions/httpTriggerCosmosDBInput.ts b/app/v4-oldConfig/src/functions/httpTriggerCosmosDBInput.ts index 88288768..ae50436c 100644 --- a/app/v4-oldConfig/src/functions/httpTriggerCosmosDBInput.ts +++ b/app/v4-oldConfig/src/functions/httpTriggerCosmosDBInput.ts @@ -4,7 +4,7 @@ import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions'; const cosmosInput = input.cosmosDB({ - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', collectionName: 'e2eTestContainerTriggerAndOutput', id: '{Query.id}', partitionKey: 'testPartKey', diff --git a/app/v4-oldConfig/src/functions/httpTriggerCosmosDBOutput.ts b/app/v4-oldConfig/src/functions/httpTriggerCosmosDBOutput.ts index 2cdfc272..95b24fec 100644 --- a/app/v4-oldConfig/src/functions/httpTriggerCosmosDBOutput.ts +++ b/app/v4-oldConfig/src/functions/httpTriggerCosmosDBOutput.ts @@ -4,7 +4,7 @@ import { HttpRequest, HttpResponseInit, InvocationContext, app, output } from '@azure/functions'; const cosmosOutput = output.cosmosDB({ - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', collectionName: 'e2eTestContainerTrigger', connectionStringSetting: 'CosmosDBConnection', }); diff --git a/app/v4/src/functions/cosmosDBTrigger.ts b/app/v4/src/functions/cosmosDBTrigger.ts index 1f5a5041..7b40a688 100644 --- a/app/v4/src/functions/cosmosDBTrigger.ts +++ b/app/v4/src/functions/cosmosDBTrigger.ts @@ -12,7 +12,7 @@ export async function cosmosDBTrigger(documents: unknown[], context: InvocationC app.cosmosDB('cosmosDBTrigger', { connection: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', containerName: 'e2eTestContainerTrigger', createLeaseContainerIfNotExists: true, leaseContainerPrefix: '2', diff --git a/app/v4/src/functions/cosmosDBTriggerAndOutput.ts b/app/v4/src/functions/cosmosDBTriggerAndOutput.ts index f658b801..d1d128f6 100644 --- a/app/v4/src/functions/cosmosDBTriggerAndOutput.ts +++ b/app/v4/src/functions/cosmosDBTriggerAndOutput.ts @@ -13,13 +13,13 @@ export async function cosmosDBTriggerAndOutput(documents: unknown[], context: In app.cosmosDB('cosmosDBTriggerAndOutput', { connection: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', containerName: 'e2eTestContainerTriggerAndOutput', createLeaseContainerIfNotExists: true, leaseContainerPrefix: '1', return: output.cosmosDB({ connection: 'CosmosDBConnection', - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', containerName: 'e2eTestContainerTrigger', }), handler: cosmosDBTriggerAndOutput, diff --git a/app/v4/src/functions/httpTriggerCosmosDBInput.ts b/app/v4/src/functions/httpTriggerCosmosDBInput.ts index acadf06e..255e6553 100644 --- a/app/v4/src/functions/httpTriggerCosmosDBInput.ts +++ b/app/v4/src/functions/httpTriggerCosmosDBInput.ts @@ -4,7 +4,7 @@ import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions'; const cosmosInput = input.cosmosDB({ - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', containerName: 'e2eTestContainerTriggerAndOutput', id: '{Query.id}', partitionKey: 'testPartKey', diff --git a/app/v4/src/functions/httpTriggerCosmosDBOutput.ts b/app/v4/src/functions/httpTriggerCosmosDBOutput.ts index a4580a97..4d9fc06c 100644 --- a/app/v4/src/functions/httpTriggerCosmosDBOutput.ts +++ b/app/v4/src/functions/httpTriggerCosmosDBOutput.ts @@ -4,7 +4,7 @@ import { app, HttpRequest, HttpResponseInit, InvocationContext, output } from '@azure/functions'; const cosmosOutput = output.cosmosDB({ - databaseName: 'e2eTestDB', + databaseName: 'e2eTestCosmosDB', containerName: 'e2eTestContainerTrigger', connection: 'CosmosDBConnection', }); diff --git a/app/v4/src/functions/httpTriggerServiceBusOutput.ts b/app/v4/src/functions/httpTriggerServiceBusOutput.ts index e3685ca1..9505a930 100644 --- a/app/v4/src/functions/httpTriggerServiceBusOutput.ts +++ b/app/v4/src/functions/httpTriggerServiceBusOutput.ts @@ -1,25 +1,25 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, HttpRequest, HttpResponseInit, InvocationContext, output } from '@azure/functions'; +import { app, HttpRequest, HttpResponseInit, InvocationContext, output } from '@azure/functions'; -// const serviceBusOutput = output.serviceBusQueue({ -// connection: 'e2eTest_serviceBus', -// queueName: 'e2eTestQueueOneTrigger', -// }); +const serviceBusOutput = output.serviceBusQueue({ + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-one-trigger', +}); -// export async function httpTriggerServiceBusOutput( -// request: HttpRequest, -// context: InvocationContext -// ): Promise { -// const body = <{ output: any }>await request.json(); -// context.extraOutputs.set(serviceBusOutput, body.output); -// return { body: 'done' }; -// } +export async function httpTriggerServiceBusOutput( + request: HttpRequest, + context: InvocationContext +): Promise { + const body = <{ output: any }>await request.json(); + context.extraOutputs.set(serviceBusOutput, body.output); + return { body: 'done' }; +} -// app.http('httpTriggerServiceBusOutput', { -// methods: ['GET', 'POST'], -// authLevel: 'anonymous', -// extraOutputs: [serviceBusOutput], -// handler: httpTriggerServiceBusOutput, -// }); +app.http('httpTriggerServiceBusOutput', { + methods: ['GET', 'POST'], + authLevel: 'anonymous', + extraOutputs: [serviceBusOutput], + handler: httpTriggerServiceBusOutput, +}); diff --git a/app/v4/src/functions/httpTriggerSqlInput.ts b/app/v4/src/functions/httpTriggerSqlInput.ts index e9b072f7..1f68f86f 100644 --- a/app/v4/src/functions/httpTriggerSqlInput.ts +++ b/app/v4/src/functions/httpTriggerSqlInput.ts @@ -1,24 +1,24 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions'; +import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions'; -// const sqlInput = input.sql({ -// connectionStringSetting: 'e2eTest_sql', -// commandText: 'select * from dbo.e2eSqlNonTriggerTable where id = @id', -// commandType: 'Text', -// parameters: '@id={Query.id}', -// }); +const sqlInput = input.sql({ + connectionStringSetting: 'SqlConnection', + commandText: 'select * from dbo.e2eSqlNonTriggerTable where id = @id', + commandType: 'Text', + parameters: '@id={Query.id}', +}); -// export async function httpTriggerSqlInput(request: HttpRequest, context: InvocationContext): Promise { -// context.log(`httpTriggerSqlInput was triggered`); -// const items = context.extraInputs.get(sqlInput); -// return { jsonBody: items }; -// } +export async function httpTriggerSqlInput(request: HttpRequest, context: InvocationContext): Promise { + context.log(`httpTriggerSqlInput was triggered`); + const items = context.extraInputs.get(sqlInput); + return { jsonBody: items }; +} -// app.http('httpTriggerSqlInput', { -// methods: ['GET', 'POST'], -// authLevel: 'anonymous', -// extraInputs: [sqlInput], -// handler: httpTriggerSqlInput, -// }); +app.http('httpTriggerSqlInput', { + methods: ['GET', 'POST'], + authLevel: 'anonymous', + extraInputs: [sqlInput], + handler: httpTriggerSqlInput, +}); \ No newline at end of file diff --git a/app/v4/src/functions/httpTriggerSqlOutput.ts b/app/v4/src/functions/httpTriggerSqlOutput.ts index c1170fe9..60cd1306 100644 --- a/app/v4/src/functions/httpTriggerSqlOutput.ts +++ b/app/v4/src/functions/httpTriggerSqlOutput.ts @@ -1,26 +1,26 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, HttpRequest, HttpResponseInit, InvocationContext, output } from '@azure/functions'; +import { app, HttpRequest, HttpResponseInit, InvocationContext, output } from '@azure/functions'; -// const sqlOutput = output.sql({ -// connectionStringSetting: 'e2eTest_sql', -// commandText: 'dbo.e2eSqlNonTriggerTable', -// }); +const sqlOutput = output.sql({ + connectionStringSetting: 'SqlConnection', + commandText: 'dbo.e2eSqlNonTriggerTable', +}); -// export async function httpTriggerSqlOutput( -// request: HttpRequest, -// context: InvocationContext -// ): Promise { -// context.log(`httpTriggerSqlOutput was triggered`); -// const body = await request.json(); -// context.extraOutputs.set(sqlOutput, body); -// return { status: 201 }; -// } +export async function httpTriggerSqlOutput( + request: HttpRequest, + context: InvocationContext +): Promise { + context.log(`httpTriggerSqlOutput was triggered`); + const body = await request.json(); + context.extraOutputs.set(sqlOutput, body); + return { status: 201 }; +} -// app.http('httpTriggerSqlOutput', { -// methods: ['GET', 'POST'], -// authLevel: 'anonymous', -// extraOutputs: [sqlOutput], -// handler: httpTriggerSqlOutput, -// }); +app.http('httpTriggerSqlOutput', { + methods: ['GET', 'POST'], + authLevel: 'anonymous', + extraOutputs: [sqlOutput], + handler: httpTriggerSqlOutput, +}); \ No newline at end of file diff --git a/app/v4/src/functions/serviceBusQueueManyTrigger.ts b/app/v4/src/functions/serviceBusQueueManyTrigger.ts index 8484a6e1..0ba7b852 100644 --- a/app/v4/src/functions/serviceBusQueueManyTrigger.ts +++ b/app/v4/src/functions/serviceBusQueueManyTrigger.ts @@ -1,17 +1,17 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext } from '@azure/functions'; +import { app, InvocationContext } from '@azure/functions'; -// export async function serviceBusQueueManyTrigger(messages: unknown[], context: InvocationContext): Promise { -// for (const message of messages) { -// context.log(`serviceBusQueueManyTrigger was triggered by "${message}"`); -// } -// } +export async function serviceBusQueueManyTrigger(messages: unknown[], context: InvocationContext): Promise { + for (const message of messages) { + context.log(`serviceBusQueueManyTrigger was triggered by "${message}"`); + } +} -// app.serviceBusQueue('serviceBusQueueManyTrigger', { -// connection: 'e2eTest_serviceBus', -// queueName: 'e2eTestQueueManyTrigger', -// cardinality: 'many', -// handler: serviceBusQueueManyTrigger, -// }); +app.serviceBusQueue('serviceBusQueueManyTrigger', { + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-many-trigger', + cardinality: 'many', + handler: serviceBusQueueManyTrigger, +}); diff --git a/app/v4/src/functions/serviceBusQueueManyTriggerAndOutput.ts b/app/v4/src/functions/serviceBusQueueManyTriggerAndOutput.ts index 6e6a40bb..c70d8449 100644 --- a/app/v4/src/functions/serviceBusQueueManyTriggerAndOutput.ts +++ b/app/v4/src/functions/serviceBusQueueManyTriggerAndOutput.ts @@ -1,28 +1,28 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext, output } from '@azure/functions'; +import { app, InvocationContext, output } from '@azure/functions'; -// export async function serviceBusQueueManyTriggerAndOutput( -// messages: unknown[], -// context: InvocationContext -// ): Promise { -// for (const message of messages) { -// context.log(`serviceBusQueueManyTriggerAndOutput was triggered by "${message}"`); -// } +export async function serviceBusQueueManyTriggerAndOutput( + messages: unknown[], + context: InvocationContext +): Promise { + for (const message of messages) { + context.log(`serviceBusQueueManyTriggerAndOutput was triggered by "${message}"`); + } -// // do an extra stringify to make sure the values are JSON-parse-able otherwise it'll hit this bug: -// // https://github.com/Azure/azure-functions-eventhubs-extension/issues/118 -// return messages.map((m) => JSON.stringify(m)); -// } + // do an extra stringify to make sure the values are JSON-parse-able otherwise it'll hit this bug: + // https://github.com/Azure/azure-functions-eventhubs-extension/issues/118 + return messages.map((m) => JSON.stringify(m)); +} -// app.serviceBusQueue('serviceBusQueueManyTriggerAndOutput', { -// connection: 'e2eTest_serviceBus', -// queueName: 'e2eTestQueueManyTriggerAndOutput', -// cardinality: 'many', -// return: output.serviceBusQueue({ -// connection: 'e2eTest_serviceBus', -// queueName: 'e2eTestQueueManyTrigger', -// }), -// handler: serviceBusQueueManyTriggerAndOutput, -// }); +app.serviceBusQueue('serviceBusQueueManyTriggerAndOutput', { + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-many-trigger-and-output', + cardinality: 'many', + return: output.serviceBusQueue({ + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-many-trigger', + }), + handler: serviceBusQueueManyTriggerAndOutput, +}); diff --git a/app/v4/src/functions/serviceBusQueueTrigger.ts b/app/v4/src/functions/serviceBusQueueTrigger.ts index 34b0e1dc..961e5c80 100644 --- a/app/v4/src/functions/serviceBusQueueTrigger.ts +++ b/app/v4/src/functions/serviceBusQueueTrigger.ts @@ -1,14 +1,14 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext } from '@azure/functions'; +import { app, InvocationContext } from '@azure/functions'; -// export async function serviceBusQueueTrigger(message: unknown, context: InvocationContext): Promise { -// context.log(`serviceBusQueueTrigger was triggered by "${message}"`); -// } +export async function serviceBusQueueTrigger(message: unknown, context: InvocationContext): Promise { + context.log(`serviceBusQueueTrigger was triggered by "${message}"`); +} -// app.serviceBusQueue('serviceBusQueueTrigger', { -// connection: 'EventHubConnection', -// queueName: 'e2e_test_queue_one_trigger', -// handler: serviceBusQueueTrigger, -// }); +app.serviceBusQueue('serviceBusQueueTrigger', { + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-one-trigger', + handler: serviceBusQueueTrigger, +}); diff --git a/app/v4/src/functions/serviceBusQueueTriggerAndOutput.ts b/app/v4/src/functions/serviceBusQueueTriggerAndOutput.ts index 52ddb09f..b73e56c5 100644 --- a/app/v4/src/functions/serviceBusQueueTriggerAndOutput.ts +++ b/app/v4/src/functions/serviceBusQueueTriggerAndOutput.ts @@ -1,19 +1,19 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext, output } from '@azure/functions'; +import { app, InvocationContext, output } from '@azure/functions'; -// export async function serviceBusQueueTriggerAndOutput(message: unknown, context: InvocationContext): Promise { -// context.log(`serviceBusQueueTriggerAndOutput was triggered by "${message}"`); -// return message; -// } +export async function serviceBusQueueTriggerAndOutput(message: unknown, context: InvocationContext): Promise { + context.log(`serviceBusQueueTriggerAndOutput was triggered by "${message}"`); + return message; +} -// app.serviceBusQueue('serviceBusQueueTriggerAndOutput', { -// connection: 'EventHubConnection', -// queueName: 'e2e-test-queue-one-trigger-and-output', -// return: output.serviceBusQueue({ -// connection: 'EventHubConnection', -// queueName: 'e2e_test_queue_one_trigger', -// }), -// handler: serviceBusQueueTriggerAndOutput, -// }); +app.serviceBusQueue('serviceBusQueueTriggerAndOutput', { + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-one-trigger-and-output', + return: output.serviceBusQueue({ + connection: 'ServiceBusConnection', + queueName: 'e2e-test-queue-one-trigger', + }), + handler: serviceBusQueueTriggerAndOutput, +}); diff --git a/app/v4/src/functions/serviceBusTopicTrigger.ts b/app/v4/src/functions/serviceBusTopicTrigger.ts index c2899518..fc8b7972 100644 --- a/app/v4/src/functions/serviceBusTopicTrigger.ts +++ b/app/v4/src/functions/serviceBusTopicTrigger.ts @@ -1,15 +1,15 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext } from '@azure/functions'; +import { app, InvocationContext } from '@azure/functions'; -// export async function serviceBusTopicTrigger(message: unknown, context: InvocationContext): Promise { -// context.log(`serviceBusTopicTrigger was triggered by "${message}"`); -// } +export async function serviceBusTopicTrigger(message: unknown, context: InvocationContext): Promise { + context.log(`serviceBusTopicTrigger was triggered by "${message}"`); +} -// app.serviceBusTopic('serviceBusTopicTrigger', { -// connection: 'e2eTest_serviceBus', -// topicName: 'e2eTestTopicTrigger', -// subscriptionName: 'e2etestsub', -// handler: serviceBusTopicTrigger, -// }); +app.serviceBusTopic('serviceBusTopicTrigger', { + connection: 'ServiceBusConnection', + topicName: 'e2e-test-topic-trigger', + subscriptionName: 'e2e-test-sub', + handler: serviceBusTopicTrigger, +}); diff --git a/app/v4/src/functions/serviceBusTopicTriggerAndOutput.ts b/app/v4/src/functions/serviceBusTopicTriggerAndOutput.ts index bcb59f2f..a1b45ae4 100644 --- a/app/v4/src/functions/serviceBusTopicTriggerAndOutput.ts +++ b/app/v4/src/functions/serviceBusTopicTriggerAndOutput.ts @@ -1,20 +1,20 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext, output } from '@azure/functions'; +import { app, InvocationContext, output } from '@azure/functions'; -// export async function serviceBusTopicTriggerAndOutput(message: unknown, context: InvocationContext): Promise { -// context.log(`serviceBusTopicTriggerAndOutput was triggered by "${message}"`); -// return message; -// } +export async function serviceBusTopicTriggerAndOutput(message: unknown, context: InvocationContext): Promise { + context.log(`serviceBusTopicTriggerAndOutput was triggered by "${message}"`); + return message; +} -// app.serviceBusTopic('serviceBusTopicTriggerAndOutput', { -// connection: 'e2eTest_serviceBus', -// topicName: 'e2eTestTopicTriggerAndOutput', -// subscriptionName: 'e2etestsub', -// return: output.serviceBusTopic({ -// connection: 'e2eTest_serviceBus', -// topicName: 'e2eTestTopicTrigger', -// }), -// handler: serviceBusTopicTriggerAndOutput, -// }); +app.serviceBusTopic('serviceBusTopicTriggerAndOutput', { + connection: 'ServiceBusConnection', + topicName: 'e2e-test-topic-trigger-and-output', + subscriptionName: 'e2e-test-sub', + return: output.serviceBusTopic({ + connection: 'ServiceBusConnection', + topicName: 'e2e-test-topic-trigger', + }), + handler: serviceBusTopicTriggerAndOutput, +}); diff --git a/app/v4/src/functions/sqlTrigger.ts b/app/v4/src/functions/sqlTrigger.ts index 4cdab5b8..8998cf3d 100644 --- a/app/v4/src/functions/sqlTrigger.ts +++ b/app/v4/src/functions/sqlTrigger.ts @@ -1,31 +1,31 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { app, InvocationContext, SqlChange, SqlChangeOperation } from '@azure/functions'; +import { app, InvocationContext, SqlChange, SqlChangeOperation } from '@azure/functions'; -// export async function sqlTrigger(changes: SqlChange[], context: InvocationContext): Promise { -// context.log(`sqlTrigger processed ${changes.length} changes`); -// for (const change of changes) { -// let operation: string; -// switch (change.Operation) { -// case SqlChangeOperation.Insert: -// operation = 'insert'; -// break; -// case SqlChangeOperation.Update: -// operation = 'update'; -// break; -// case SqlChangeOperation.Delete: -// operation = 'delete'; -// break; -// default: -// throw RangeError(`Unrecognized operation "${change.Operation}"`); -// } -// context.log(`sqlTrigger was triggered by operation "${operation}" for "${JSON.stringify(change.Item)}"`); -// } -// } +export async function sqlTrigger(changes: SqlChange[], context: InvocationContext): Promise { + context.log(`sqlTrigger processed ${changes.length} changes`); + for (const change of changes) { + let operation: string; + switch (change.Operation) { + case SqlChangeOperation.Insert: + operation = 'insert'; + break; + case SqlChangeOperation.Update: + operation = 'update'; + break; + case SqlChangeOperation.Delete: + operation = 'delete'; + break; + default: + throw RangeError(`Unrecognized operation "${change.Operation}"`); + } + context.log(`sqlTrigger was triggered by operation "${operation}" for "${JSON.stringify(change.Item)}"`); + } +} -// app.sql('sqlTrigger', { -// tableName: 'dbo.e2eSqlTriggerTable', -// connectionStringSetting: 'e2eTest_sql', -// handler: sqlTrigger, -// }); +app.sql('sqlTrigger', { + tableName: 'dbo.e2eSqlTriggerTable', + connectionStringSetting: 'SqlConnection', + handler: sqlTrigger, +}); \ No newline at end of file diff --git a/azure-pipelines/templates/test-node-version.yml b/azure-pipelines/templates/test-node-version.yml index 029551be..84732ae7 100644 --- a/azure-pipelines/templates/test-node-version.yml +++ b/azure-pipelines/templates/test-node-version.yml @@ -1,27 +1,62 @@ parameters: - name: nodeVersion type: string - - name: testCommand - type: string - default: test + - name: runOldConfig + type: boolean + default: false steps: - task: NodeTool@0 inputs: - versionSpec: ${{ parameters.nodeVersion }} + versionSpec: ${{ parameters.nodeVersion }} displayName: 'Install Node ${{ parameters.nodeVersion }}' retryCountOnTaskFailure: 10 + - bash: | docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview - docker run --detach --publish 8081:8081 --publish 1234:1234 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview + docker run --detach --publish 8081:8081 --publish 1234:1234 --name cosmosdb-emulator mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview docker ps displayName: "Start CosmosDB Emulator" + + - bash: | + docker compose -f src/utils/sql/docker-compose.yml up -d + sleep 60 + env: + SA_PASSWORD: $(AzureWebJobsSQLPassword) + displayName: "Start SQL Service" + + - bash: docker compose -f src/utils/servicebus/docker-compose.yml up -d + env: + AzureWebJobsSQLPassword: $(AzureWebJobsSQLPassword) + displayName: 'Start ServiceBus Emulator' + + - bash: npm run testServiceBus + env: + SA_PASSWORD: $(AzureWebJobsSQLPassword) + displayName: 'Run ServiceBus tests Node ${{ parameters.nodeVersion }}' + continueOnError: true + - bash: | - docker compose -f src/utils/eventhub/docker-compose.yml pull + docker stop servicebus-emulator || true + docker rm -f servicebus-emulator || true docker compose -f src/utils/eventhub/docker-compose.yml up -d - displayName: 'Install Azurite and Start EventHub Emulator' - condition: and(succeeded(), ne('${{ parameters.testCommand }}', 'testOldConfig')) + displayName: 'Stop ServiceBus Emulator and Start EventHub Emulator' + + - bash: npm run testAllExceptServiceBus + env: + SA_PASSWORD: $(AzureWebJobsSQLPassword) + displayName: 'Run remaining tests Node ${{ parameters.nodeVersion }}' + continueOnError: true + + - bash: npm run testOldConfig + displayName: 'Run oldConfig tests Node ${{ parameters.nodeVersion }}' + condition: and(succeeded(), eq('${{ parameters.runOldConfig }}', 'true')) + continueOnError: true + - bash: | - npm run ${{ parameters.testCommand }} - displayName: 'Run tests Node ${{ parameters.nodeVersion }}' - continueOnError: true \ No newline at end of file + docker stop cosmosdb-emulator || true + docker rm -f cosmosdb-emulator || true + docker compose -f src/utils/eventhub/docker-compose.yml down -v + docker compose -f src/utils/servicebus/docker-compose.yml down -v + docker compose -f src/utils/sql/docker-compose.yml down -v + displayName: 'Stop all resources' \ No newline at end of file diff --git a/azure-pipelines/templates/test.yml b/azure-pipelines/templates/test.yml index 98ebca05..14cb21c1 100644 --- a/azure-pipelines/templates/test.yml +++ b/azure-pipelines/templates/test.yml @@ -16,9 +16,11 @@ jobs: - template: /azure-pipelines/templates/build-apps.yml@self + # Run tests for old config (just one Node.js version (18) is enough) - template: /azure-pipelines/templates/test-node-version.yml@self parameters: nodeVersion: 18.x + runOldConfig: true - template: /azure-pipelines/templates/test-node-version.yml@self parameters: @@ -28,12 +30,6 @@ jobs: parameters: nodeVersion: 22.x - # Run tests for old config (just one Node.js version is enough) - - template: /azure-pipelines/templates/test-node-version.yml@self - parameters: - nodeVersion: 18.x - testCommand: testOldConfig - - task: PublishTestResults@2 displayName: 'Publish Unit Test Results' inputs: diff --git a/package-lock.json b/package-lock.json index 74e081dd..93838b4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4544,9 +4544,9 @@ "license": "MIT" }, "node_modules/mssql": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/mssql/-/mssql-10.0.2.tgz", - "integrity": "sha512-GrQ6gzv2xA7ndOvONyZ++4RZsNkr8qDiIpvuFn2pR3TPiSk/cKdmvOrDU3jWgon7EPj7CPgmDiMh7Hgtft2xLg==", + "version": "10.0.4", + "resolved": "https://registry.npmjs.org/mssql/-/mssql-10.0.4.tgz", + "integrity": "sha512-MhX5IcJ75/q+dUiOe+1ajpqjEe96ZKqMchYYPUIDU+Btqhwt4gbFeZhcGUZaRCEMV9uF+G8kLvaNSFaEzL9OXQ==", "dependencies": { "@tediousjs/connection-string": "^0.5.0", "commander": "^11.0.0", diff --git a/package.json b/package.json index 7b679fae..35f54926 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,15 @@ "lint": "eslint . --fix", "watch": "tsc -w", "createCombinedApps": "node out/createCombinedApps.js", - "test": "npm run testV3 && npm run testV4", "testOldConfig": "npm run testV3OldConfig && npm run testV4OldConfig", - "testV3": "node out/index.js --model v3", "testV3OldConfig": "node out/index.js --model v3 --oldConfig", - "testV4": "node out/index.js --model v4", - "testV4OldConfig": "node out/index.js --model v4 --oldConfig" + "testV4OldConfig": "node out/index.js --model v4 --oldConfig", + "testServiceBus": "npm run testV3ServiceBus && npm run testV4ServiceBus", + "testV3ServiceBus": "node out/index.js --model v3 --only serviceBus.test.js", + "testV4ServiceBus": "node out/index.js --model v4 --only serviceBus.test.js", + "testAllExceptServiceBus": "npm run testV3AllExceptServiceBus && npm run testV4AllExceptServiceBus", + "testV3AllExceptServiceBus": "node out/index.js --model v3 --exclude serviceBus.test.js", + "testV4AllExceptServiceBus": "node out/index.js --model v4 --exclude serviceBus.test.js" }, "dependencies": { "@azure/arm-cosmosdb": "^15.4.0", diff --git a/src/constants.ts b/src/constants.ts index 24cebd74..ddb5872c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,13 +5,15 @@ export namespace EnvVarNames { export const storage = 'AzureWebJobsStorage'; export const cosmosDB = 'CosmosDBConnection'; export const eventHub = 'EventHubConnection'; + export const serviceBus = 'ServiceBusConnection'; + export const sql = 'SqlConnection'; } export namespace CosmosDB { - export const dbName = 'e2eTestDB'; + export const dbName = 'e2eTestCosmosDB'; export const triggerAndOutputContainerName = 'e2eTestContainerTriggerAndOutput'; export const triggerContainerName = 'e2eTestContainerTrigger'; - export const triggerDatabaseName = 'e2eTestDB'; + export const triggerDatabaseName = 'e2eTestCosmosDB'; export const partitionKey = 'testPartKey'; } @@ -22,6 +24,22 @@ export namespace EventHub { export const eventHubManyTrigger = 'e2e-test-hub-many-trigger'; } +export namespace ServiceBus { + export const serviceBusQueueOneTriggerAndOutput = 'e2e-test-queue-one-trigger-and-output'; + export const serviceBusQueueOneTrigger = 'e2e-test-queue-one-trigger'; + export const serviceBusQueueManyTriggerAndOutput = 'e2e-test-queue-many-trigger-and-output'; + export const serviceBusQueueManyTrigger = 'e2e-test-queue-many-trigger'; + export const serviceBusTopicTriggerAndOutput = 'e2e-test-topic-trigger-and-output'; + export const serviceBusTopicTrigger = 'e2e-test-topic-trigger'; + export const serviceBusTestFileName = 'serviceBus.test'; +} + +export namespace Sql { + export const dbName = 'e2eTestDB'; + export const sqlTriggerTable = 'e2eSqlTriggerTable'; + export const sqlNonTriggerTable = 'e2eSqlNonTriggerTable'; +} + export const defaultTimeout = 3 * 60 * 1000; export const combinedFolder = 'combined'; diff --git a/src/getModelArg.ts b/src/getModelArg.ts index 9f85b941..912eb6e6 100644 --- a/src/getModelArg.ts +++ b/src/getModelArg.ts @@ -20,3 +20,10 @@ export function getOldConfigArg(): boolean { const args = parseArgs(process.argv.slice(2), { boolean: flag }); return args[flag]; } + +export function getTestFileFilter(): { only?: string; exclude?: string } { + const args = parseArgs(process.argv.slice(2)); + const only = typeof args.only === 'string' ? args.only : undefined; + const exclude = typeof args.exclude === 'string' ? args.exclude : undefined; + return { only, exclude }; +} diff --git a/src/global.test.ts b/src/global.test.ts index f0472763..52ccda8f 100644 --- a/src/global.test.ts +++ b/src/global.test.ts @@ -6,16 +6,20 @@ import * as fs from 'fs/promises'; import path from 'path'; import semver from 'semver'; import { combinedFolder, defaultTimeout, EnvVarNames, oldConfigSuffix } from './constants'; -import { getModelArg, getOldConfigArg, Model } from './getModelArg'; +import { getModelArg, getOldConfigArg, getTestFileFilter, Model } from './getModelArg'; import { cosmosDBConnectionString, eventHubConnectionString, initializeConnectionStrings, + serviceBusConnectionString, + sqlTestConnectionString, storageConnectionString } from './utils/connectionStrings'; -import { setupCosmosDB } from './utils/setupCosmosDB'; import { delay } from './utils/delay'; import findProcess = require('find-process'); +import { setupCosmosDB } from './utils/cosmosdb/setupCosmosDB'; +import { runSqlSetupQueries } from './utils/sql/setupSql'; +import { ServiceBus } from './constants'; let perTestFuncOutput = ''; let fullFuncOutput = ''; @@ -40,7 +44,11 @@ before(async function (this: Mocha.Context): Promise { await initializeConnectionStrings(); - await setupCosmosDB(); + const { only } = getTestFileFilter(); + if (only?.startsWith(ServiceBus.serviceBusTestFileName)) { + await runSqlSetupQueries(); + await setupCosmosDB(); + } isOldConfig = getOldConfigArg(); const appPath = isOldConfig @@ -116,6 +124,9 @@ async function startFuncProcess(appPath: string): Promise { [EnvVarNames.storage]: storageConnectionString, [EnvVarNames.cosmosDB]: cosmosDBConnectionString, [EnvVarNames.eventHub]: eventHubConnectionString, + [EnvVarNames.serviceBus]: serviceBusConnectionString, + [EnvVarNames.sql]: sqlTestConnectionString, + WEBSITE_SITE_NAME: 'azure-functions-nodejs-e2e-tests', FUNCTIONS_REQUEST_BODY_SIZE_LIMIT: '4294967296', }, }, diff --git a/src/index.ts b/src/index.ts index 0c52d1c2..487923aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import globby from 'globby'; import Mocha from 'mocha'; import path from 'path'; import { defaultTimeout } from './constants'; -import { getModelArg, getOldConfigArg } from './getModelArg'; +import { getModelArg, getOldConfigArg, getTestFileFilter } from './getModelArg'; export async function run(): Promise { try { @@ -27,8 +27,18 @@ export async function run(): Promise { const mocha = new Mocha(options); - const files: string[] = await globby('**/**.test.js', { cwd: __dirname }); + const globalTestPath = path.resolve(__dirname, 'global.test.js'); + mocha.addFile(globalTestPath); + let files: string[] = await globby('**/*.test.js', { cwd: __dirname }); + const { only, exclude } = getTestFileFilter(); + if (only) { + files = files.filter(f => f.endsWith(only)); + } else if (exclude) { + files = files.filter(f => !f.endsWith(exclude)); + } + + files = files.filter(f => path.resolve(__dirname, f) !== globalTestPath); files.forEach((f) => mocha.addFile(path.resolve(__dirname, f))); const failures = await new Promise((resolve) => mocha.run(resolve)); diff --git a/src/serviceBus.test.ts b/src/serviceBus.test.ts new file mode 100644 index 00000000..74d2f5ee --- /dev/null +++ b/src/serviceBus.test.ts @@ -0,0 +1,81 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { ServiceBusClient } from '@azure/service-bus'; +import { default as fetch } from 'node-fetch'; +import { getFuncUrl } from './constants'; +import { isOldConfig, waitForOutput } from './global.test'; +import { getRandomTestData } from './utils/getRandomTestData'; +import { serviceBusConnectionString } from './utils/connectionStrings'; +import { ServiceBus } from './constants'; + +describe('serviceBus', () => { + let client: ServiceBusClient; + + before(function (this: Mocha.Context) { + if (isOldConfig) { + this.skip(); + } + client = new ServiceBusClient(serviceBusConnectionString); + }); + + after(async () => { + void client?.close(); + }); + + it('queue trigger and output', async () => { + const message = getRandomTestData(); + const sender = client.createSender(ServiceBus.serviceBusQueueOneTriggerAndOutput); + const batch = await sender.createMessageBatch(); + batch.tryAddMessage({ body: message }); + await sender.sendMessages(batch); + + await waitForOutput(`serviceBusQueueTriggerAndOutput was triggered by "${message}"`); + await waitForOutput(`serviceBusQueueTrigger was triggered by "${message}"`); + }); + + it('topic trigger and output', async () => { + const message = getRandomTestData(); + const sender = client.createSender(ServiceBus.serviceBusTopicTriggerAndOutput); + const batch = await sender.createMessageBatch(); + batch.tryAddMessage({ body: message }); + await sender.sendMessages(batch); + + await waitForOutput(`serviceBusTopicTriggerAndOutput was triggered by "${message}"`); + await waitForOutput(`serviceBusTopicTrigger was triggered by "${message}"`); + }); + + it('trigger and output, cardinality many', async () => { + const message1 = getRandomTestData(); + const message2 = getRandomTestData(); + const sender = client.createSender(ServiceBus.serviceBusQueueManyTriggerAndOutput); + const batch = await sender.createMessageBatch(); + batch.tryAddMessage({ body: message1 }); + batch.tryAddMessage({ body: message2 }); + await sender.sendMessages(batch); + + await waitForOutput(`serviceBusQueueManyTriggerAndOutput was triggered by "${message1}"`); + await waitForOutput(`serviceBusQueueManyTriggerAndOutput was triggered by "${message2}"`); + await waitForOutput(`serviceBusQueueManyTrigger was triggered by "${message1}"`); + await waitForOutput(`serviceBusQueueManyTrigger was triggered by "${message2}"`); + }); + + it('extra output', async () => { + const url = getFuncUrl('httpTriggerServiceBusOutput'); + + // single + const message = getRandomTestData(); + await fetch(url, { method: 'POST', body: JSON.stringify({ output: message }) }); + await waitForOutput(`serviceBusQueueTrigger was triggered by "${message}"`); + + // bulk + const bulkMsgs: string[] = []; + for (let i = 0; i < 5; i++) { + bulkMsgs.push(getRandomTestData()); + } + await fetch(url, { method: 'POST', body: JSON.stringify({ output: bulkMsgs }) }); + for (const msg of bulkMsgs) { + await waitForOutput(`serviceBusQueueTrigger was triggered by "${msg}"`); + } + }); +}); \ No newline at end of file diff --git a/src/sql.test.ts b/src/sql.test.ts index e2b1f3a0..6bbac192 100644 --- a/src/sql.test.ts +++ b/src/sql.test.ts @@ -1,78 +1,78 @@ -// // Copyright (c) .NET Foundation. All rights reserved. -// // Licensed under the MIT License. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. -// import { expect } from 'chai'; -// import { ConnectionPool } from 'mssql'; -// import { default as fetch } from 'node-fetch'; -// import { v4 as uuid } from 'uuid'; -// import { getFuncUrl } from './constants'; -// import { isOldConfig, waitForOutput } from './global.test'; -// import { sqlConnectionString } from './resources/connectionStrings'; -// import { createPoolConnnection, sqlTriggerTable } from './resources/sql'; -// import { getRandomTestData } from './utils/getRandomTestData'; +import { expect } from 'chai'; +import { default as fetch } from 'node-fetch'; +import { v4 as uuid } from 'uuid'; +import { Sql, getFuncUrl } from './constants'; +import { isOldConfig, waitForOutput } from './global.test'; +import { getRandomTestData } from './utils/getRandomTestData'; +import { ConnectionPool } from 'mssql'; +import { createPoolConnnection } from './utils/sql/setupSql'; +import { sqlTestConnectionString } from './utils/connectionStrings'; -// describe('sql', () => { -// let poolConnection: ConnectionPool | undefined; -// before(async function (this: Mocha.Context) { -// if (isOldConfig) { -// this.skip(); -// } +describe('sql', () => { + let poolConnection: ConnectionPool | undefined; + before(async function (this: Mocha.Context) { + if (isOldConfig) { + this.skip(); + } -// poolConnection = await createPoolConnnection(sqlConnectionString); -// }); + poolConnection = await createPoolConnnection(sqlTestConnectionString); + }); -// after(async () => { -// await poolConnection?.close(); -// }); + after(async () => { + await poolConnection?.close(); + }); -// type SqlItem = { id: string; testData: string }; + type SqlItem = { id: string; testData: string }; -// it('trigger', async () => { -// const id = uuid(); -// const testData = getRandomTestData(); + it('trigger', async () => { + const id = uuid(); + const testData = getRandomTestData(); -// // trigger by insert -// await poolConnection!.request().query(`INSERT INTO ${sqlTriggerTable} VALUES ('${id}', '${testData}');`); -// await waitForOutput(`sqlTrigger processed 1 changes`); -// await waitForOutput(`sqlTrigger was triggered by operation "insert" for "${JSON.stringify({ id, testData })}"`); + // trigger by insert + await poolConnection!.request().query(`INSERT INTO ${Sql.sqlTriggerTable} VALUES ('${id}', '${testData}');`); + await waitForOutput(`sqlTrigger processed 1 changes`); + await waitForOutput(`sqlTrigger was triggered by operation "insert" for "${JSON.stringify({ id, testData })}"`); -// // trigger by update -// await poolConnection! -// .request() -// .query(`UPDATE ${sqlTriggerTable} SET testData='${testData}-updated' WHERE id='${id}';`); -// await waitForOutput(`sqlTrigger processed 1 changes`); -// await waitForOutput( -// `sqlTrigger was triggered by operation "update" for "${JSON.stringify({ -// id, -// testData: `${testData}-updated`, -// })}"` -// ); + // trigger by update + await poolConnection! + .request() + .query(`UPDATE ${Sql.sqlTriggerTable} SET testData='${testData}-updated' WHERE id='${id}';`); + await waitForOutput(`sqlTrigger processed 1 changes`); + await waitForOutput( + `sqlTrigger was triggered by operation "update" for "${JSON.stringify({ + id, + testData: `${testData}-updated`, + })}"` + ); -// // trigger by delete -// await poolConnection!.request().query(`DELETE FROM ${sqlTriggerTable} WHERE id='${id}';`); -// await waitForOutput(`sqlTrigger processed 1 changes`); -// await waitForOutput(`sqlTrigger was triggered by operation "delete" for "${JSON.stringify({ id })}"`); -// }); + // trigger by delete + await poolConnection!.request().query(`DELETE FROM ${Sql.sqlTriggerTable} WHERE id='${id}';`); + await waitForOutput(`sqlTrigger processed 1 changes`); + await waitForOutput(`sqlTrigger was triggered by operation "delete" for "${JSON.stringify({ id })}"`); + }); -// it('input and output', async () => { -// const outputUrl = getFuncUrl('httpTriggerSqlOutput'); + it('input and output', async () => { + const outputUrl = getFuncUrl('httpTriggerSqlOutput'); -// const id = uuid(); -// const items: SqlItem[] = [ -// { -// id, -// testData: getRandomTestData(), -// }, -// ]; -// const responseOut = await fetch(outputUrl, { method: 'POST', body: JSON.stringify(items) }); -// expect(responseOut.status).to.equal(201); -// await waitForOutput(`httpTriggerSqlOutput was triggered`); + const id = uuid(); + const items: SqlItem[] = [ + { + id, + testData: getRandomTestData(), + }, + ]; + const responseOut = await fetch(outputUrl, { method: 'POST', body: JSON.stringify(items) }); + expect(responseOut.status).to.equal(201); + await waitForOutput(`httpTriggerSqlOutput was triggered`); -// const inputUrl = getFuncUrl('httpTriggerSqlInput'); -// const responseIn = await fetch(`${inputUrl}?id=${id}`, { method: 'GET' }); -// expect(responseIn.status).to.equal(200); -// const result = await responseIn.json(); -// expect(result).to.deep.equal(items); -// await waitForOutput(`httpTriggerSqlInput was triggered`); -// }); -// }); + const inputUrl = getFuncUrl('httpTriggerSqlInput'); + const responseIn = await fetch(`${inputUrl}?id=${id}`, { method: 'GET' }); + expect(responseIn.status).to.equal(200); + const result = await responseIn.json(); + expect(result).to.deep.equal(items); + await waitForOutput(`httpTriggerSqlInput was triggered`); + }); +}); \ No newline at end of file diff --git a/src/utils/connectionStrings.ts b/src/utils/connectionStrings.ts index e65db531..31b65015 100644 --- a/src/utils/connectionStrings.ts +++ b/src/utils/connectionStrings.ts @@ -4,9 +4,14 @@ export let storageConnectionString: string; export let cosmosDBConnectionString: string; export let eventHubConnectionString: string; +export let serviceBusConnectionString: string; +export let sqlConnectionString: string; +export let sqlTestConnectionString: string; export async function initializeConnectionStrings(): Promise { storageConnectionString = "UseDevelopmentStorage=true"; cosmosDBConnectionString = "AccountEndpoint=http://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; - eventHubConnectionString = "Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"; + serviceBusConnectionString = eventHubConnectionString = "Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"; + sqlConnectionString = `Server=localhost,15433;Database=master;User Id=sa;Password=${process.env.SA_PASSWORD};Encrypt=false;TrustServerCertificate=true;`; + sqlTestConnectionString = `Server=localhost,15433;Database=e2eTestDB;User Id=sa;Password=${process.env.SA_PASSWORD};Encrypt=false;TrustServerCertificate=true;`; } diff --git a/src/utils/cosmosdb/setupCosmosDB.ts b/src/utils/cosmosdb/setupCosmosDB.ts new file mode 100644 index 00000000..7f646a25 --- /dev/null +++ b/src/utils/cosmosdb/setupCosmosDB.ts @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +// The CosmosDB emulator requires a container and database to be created before running tests but after the emulator starts +// Otherwise the following error will occur: +// Microsoft.Azure.Cosmos.Client: This builder instance has already been used to build a processor. Create a new instance to build another. + +import { CosmosClient, PartitionKeyKind } from '@azure/cosmos'; +import { cosmosDBConnectionString } from '../connectionStrings'; +import { CosmosDB } from '../../constants'; + +export async function setupCosmosDB() { + const partitionKeyPath = `/${CosmosDB.partitionKey}`; + if (!cosmosDBConnectionString) { + throw new Error('CosmosDB connection string is not set'); + } + const client = new CosmosClient(cosmosDBConnectionString); + await client.databases.createIfNotExists({ id: CosmosDB.triggerDatabaseName }); + await client.database(CosmosDB.triggerDatabaseName).containers.createIfNotExists({ + id: CosmosDB.triggerContainerName, + partitionKey: { paths: [partitionKeyPath], kind: PartitionKeyKind.Hash } + }); + await client.database(CosmosDB.triggerDatabaseName).containers.createIfNotExists({ + id: CosmosDB.triggerAndOutputContainerName, + partitionKey: { paths: [partitionKeyPath], kind: PartitionKeyKind.Hash } + }); +} \ No newline at end of file diff --git a/src/utils/eventhub/docker-compose.yml b/src/utils/eventhub/docker-compose.yml index 642ac61a..2a396a95 100644 --- a/src/utils/eventhub/docker-compose.yml +++ b/src/utils/eventhub/docker-compose.yml @@ -20,15 +20,15 @@ services: aliases: - "eventhubs-emulator" azurite: - container_name: "azurite" + container_name: "azurite-eh" image: "mcr.microsoft.com/azure-storage/azurite:latest" ports: - - "10000:10000" - - "10001:10001" - - "10002:10002" + - "10003:10003" + - "10004:10004" + - "10005:10005" networks: eh-emulator: aliases: - - "azurite" + - "azurite-eh" networks: eh-emulator: \ No newline at end of file diff --git a/src/utils/servicebus/config.json b/src/utils/servicebus/config.json new file mode 100644 index 00000000..796e0d23 --- /dev/null +++ b/src/utils/servicebus/config.json @@ -0,0 +1,116 @@ +{ + "UserConfig": { + "Namespaces": [ + { + "Name": "sbemulatorns", + "Queues": [ + { + "Name": "e2e-test-queue-one-trigger", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "LockDuration": "PT1M", + "MaxDeliveryCount": 10, + "RequiresDuplicateDetection": false, + "RequiresSession": false + } + }, + { + "Name": "e2e-test-queue-many-trigger", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "LockDuration": "PT1M", + "MaxDeliveryCount": 10, + "RequiresDuplicateDetection": false, + "RequiresSession": false + } + }, + { + "Name": "e2e-test-queue-one-trigger-and-output", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "LockDuration": "PT1M", + "MaxDeliveryCount": 10, + "RequiresDuplicateDetection": false, + "RequiresSession": false + } + }, + { + "Name": "e2e-test-queue-many-trigger-and-output", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "LockDuration": "PT1M", + "MaxDeliveryCount": 10, + "RequiresDuplicateDetection": false, + "RequiresSession": false + } + } + ], + "Topics": [ + { + "Name": "e2e-test-topic-trigger", + "Properties": { + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "RequiresDuplicateDetection": false + }, + "Subscriptions": [ + { + "Name": "e2e-test-sub", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "LockDuration": "PT1M", + "MaxDeliveryCount": 3, + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "RequiresSession": false + } + } + ] + }, + { + "Name": "e2e-test-topic-trigger-and-output", + "Properties": { + "DefaultMessageTimeToLive": "PT1H", + "DuplicateDetectionHistoryTimeWindow": "PT20S", + "RequiresDuplicateDetection": false + }, + "Subscriptions": [ + { + "Name": "e2e-test-sub", + "Properties": { + "DeadLetteringOnMessageExpiration": false, + "DefaultMessageTimeToLive": "PT1H", + "LockDuration": "PT1M", + "MaxDeliveryCount": 3, + "ForwardDeadLetteredMessagesTo": "", + "ForwardTo": "", + "RequiresSession": false + } + } + ] + } + ] + } + ], + "Logging": { + "Type": "File" + } + } +} \ No newline at end of file diff --git a/src/utils/servicebus/docker-compose.yml b/src/utils/servicebus/docker-compose.yml new file mode 100644 index 00000000..a1160710 --- /dev/null +++ b/src/utils/servicebus/docker-compose.yml @@ -0,0 +1,42 @@ +name: microsoft-azure-servicebus +services: + sbemulator: + container_name: "servicebus-emulator" + image: mcr.microsoft.com/azure-messaging/servicebus-emulator:latest + volumes: + - "./config.json:/ServiceBus_Emulator/ConfigFiles/Config.json" + ports: + - "5672:5672" + environment: + SQL_SERVER: sqledge + MSSQL_SA_PASSWORD: ${AzureWebJobsSQLPassword} + ACCEPT_EULA: Y + depends_on: + - sqledge + networks: + sb-emulator: + aliases: + - "servicebus-emulator" + sqledge: + container_name: "sqledge" + image: "mcr.microsoft.com/azure-sql-edge:latest" + ports: + - "1431:1431" + - "1433:1433" + networks: + sb-emulator: + aliases: + - "sqledge" + environment: + ACCEPT_EULA: Y + MSSQL_SA_PASSWORD: ${AzureWebJobsSQLPassword} + # Service for the Azurite Storage Emulator + azurite: + container_name: "azurite" + image: "mcr.microsoft.com/azure-storage/azurite:latest" + ports: + - "10000:10000" + - "10001:10001" + - "10002:10002" +networks: + sb-emulator: \ No newline at end of file diff --git a/src/utils/setupCosmosDB.ts b/src/utils/setupCosmosDB.ts deleted file mode 100644 index b7a68bc0..00000000 --- a/src/utils/setupCosmosDB.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. - -// The CosmosDB emulator requires a container and database to be created before running tests but after the emulator starts -// Otherwise the following error will occur: -// Microsoft.Azure.Cosmos.Client: This builder instance has already been used to build a processor. Create a new instance to build another. - -import { CosmosClient, PartitionKeyKind } from '@azure/cosmos'; -import { cosmosDBConnectionString } from './connectionStrings'; -import { CosmosDB } from '../constants'; - -export async function setupCosmosDB() { - const partitionKeyPath = `/${CosmosDB.partitionKey}`; - const client = new CosmosClient(cosmosDBConnectionString); - await client.databases.createIfNotExists({ id: CosmosDB.triggerDatabaseName }); - await client.database(CosmosDB.triggerDatabaseName).containers.createIfNotExists({ - id: CosmosDB.triggerContainerName, - partitionKey: { paths: [partitionKeyPath], kind: PartitionKeyKind.Hash } - }); - await client.database(CosmosDB.triggerDatabaseName).containers.createIfNotExists({ - id: CosmosDB.triggerAndOutputContainerName, - partitionKey: { paths: [partitionKeyPath], kind: PartitionKeyKind.Hash } - }); -} \ No newline at end of file diff --git a/src/utils/sql/docker-compose.yml b/src/utils/sql/docker-compose.yml new file mode 100644 index 00000000..5d12463d --- /dev/null +++ b/src/utils/sql/docker-compose.yml @@ -0,0 +1,15 @@ +services: + mssql: + image: mcr.microsoft.com/mssql/server:2022-latest + container_name: mssql + ports: + - "15433:1433" + environment: + SA_PASSWORD: ${SA_PASSWORD} + ACCEPT_EULA: "Y" + volumes: + - mssql_data:/var/opt/mssql + restart: unless-stopped + +volumes: + mssql_data: \ No newline at end of file diff --git a/src/utils/sql/setupSql.ts b/src/utils/sql/setupSql.ts new file mode 100644 index 00000000..59b4c770 --- /dev/null +++ b/src/utils/sql/setupSql.ts @@ -0,0 +1,89 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import * as sql from 'mssql'; +import retry from 'p-retry'; +import { sqlConnectionString, sqlTestConnectionString } from '../connectionStrings'; +import { Sql } from '../../constants'; + +export async function runSqlSetupQueries() { + // STEP 1: Create DB if not exists + let pool = await createPoolConnnection(sqlConnectionString); + await pool.request().query(` + IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = '${Sql.dbName}') + BEGIN + CREATE DATABASE [${Sql.dbName}]; + END + `); + + // STEP 2: Retry ALTER DATABASE (change_tracking) + try { + await retry(async (currentAttempt) => { + if (currentAttempt > 1) { + console.log( + `${new Date().toISOString()}: Retrying ALTER DATABASE. Attempt ${currentAttempt}` + ); + } + await pool.request().query(` + IF NOT EXISTS ( + SELECT 1 + FROM sys.change_tracking_databases + WHERE database_id = DB_ID('${Sql.dbName}') + ) + BEGIN + ALTER DATABASE [${Sql.dbName}] + SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON); + END + `); + }, { + retries: 5, + minTimeout: 5000 + }); + } finally { + await pool.close(); + } + + // STEP 3: Create tables and enable tracking + pool = await createPoolConnnection(sqlTestConnectionString); + try { + for (const table of [Sql.sqlTriggerTable, Sql.sqlNonTriggerTable]) { + await pool.request().query(` + IF OBJECT_ID('dbo.${table}', 'U') IS NULL + BEGIN + CREATE TABLE dbo.${table} ( + id UNIQUEIDENTIFIER PRIMARY KEY, + testData NVARCHAR(200) NOT NULL + ); + ALTER TABLE dbo.${table} ENABLE CHANGE_TRACKING; + END + `); + } + } finally { + await pool.close(); + } +} + +export async function createPoolConnnection(connectionString: string): Promise { + const retries = 5; + return retry( + async (currentAttempt: number) => { + if (currentAttempt > 1) { + console.log( + `${new Date().toISOString()}: Retrying sql connect. Attempt ${currentAttempt}/${retries + 1}` + ); + } + return sql.connect(connectionString); + }, + { + retries: retries, + minTimeout: 5 * 1000, + onFailedAttempt: (error) => { + if (!/ip address/i.test(error?.message || '')) { + throw error; // abort for an unrecognized error + } else if (error.retriesLeft > 0) { + console.log(`Warning: Failed to sql connect with error "${error.message}"`); + } + }, + } + ); +} \ No newline at end of file diff --git a/src/utils/validateEnvVar.ts b/src/utils/validateEnvVar.ts deleted file mode 100644 index 7abf90d1..00000000 --- a/src/utils/validateEnvVar.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. - -import { isDefined } from './nonNull'; - -export function validateEnvVar(name: string): string { - const value = process.env[name]; - if (!isDefined(value)) { - throw new Error(`You must set the environment variable "${name}".`); - } - return value; -}