From 60da0b79e5d382fdb9bfc4d08f05805ffe7005e8 Mon Sep 17 00:00:00 2001 From: Zian Wang <101320907+ZianWang02@users.noreply.github.com> Date: Mon, 28 Mar 2022 15:22:16 +0800 Subject: [PATCH] Add AzCdnOrigin Tests --- src/Cdn/Cdn.Autorest/README.md | 4 + .../test/Get-AzCdnOrigin.Tests.ps1 | 114 +++++++++++++++++- .../test/New-AzCdnOrigin.Tests.ps1 | 49 +++++++- .../test/Remove-AzCdnOrigin.Tests.ps1 | 95 ++++++++++++++- .../test/Update-AzCdnEndpoint.Tests.ps1 | 2 +- .../test/Update-AzCdnOrigin.Tests.ps1 | 96 ++++++++++++++- 6 files changed, 343 insertions(+), 17 deletions(-) diff --git a/src/Cdn/Cdn.Autorest/README.md b/src/Cdn/Cdn.Autorest/README.md index 800d5b8c7e30..4d30e90584cb 100644 --- a/src/Cdn/Cdn.Autorest/README.md +++ b/src/Cdn/Cdn.Autorest/README.md @@ -163,6 +163,10 @@ directive: where: $.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/originGroups/{originGroupName}"].delete transform: >- $["x-ms-long-running-operation-options"] = {"final-state-via": "azure-async-operation"} + - from: swagger-document + where: $.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/origins/{originName}"].delete + transform: >- + $["x-ms-long-running-operation-options"] = {"final-state-via": "azure-async-operation"} - from: swagger-document where: $.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}"].delete transform: >- diff --git a/src/Cdn/Cdn.Autorest/test/Get-AzCdnOrigin.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/Get-AzCdnOrigin.Tests.ps1 index b0edeea9a2cc..4622304295f4 100644 --- a/src/Cdn/Cdn.Autorest/test/Get-AzCdnOrigin.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/Get-AzCdnOrigin.Tests.ps1 @@ -15,15 +15,117 @@ if(($null -eq $TestName) -or ($TestName -contains 'Get-AzCdnOrigin')) } Describe 'Get-AzCdnOrigin' { - It 'List' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'List' { + { + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + $origin = @{ + Name = "origin1" + HostName = "host1.hello.com" + }; + $location = "westus" + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)" + + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin + $origins = Get-AzCdnOrigin -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + + $origins.Count | Should -Be 1 + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } - It 'Get' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'Get' { + { + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + $originName = "origin1" + $originHostName = "host1.hello.com" + $originHttpPort = 80 + $origin = @{ + Name = $originName + HostName = $originHostName + HttpPort = $originHttpPort + }; + $location = "westus" + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)" + + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin + $origin = Get-AzCdnOrigin -Name $originName -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be $originHostName + $origin.HttpPort | Should -Be $originHttpPort + $origin.HttpsPort | Should -Be $null + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } - It 'GetViaIdentity' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'GetViaIdentity' { + { + $PSDefaultParameterValues['Disabled'] = $true + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + $originName = "origin1" + $originHostName = "host1.hello.com" + $originHttpPort = 80 + $origin = @{ + Name = $originName + HostName = $originHostName + HttpPort = $originHttpPort + }; + $location = "westus" + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)" + + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin + $origin = Get-AzCdnOrigin -Name $originName -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName | Get-AzCdnOrigin + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be $originHostName + $origin.HttpPort | Should -Be $originHttpPort + $origin.HttpsPort | Should -Be $null + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } } diff --git a/src/Cdn/Cdn.Autorest/test/New-AzCdnOrigin.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/New-AzCdnOrigin.Tests.ps1 index 9e707d7ddbe9..f35bbf151afd 100644 --- a/src/Cdn/Cdn.Autorest/test/New-AzCdnOrigin.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/New-AzCdnOrigin.Tests.ps1 @@ -15,7 +15,52 @@ if(($null -eq $TestName) -or ($TestName -contains 'New-AzCdnOrigin')) } Describe 'New-AzCdnOrigin' { - It 'CreateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'CreateExpanded' { + { + $subId = $env.SubscriptionId + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName)" + + $origin = @{ + Name = "origin1" + HostName = "host1.hello.com" + }; + $location = "westus" + $originId = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origins/$($origin.Name)" + $originGroup = @{ + Name = "originGroup1" + HealthProbeSettingProbeIntervalInSecond = 240 + HealthProbeSettingProbePath = "/health.aspx" + HealthProbeSettingProbeProtocol = "Https" + HealthProbeSettingProbeRequestType = "GET" + Origin = @(@{ + Id = $originId + }) + } + $defaultOriginGroup = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origingroups/$($originGroup.Name)" + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location ` + -Origin $origin -OriginGroup $originGroup -DefaultOriginGroupId $defaultOriginGroup + + $origin = New-AzCdnOrigin -Name "origin2" -HostName "host2.hello.com" -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + + $origin.Name | Should -Be "origin2" + $origin.HostName | Should -Be "host2.hello.com" + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } } diff --git a/src/Cdn/Cdn.Autorest/test/Remove-AzCdnOrigin.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/Remove-AzCdnOrigin.Tests.ps1 index 2d24d7b7868b..fd78c7927ce7 100644 --- a/src/Cdn/Cdn.Autorest/test/Remove-AzCdnOrigin.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/Remove-AzCdnOrigin.Tests.ps1 @@ -15,11 +15,98 @@ if(($null -eq $TestName) -or ($TestName -contains 'Remove-AzCdnOrigin')) } Describe 'Remove-AzCdnOrigin' { - It 'Delete' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'Delete' { + { + $subId = $env.SubscriptionId + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName)" + + $origin = @{ + Name = "origin1" + HostName = "host1.hello.com" + }; + $location = "westus" + $originId = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origins/$($origin.Name)" + $originGroup = @{ + Name = "originGroup1" + HealthProbeSettingProbeIntervalInSecond = 240 + HealthProbeSettingProbePath = "/health.aspx" + HealthProbeSettingProbeProtocol = "Https" + HealthProbeSettingProbeRequestType = "GET" + Origin = @(@{ + Id = $originId + }) + } + $defaultOriginGroup = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origingroups/$($originGroup.Name)" + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location ` + -Origin $origin -OriginGroup $originGroup -DefaultOriginGroupId $defaultOriginGroup + + New-AzCdnOrigin -Name "origin2" -HostName "host2.hello.com" -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + Remove-AzCdnOrigin -Name "origin2" -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } - It 'DeleteViaIdentity' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'DeleteViaIdentity' { + { + $PSDefaultParameterValues['Disabled'] = $true + $subId = $env.SubscriptionId + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName)" + + $origin = @{ + Name = "origin1" + HostName = "host1.hello.com" + }; + $location = "westus" + $originId = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origins/$($origin.Name)" + $originGroup = @{ + Name = "originGroup1" + HealthProbeSettingProbeIntervalInSecond = 240 + HealthProbeSettingProbePath = "/health.aspx" + HealthProbeSettingProbeProtocol = "Https" + HealthProbeSettingProbeRequestType = "GET" + Origin = @(@{ + Id = $originId + }) + } + $defaultOriginGroup = "/subscriptions/$subId/resourcegroups/$ResourceGroupName/providers/Microsoft.Cdn/profiles/$cdnProfileName/endpoints/$endpointName/origingroups/$($originGroup.Name)" + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location ` + -Origin $origin -OriginGroup $originGroup -DefaultOriginGroupId $defaultOriginGroup + + New-AzCdnOrigin -Name "origin2" -HostName "host2.hello.com" -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + Get-AzCdnOrigin -Name "origin2" -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName | Remove-AzCdnOrigin + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } } diff --git a/src/Cdn/Cdn.Autorest/test/Update-AzCdnEndpoint.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/Update-AzCdnEndpoint.Tests.ps1 index 2c87f50ecb77..3a80560b62f5 100644 --- a/src/Cdn/Cdn.Autorest/test/Update-AzCdnEndpoint.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/Update-AzCdnEndpoint.Tests.ps1 @@ -15,7 +15,7 @@ if(($null -eq $TestName) -or ($TestName -contains 'Update-AzCdnEndpoint')) } Describe 'Update-AzCdnEndpoint' { - It 'UpdateExpanded' -skip { + It 'UpdateExpanded' { { $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) try diff --git a/src/Cdn/Cdn.Autorest/test/Update-AzCdnOrigin.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/Update-AzCdnOrigin.Tests.ps1 index 781ebd480cd2..d9d425da3dcc 100644 --- a/src/Cdn/Cdn.Autorest/test/Update-AzCdnOrigin.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/Update-AzCdnOrigin.Tests.ps1 @@ -15,11 +15,99 @@ if(($null -eq $TestName) -or ($TestName -contains 'Update-AzCdnOrigin')) } Describe 'Update-AzCdnOrigin' { - It 'UpdateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'UpdateExpanded' { + { + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + $originName = "origin1" + $originHostName = "host1.hello.com" + $originHttpPort = 80 + $origin = @{ + Name = $originName + HostName = $originHostName + HttpPort = $originHttpPort + }; + $location = "westus" + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)" + + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin + $origin = Get-AzCdnOrigin -Name $originName -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be $originHostName + $origin.HttpPort | Should -Be $originHttpPort + $origin.HttpsPort | Should -Be $null + + $origin = Update-AzCdnOrigin -Name $originName -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName ` + -HostName "www.azure.com" -HttpPort 456 -HttpsPort 789 + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be "www.azure.com" + $origin.HttpPort | Should -Be 456 + $origin.HttpsPort | Should -Be 789 + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } - It 'UpdateViaIdentityExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + It 'UpdateViaIdentityExpanded' { + { + $PSDefaultParameterValues['Disabled'] = $true + $ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6) + try + { + Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)" + New-AzResourceGroup -Name $ResourceGroupName -Location $env.location + + $cdnProfileName = 'p-' + (RandomString -allChars $false -len 6); + Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)" + + $profileSku = "Standard_Microsoft"; + New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global + + $endpointName = 'e-' + (RandomString -allChars $false -len 6); + $originName = "origin1" + $originHostName = "host1.hello.com" + $originHttpPort = 80 + $origin = @{ + Name = $originName + HostName = $originHostName + HttpPort = $originHttpPort + }; + $location = "westus" + Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)" + + New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin + $origin = Get-AzCdnOrigin -Name $originName -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be $originHostName + $origin.HttpPort | Should -Be $originHttpPort + $origin.HttpsPort | Should -Be $null + + $origin = $origin | Update-AzCdnOrigin -HostName "www.azure.com" -HttpPort 456 -HttpsPort 789 + + $origin.Name | Should -Be $originName + $origin.HostName | Should -Be "www.azure.com" + $origin.HttpPort | Should -Be 456 + $origin.HttpsPort | Should -Be 789 + } Finally + { + Remove-AzResourceGroup -Name $ResourceGroupName -NoWait + } + } | Should -Not -Throw } }