|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +<# |
| 16 | +.SYNOPSIS |
| 17 | +Tests EventGrid Topic Create, Get and List operations. |
| 18 | +#> |
| 19 | +function SystemTopicEventSubscriptionTests { |
| 20 | + # Setup |
| 21 | + $location = Get-LocationForEventGrid |
| 22 | + $topicName = Get-TopicName |
| 23 | + $topicName2 = Get-TopicName |
| 24 | + $topicName3 = Get-TopicName |
| 25 | + $topicName4 = Get-TopicName |
| 26 | + $eventSubscriptionName = Get-EventSubscriptionName |
| 27 | + $eventSubscriptionName2 = Get-EventSubscriptionName |
| 28 | + $eventSubscriptionName3 = Get-EventSubscriptionName |
| 29 | + $resourceGroupName = Get-ResourceGroupName |
| 30 | + $secondResourceGroup = Get-ResourceGroupName |
| 31 | + $subscriptionId = Get-SubscriptionId |
| 32 | + |
| 33 | + New-ResourceGroup $resourceGroupName $location |
| 34 | + |
| 35 | + New-ResourceGroup $secondResourceGroup $location |
| 36 | + |
| 37 | + $eventSubscriptionEndpoint = Get-EventSubscriptionWebhookEndpoint |
| 38 | + $eventSubscriptionEndpointCloudEvent = Get-EventSubscriptionWebhookEndpointWithCloudEvent |
| 39 | + |
| 40 | + $storageAccountName = Get-StorageAccountName |
| 41 | + $storageContainerName = Get-StorageBlobName |
| 42 | + |
| 43 | + New-StorageBlob $resourceGroupName $storageAccountName $storageContainerName $location |
| 44 | + $storageAccountResourceId = Get-StorageAccountResourceId $resourceGroupName $storageAccountName |
| 45 | + try |
| 46 | + { |
| 47 | + Write-Debug "Creating a new EventGrid SystemTopic: $topicName in resource group $resourceGroupName" |
| 48 | + Write-Debug "Topic: $topicName" |
| 49 | + $result = New-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName -Source $storageAccountResourceId -TopicType 'microsoft.storage.storageaccounts' -Location $location |
| 50 | + Assert-True {$result.ProvisioningState -eq "Succeeded"} |
| 51 | + |
| 52 | + Write-Debug "Getting the created topic within the resource group" |
| 53 | + $createdTopic = Get-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName |
| 54 | + Assert-True {$createdTopic.Count -eq 1} |
| 55 | + Assert-True {$createdTopic.TopicName -eq $topicName} "System Topic created earlier is not found." |
| 56 | + |
| 57 | + #Write-Debug "Creating a second EventGrid SystemTopic: $topicName2 in resource group $secondResourceGroup" |
| 58 | + #$result = New-AzEventGridSystemTopic -ResourceGroup $secondResourceGroup -Name $topicName2 -Source $sbNamespace1InRg2.Id -TopicType 'Microsoft.ServiceBus.Namespaces' -Location $location -Tag @{ Dept = "IT"; Environment = "Test" } |
| 59 | + #Assert-True {$result.ProvisioningState -eq "Succeeded"} |
| 60 | + |
| 61 | + Write-Debug "Creating a new EventSubscription $eventSubscriptionName to topic $topicName in resource group $resourceGroupName" |
| 62 | + $result = New-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Endpoint $eventSubscriptionEndpoint -EventSubscriptionName $eventSubscriptionName |
| 63 | + Assert-True {$result.ProvisioningState -eq "Succeeded"} |
| 64 | + |
| 65 | + Write-Debug "Get event subscription created for system topic : $topicName" |
| 66 | + $createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName |
| 67 | + Assert-True {$createdEventSubscription.EventSubscriptionName -eq $eventSubscriptionName} "Event subscription created earlier is not found in the list" |
| 68 | + |
| 69 | + Write-Debug "Creating 2nd EventSubscription $eventSubscriptionName2 to topic $topicName in resource group $resourceGroupName" |
| 70 | + $result = New-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Endpoint $eventSubscriptionEndpoint -EventSubscriptionName $eventSubscriptionName2 |
| 71 | + Assert-True {$result.ProvisioningState -eq "Succeeded"} |
| 72 | + |
| 73 | + Write-Debug "Get event subscription created for system topic : $topicName" |
| 74 | + $createdEventSubscription2 = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName |
| 75 | + Assert-True {$createdEventSubscription2.Count -ge 0} "Event subscription created earlier is not found in the list" |
| 76 | + |
| 77 | + Write-Debug "Get event subscription created for system topic : $topicName" |
| 78 | + $createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Top 1 |
| 79 | + Assert-True {$createdEventSubscription.NextLink -ne $null } "NextLink should not be null as more event subscription should be available under system topic" |
| 80 | + |
| 81 | + Write-Debug "Get event subscription created for system topic : $topicName with nextlink" |
| 82 | + $createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -NextLink $createdEventSubscription.NextLink |
| 83 | + Assert-True {$createdEventSubscription -ne $null } "Event subscription should not be null as more event subscription should be available under system topic" |
| 84 | + |
| 85 | + $labels = "Finance", "HR" |
| 86 | + Write-Debug "Updating a EventGrid SystemTopic Eventsubscription with TopicName: $topicName in resource group $resourceGroupName and EventSubscriptionName: $eventSubscriptionName" |
| 87 | + $result = Update-AzEventGridSystemTopicEventSubscription -EventSubscriptionName $eventSubscriptionName -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Label $labels |
| 88 | + Assert-True {$result.ProvisioningState -eq "Succeeded"} |
| 89 | + $updatedLabels = $result.Labels |
| 90 | + Assert-AreEqual 2 $updatedLabels.Count; |
| 91 | + Assert-AreEqual "Finance" $updatedLabels[0]; |
| 92 | + Assert-AreEqual "HR" $updatedLabels[1]; |
| 93 | + |
| 94 | + Write-Debug "Get Delivery attributes for topic: $topicName and Eventsubscription $eventSubscriptionName" |
| 95 | + $createdEventSubscriptionDa = Get-AzEventGridSystemTopicEventSubscriptionDeliveryAttribute -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName |
| 96 | + |
| 97 | + Write-Debug "Get full url for topic: $topicName and Eventsubscription $eventSubscriptionName" |
| 98 | + $createdEventSubscriptionDa = Get-AzEventGridFullUrlForSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + Write-Debug "Deleting event subscription : $eventSubscriptionName for system topic : $topicName" |
| 104 | + Remove-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName -Force |
| 105 | + |
| 106 | + Write-Debug "Deleting event subscription : $eventSubscriptionName for system topic : $topicName" |
| 107 | + Remove-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName2 -Force |
| 108 | + |
| 109 | + |
| 110 | + Write-Debug "Deleting topic: $topicName" |
| 111 | + Remove-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName -Force |
| 112 | + |
| 113 | + #Write-Debug "Deleting topic: $topicName" |
| 114 | + #Remove-AzEventGridSystemTopic -ResourceGroup $secondResourceGroup -Name $topicName2 |
| 115 | + |
| 116 | + |
| 117 | + } |
| 118 | + finally |
| 119 | + { |
| 120 | + Remove-StorageContainerResources $resourceGroupName $storageAccountName $storageContainerName |
| 121 | + |
| 122 | + Remove-ResourceGroup $resourceGroupName |
| 123 | + Remove-ResourceGroup $secondResourceGroup |
| 124 | + } |
| 125 | +} |
| 126 | + |
0 commit comments