forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaTests.ps1
194 lines (169 loc) · 9.42 KB
/
MediaTests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
<#
.SYNOPSIS
Test Media related Cmdlets
#>
function Test-Media
{
$rgname = GetResourceGroupName
$preferedlocation = "East US"
$location = Get-AvailableLocation $preferedlocation
Write-Output $location
$resourceGroup = CreateResourceGroup $rgname $location
$storageAccountName1 = "sto" + $rgname
$storageAccount1 = CreateStorageAccount $rgname $storageAccountName1 $location
$storageAccountName2 = "sto" + $rgname + "2"
$storageAccount2 = CreateStorageAccount $rgname $storageAccountName2 $location
<# Check name availability #>
$accountName = "med" + $rgname
$availability = Get-AzMediaServiceNameAvailability -AccountName $accountName
Assert-AreEqual $true $availability.nameAvailable
<# Create a media service with specifiying the primary storage account only #>
$accountName = "med" + $rgname
$tags = @{"tag1" = "value1"; "tag2" = "value2"}
$storageAccount1 = GetStorageAccount -ResourceGroupName $rgname -Name $storageAccountName1
$mediaService = New-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Location $location -StorageAccountId $storageAccount1.Id -Tag $tags
Assert-NotNull $mediaService
Assert-AreEqual $accountName $mediaService.AccountName
Assert-AreEqual $rgname $mediaService.ResourceGroupName
Assert-AreEqual $location $mediaService.Location
Assert-Tags $tags $mediaService.Tags
Assert-AreEqual $storageAccountName1 $mediaService.StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $rgname $mediaService.StorageAccounts[0].ResourceGroupName
$availability = Get-AzMediaServiceNameAvailability -AccountName $accountName
Assert-AreEqual $false $availability.nameAvailable
<# Get a media service with specifying resource group only #>
$mediaServices = Get-AzMediaService -ResourceGroupName $rgname
Assert-NotNull $mediaServices
Assert-AreEqual 1 $mediaServices.Count
Assert-AreEqual $accountName $mediaServices[0].AccountName
Assert-AreEqual $rgname $mediaServices[0].ResourceGroupName
Assert-AreEqual $location $mediaServices[0].Location
Assert-AreEqual $storageAccountName1 $mediaServices[0].StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $rgname $mediaServices[0].StorageAccounts[0].ResourceGroupName
<# Get a media service with specifying resource group and account name #>
$mediaService = Get-AzMediaService -ResourceGroupName $rgname -AccountName $accountName
Assert-NotNull $mediaService
Assert-AreEqual $accountName $mediaService.AccountName
Assert-AreEqual $rgname $mediaService.ResourceGroupName
Assert-AreEqual $location $mediaService.Location
Assert-AreEqual $storageAccountName1 $mediaService.StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $rgname $mediaService.StorageAccounts[0].ResourceGroupName
<# Set a media service #>
$tagsUpdated = @{"tag3" = "value3"; "tag4" = "value4"}
$storageAccount2 = GetStorageAccount -ResourceGroupName $rgname -Name $storageAccountName2
$primaryStorageAccount = New-AzMediaServiceStorageConfig -storageAccountId $storageAccount1.Id -IsPrimary
$secondaryStorageAccount = New-AzMediaServiceStorageConfig -storageAccountId $storageAccount2.Id
$storageAccounts = @($primaryStorageAccount, $secondaryStorageAccount)
$mediaServiceUpdated = Set-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Tag $tagsUpdated -StorageAccounts $storageAccounts
Assert-NotNull $mediaServiceUpdated
Assert-Tags $tagsUpdated $mediaServiceUpdated.Tags
Assert-AreEqual $storageAccountName1 $mediaServiceUpdated.StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $storageAccountName2 $mediaServiceUpdated.StorageAccounts[1].AccountName
Assert-AreEqual $false $mediaServiceUpdated.StorageAccounts[1].IsPrimary
<# Get service keys #>
$serviceKeys = Get-AzMediaServiceKeys -ResourceGroupName $rgname -AccountName $accountName
Assert-NotNull $serviceKeys
Assert-NotNull $serviceKeys.PrimaryAuthEndpoint
Assert-NotNull $serviceKeys.PrimaryKey
Assert-NotNull $serviceKeys.SecondaryAuthEndpoint
Assert-NotNull $serviceKeys.SecondaryKey
Assert-NotNull $serviceKeys.Scope
<# Set service key #>
$serviceKeysUpdated1 = Set-AzMediaServiceKey -ResourceGroupName $rgname -AccountName $accountName -KeyType Primary
Assert-NotNull $serviceKeysUpdated1
Assert-NotNull $serviceKeysUpdated1.Key
Assert-AreNotEqual $serviceKeys.PrimaryKey $serviceKeysUpdated1.Key
$serviceKeysUpdated2 = Set-AzMediaServiceKey -ResourceGroupName $rgname -AccountName $accountName -KeyType Secondary
Assert-NotNull $serviceKeysUpdated2
Assert-NotNull $serviceKeysUpdated2.Key
Assert-AreNotEqual $serviceKeys.SecondaryKey $serviceKeysUpdated2.Key
<# Remove media service #>
Remove-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Force
$mediaServices = Get-AzMediaService -ResourceGroupName $rgname
Assert-Null $mediaServices
<# Create a media service with multiple storage accounts #>
$tags = @{"tag1" = "value1"; "tag2" = "value2"}
$mediaService = New-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Location $location -StorageAccounts $storageAccounts -Tag $tags
Assert-NotNull $mediaService
Assert-AreEqual $accountName $mediaService.AccountName
Assert-AreEqual $rgname $mediaService.ResourceGroupName
Assert-AreEqual $location $mediaService.Location
Assert-Tags $tags $mediaService.Tags
Assert-AreEqual $storageAccountName1 $mediaService.StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $rgname $mediaService.StorageAccounts[0].ResourceGroupName
Assert-AreEqual $storageAccountName2 $mediaService.StorageAccounts[1].AccountName
Assert-AreEqual $false $mediaService.StorageAccounts[1].IsPrimary
Assert-AreEqual $rgname $mediaService.StorageAccounts[1].ResourceGroupName
Remove-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Force
RemoveStorageAccount $rgname $storageAccountName1
RemoveStorageAccount $rgname $storageAccountName2
RemoveResourceGroup $rgname
}
<#
.SYNOPSIS
Test Media related Cmdlets with piping
#>
function Test-MediaWithPiping
{
$rgname = GetResourceGroupName
$preferedlocation = "East US"
$location = Get-AvailableLocation $preferedlocation
$resourceGroup = CreateResourceGroup $rgname $location
Assert-NotNull $resourceGroup
Assert-AreEqual $rgname $resourceGroup.ResourceGroupName
Assert-AreEqual $location $resourceGroup.Location
$storageAccountName1 = "sto" + $rgname
$storageAccount1 = CreateStorageAccount $rgname $storageAccountName1 $location
<# Create a media service with piping #>
$accountName = "med" + $rgname
$tags = @{"tag1" = "value1"; "tag2" = "value2"}
$mediaService = GetStorageAccount -ResourceGroupName $rgname -Name $storageAccountName1 | New-AzMediaService -ResourceGroupName $rgname -AccountName $accountName -Location $location -Tag $tags
Assert-NotNull $mediaService
Assert-AreEqual $accountName $mediaService.AccountName
Assert-AreEqual $rgname $mediaService.ResourceGroupName
Assert-AreEqual $location $mediaService.Location
Assert-Tags $tags $mediaService.Tags
Assert-AreEqual $storageAccountName1 $mediaService.StorageAccounts[0].AccountName
Assert-AreEqual $true $mediaService.StorageAccounts[0].IsPrimary
Assert-AreEqual $rgname $mediaService.StorageAccounts[0].ResourceGroupName
<# Update a media service with piping #>
$tagsUpdated = @{"tag3" = "value3"; "tag4" = "value4"}
$mediaServiceUpdated = Get-AzMediaService -ResourceGroupName $rgname -AccountName $accountName | Set-AzMediaService -Tag $tagsUpdated
Assert-NotNull $mediaServiceUpdated
Assert-Tags $tagsUpdated $mediaServiceUpdated.Tags
<# Get service keys with piping #>
$serviceKeys = Get-AzMediaService -ResourceGroupName $rgname -AccountName $accountName | Get-AzMediaServiceKeys
Assert-NotNull $serviceKeys
Assert-NotNull $serviceKeys.PrimaryAuthEndpoint
Assert-NotNull $serviceKeys.PrimaryKey
Assert-NotNull $serviceKeys.SecondaryAuthEndpoint
Assert-NotNull $serviceKeys.SecondaryKey
Assert-NotNull $serviceKeys.Scope
<# Set service keys with piping #>
$serviceKeysUpdated2 = Get-AzMediaService -ResourceGroupName $rgname -AccountName $accountName | Set-AzMediaServiceKey -KeyType Secondary
Assert-NotNull $serviceKeysUpdated2
Assert-NotNull $serviceKeysUpdated2.Key
Assert-AreNotEqual $serviceKeys.SecondaryKey $serviceKeysUpdated2.Key
<# Remove media service with piping #>
Get-AzMediaService -ResourceGroupName $rgname -AccountName $accountName | Remove-AzMediaService -Force
RemoveStorageAccount $rgname $storageAccountName
RemoveResourceGroup $rgname
}