Skip to content

Commit

Permalink
Merge pull request #10 from ZianWang02/feature/Cdn
Browse files Browse the repository at this point in the history
Add AzCdnOrigin Tests
  • Loading branch information
ChenglongLiu authored Mar 28, 2022
2 parents 2b1b6fa + 60da0b7 commit f40c50f
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/Cdn/Cdn.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
114 changes: 108 additions & 6 deletions src/Cdn/Cdn.Autorest/test/Get-AzCdnOrigin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
49 changes: 47 additions & 2 deletions src/Cdn/Cdn.Autorest/test/New-AzCdnOrigin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
95 changes: 91 additions & 4 deletions src/Cdn/Cdn.Autorest/test/Remove-AzCdnOrigin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/Cdn/Cdn.Autorest/test/Update-AzCdnEndpoint.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f40c50f

Please sign in to comment.