From f96958bf2a2d07495ebb38334b045b2a865c616e Mon Sep 17 00:00:00 2001 From: "Stephen Weatherford (MSFT)" Date: Thu, 11 Nov 2021 15:42:14 -0800 Subject: [PATCH] service bus and blob container snippets (#1416) * Add service bus snippets * remove 'other' from choices Co-authored-by: Stephen Weatherford --- .../ServiceBus Namespace.snippet.json | 21 +++++++++ .../ServiceBus Queue.snippet.json | 31 +++++++++++++ .../Storage Blob Container.snippet.json | 21 +++++++++ src/snippets/SnippetManager.ts | 2 +- test/DeploymentTemplate.test.ts | 5 --- test/functional/snippets.test.ts | 36 ++++++++++++++- .../ServiceBus Namespace.snippetresult.json | 36 +++++++++++++++ .../ServiceBus Queue.snippetresult.json | 44 +++++++++++++++++++ .../Storage Blob Container.snippetresult.json | 34 ++++++++++++++ 9 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 assets/resourceSnippets/ServiceBus Namespace.snippet.json create mode 100644 assets/resourceSnippets/ServiceBus Queue.snippet.json create mode 100644 assets/resourceSnippets/Storage Blob Container.snippet.json create mode 100644 test/snippets/expected/ServiceBus Namespace.snippetresult.json create mode 100644 test/snippets/expected/ServiceBus Queue.snippetresult.json create mode 100644 test/snippets/expected/Storage Blob Container.snippetresult.json diff --git a/assets/resourceSnippets/ServiceBus Namespace.snippet.json b/assets/resourceSnippets/ServiceBus Namespace.snippet.json new file mode 100644 index 000000000..24d40be50 --- /dev/null +++ b/assets/resourceSnippets/ServiceBus Namespace.snippet.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "prefix": "arm-servicebus-namespace", + "description": "ServiceBus Namespace" + }, + "resources": [ + { + "name": "${1:serviceBusNamespace1}", + "type": "Microsoft.ServiceBus/namespaces", + "apiVersion": "2021-01-01-preview", + "location": /*${2|[parameters('location')],[resourceGroup().location]|}*/ "location", + "sku": { + "name": "Standard" + }, + "properties": { + } + } + ] +} diff --git a/assets/resourceSnippets/ServiceBus Queue.snippet.json b/assets/resourceSnippets/ServiceBus Queue.snippet.json new file mode 100644 index 000000000..92b0d2058 --- /dev/null +++ b/assets/resourceSnippets/ServiceBus Queue.snippet.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "prefix": "arm-servicebus-queue", + "description": "ServiceBus Queue" + }, + "resources": [ + { + "name": "${1:serviceBusNamespace1}/${2:serviceBusQueue1}", + "type": "Microsoft.ServiceBus/namespaces/queues", + "apiVersion": "2021-01-01-preview", + "dependsOn": [ + "[resourceId('Microsoft.ServiceBus/namespaces', '${2:serviceBusQueue1}')]" + ], + "properties": { + "lockDuration": "${3|PT5M,PT30S|}", + "maxSizeInMegabytes": 1024, + "requiresDuplicateDetection": false, + "requiresSession": false, + "defaultMessageTimeToLive": "${4|P14D,PT10M,P10675199DT2H48M5.4775807S|}", + "deadLetteringOnMessageExpiration": false, + "duplicateDetectionHistoryTimeWindow": "PT10M", + "maxDeliveryCount": 10, + "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S", + "enablePartitioning": false, + "enableExpress": false + } + } + ] +} diff --git a/assets/resourceSnippets/Storage Blob Container.snippet.json b/assets/resourceSnippets/Storage Blob Container.snippet.json new file mode 100644 index 000000000..a51ff88cf --- /dev/null +++ b/assets/resourceSnippets/Storage Blob Container.snippet.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "prefix": "arm-storage-blob-container", + "description": "Storage Blob Container" + }, + "resources": [ + { + "name": "${1:accountName}/default/${2:blobContainerName}", + "type": "Microsoft.Storage/storageAccounts/blobServices/containers", + "apiVersion": "2021-04-01", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts', '${1:accountName}')]" + ], + "properties": { + "publicAccess": "None" + } + } + ] +} diff --git a/src/snippets/SnippetManager.ts b/src/snippets/SnippetManager.ts index 7b8889c80..c8656d5b7 100644 --- a/src/snippets/SnippetManager.ts +++ b/src/snippets/SnippetManager.ts @@ -86,7 +86,7 @@ export class SnippetManager implements ISnippetManager { const snippetFiles = await fse.readdir(folderPath); for (const relativePath of snippetFiles.filter(f => f !== 'README.jsonc')) { const snippetName = relativePath.replace(/(.*)\.snippet\.json$/, '$1'); - assert(snippetName !== relativePath, `Incorrectly formed resource snippet file name ${relativePath}`); + assert(snippetName !== relativePath, `Resource snippet ${snippetName} should have this filename: ${relativePath}`); const content: string = await readUtf8FileWithBom(path.join(folderPath, relativePath)); const snippet = createResourceSnippetFromFile(snippetName, content); const internalSnippet = convertToInternalSnippet(snippetName, snippet); diff --git a/test/DeploymentTemplate.test.ts b/test/DeploymentTemplate.test.ts index d7289e75e..81ef5567a 100644 --- a/test/DeploymentTemplate.test.ts +++ b/test/DeploymentTemplate.test.ts @@ -917,11 +917,6 @@ suite("DeploymentTemplate", () => { suite("ReferenceInVariableDefinitionJSONVisitor", () => { suite("constructor(DeploymentTemplate)", () => { - test("with undefined", () => { - // tslint:disable-next-line:no-any - assert.throws(() => { new ReferenceInVariableDefinitionsVisitor(undefined); }); - }); - test("with deploymentTemplate", () => { const dt = new DeploymentTemplateDoc(`{ "variables": { "a": "[reference('test')]" } }`, fakeId, 0); const visitor = new ReferenceInVariableDefinitionsVisitor(dt); diff --git a/test/functional/snippets.test.ts b/test/functional/snippets.test.ts index 3e93c3db3..9d9fb9c17 100644 --- a/test/functional/snippets.test.ts +++ b/test/functional/snippets.test.ts @@ -59,6 +59,34 @@ let resourceTemplate: string = `{ \t] }`; +let resourceTemplateWithLocation: string = `{ + \t"resources": [ + \t\t//Insert here: resource + \t], + \t"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + \t"contentVersion": "1.0.0.0", + \t"variables": { + \t\t//Insert here: variable + \t}, + \t"parameters": { + \t\t"location": { + \t\t\t"type": "string" + \t\t} + \t\t//Insert here: parameter + \t}, + \t"outputs": { + \t\t//Insert here: output + \t}, + \t"functions": [ + \t\t{ + \t\t\t"namespace": "udf", + \t\t\t"members": { + \t\t\t\t//Insert here: user function + \t\t\t} + \t\t} + \t] + }`; + let emptyTemplate: string = ` //Insert here: empty `; @@ -280,7 +308,13 @@ suite("Snippets functional tests", () => { validateSnippet(); - const template = overrideTemplateForSnippet[snippetName] !== undefined ? overrideTemplateForSnippet[snippetName] : resourceTemplate; + let defaultTemplate = resourceTemplate; + if (snippet.insertText.includes("parameters('location')")) { + // add location parameter if used in snippet + defaultTemplate = resourceTemplateWithLocation; + } + const template = overrideTemplateForSnippet[snippetName] !== undefined ? overrideTemplateForSnippet[snippetName] : defaultTemplate; + // tslint:disable-next-line: strict-boolean-expressions const expectedDiagnostics = (overrideExpectedDiagnostics[snippetName] || []).sort(); // tslint:disable-next-line: strict-boolean-expressions diff --git a/test/snippets/expected/ServiceBus Namespace.snippetresult.json b/test/snippets/expected/ServiceBus Namespace.snippetresult.json new file mode 100644 index 000000000..78d9a313e --- /dev/null +++ b/test/snippets/expected/ServiceBus Namespace.snippetresult.json @@ -0,0 +1,36 @@ +{ + "resources": [ + { + "name": "serviceBusNamespace1", + "type": "Microsoft.ServiceBus/namespaces", + "apiVersion": "2021-01-01-preview", + "location": "[parameters('location')]", + "sku": { + "name": "Standard" + }, + "properties": {} + } + ], + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "variables": { + //Insert here: variable + }, + "parameters": { + "location": { + "type": "string" + } + //Insert here: parameter + }, + "outputs": { + //Insert here: output + }, + "functions": [ + { + "namespace": "udf", + "members": { + //Insert here: user function + } + } + ] +} \ No newline at end of file diff --git a/test/snippets/expected/ServiceBus Queue.snippetresult.json b/test/snippets/expected/ServiceBus Queue.snippetresult.json new file mode 100644 index 000000000..1701c368a --- /dev/null +++ b/test/snippets/expected/ServiceBus Queue.snippetresult.json @@ -0,0 +1,44 @@ +{ + "resources": [ + { + "name": "serviceBusNamespace1/serviceBusQueue1", + "type": "Microsoft.ServiceBus/namespaces/queues", + "apiVersion": "2021-01-01-preview", + "dependsOn": [ + "[resourceId('Microsoft.ServiceBus/namespaces', 'serviceBusQueue1')]" + ], + "properties": { + "lockDuration": "PT5M", + "maxSizeInMegabytes": 1024, + "requiresDuplicateDetection": false, + "requiresSession": false, + "defaultMessageTimeToLive": "P14D", + "deadLetteringOnMessageExpiration": false, + "duplicateDetectionHistoryTimeWindow": "PT10M", + "maxDeliveryCount": 10, + "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S", + "enablePartitioning": false, + "enableExpress": false + } + } + ], + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "variables": { + //Insert here: variable + }, + "parameters": { + //Insert here: parameter + }, + "outputs": { + //Insert here: output + }, + "functions": [ + { + "namespace": "udf", + "members": { + //Insert here: user function + } + } + ] +} \ No newline at end of file diff --git a/test/snippets/expected/Storage Blob Container.snippetresult.json b/test/snippets/expected/Storage Blob Container.snippetresult.json new file mode 100644 index 000000000..07c570cb2 --- /dev/null +++ b/test/snippets/expected/Storage Blob Container.snippetresult.json @@ -0,0 +1,34 @@ +{ + "resources": [ + { + "name": "accountName/default/blobContainerName", + "type": "Microsoft.Storage/storageAccounts/blobServices/containers", + "apiVersion": "2021-04-01", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts', 'accountName')]" + ], + "properties": { + "publicAccess": "None" + } + } + ], + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "variables": { + //Insert here: variable + }, + "parameters": { + //Insert here: parameter + }, + "outputs": { + //Insert here: output + }, + "functions": [ + { + "namespace": "udf", + "members": { + //Insert here: user function + } + } + ] +}