-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ZianWang02/feature/Cdn
Add DeliveryPolicy & Rule Tests
- Loading branch information
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/Cdn/Cdn.Autorest/docs/New-AzCdnDeliveryRuleObject.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
--- | ||
external help file: | ||
Module Name: Az.Cdn | ||
online version: https://docs.microsoft.com/powershell/module/az.Cdn/new-AzCdnDeliveryRuleObject | ||
schema: 2.0.0 | ||
--- | ||
|
||
# New-AzCdnDeliveryRuleObject | ||
|
||
## SYNOPSIS | ||
Create an in-memory object for DeliveryRule. | ||
|
||
## SYNTAX | ||
|
||
``` | ||
New-AzCdnDeliveryRuleObject -Action <IDeliveryRuleAction1[]> -Order <Int32> | ||
[-Condition <IDeliveryRuleCondition[]>] [-Name <String>] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Create an in-memory object for DeliveryRule. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1: {{ Add title here }} | ||
```powershell | ||
{{ Add code here }} | ||
``` | ||
|
||
```output | ||
{{ Add output here }} | ||
``` | ||
|
||
{{ Add description here }} | ||
|
||
### Example 2: {{ Add title here }} | ||
```powershell | ||
{{ Add code here }} | ||
``` | ||
|
||
```output | ||
{{ Add output here }} | ||
``` | ||
|
||
{{ Add description here }} | ||
|
||
## PARAMETERS | ||
|
||
### -Action | ||
A list of actions that are executed when all the conditions of a rule are satisfied. | ||
To construct, see NOTES section for ACTION properties and create a hash table. | ||
|
||
```yaml | ||
Type: Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.IDeliveryRuleAction1[] | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Condition | ||
A list of conditions that must be matched for the actions to be executed. | ||
To construct, see NOTES section for CONDITION properties and create a hash table. | ||
```yaml | ||
Type: Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.IDeliveryRuleCondition[] | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Name | ||
Name of the rule. | ||
```yaml | ||
Type: System.String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Order | ||
The order in which the rules are applied for the endpoint. | ||
Possible values {0,1,2,3,………}. | ||
A rule with a lesser order will be applied before a rule with a greater order. | ||
Rule with order 0 is a special rule. | ||
It does not require any condition and actions listed in it will always be applied. | ||
```yaml | ||
Type: System.Int32 | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
## INPUTS | ||
## OUTPUTS | ||
### Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.DeliveryRule | ||
## NOTES | ||
ALIASES | ||
COMPLEX PARAMETER PROPERTIES | ||
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. | ||
ACTION <IDeliveryRuleAction1[]>: A list of actions that are executed when all the conditions of a rule are satisfied. | ||
- `Name <DeliveryRuleAction>`: The name of the action for the delivery rule. | ||
|
||
CONDITION <IDeliveryRuleCondition[]>: A list of conditions that must be matched for the actions to be executed. | ||
- `Name <MatchVariable>`: The name of the condition for the delivery rule. | ||
|
||
## RELATED LINKS | ||
|
22 changes: 22 additions & 0 deletions
22
src/Cdn/Cdn.Autorest/examples/New-AzCdnDeliveryRuleObject.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
### Example 1: {{ Add title here }} | ||
```powershell | ||
{{ Add code here }} | ||
``` | ||
|
||
```output | ||
{{ Add output here }} | ||
``` | ||
|
||
{{ Add description here }} | ||
|
||
### Example 2: {{ Add title here }} | ||
```powershell | ||
{{ Add code here }} | ||
``` | ||
|
||
```output | ||
{{ Add output here }} | ||
``` | ||
|
||
{{ Add description here }} | ||
|
67 changes: 67 additions & 0 deletions
67
src/Cdn/Cdn.Autorest/test/New-AzCdnDeliveryRuleObject.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
if(($null -eq $TestName) -or ($TestName -contains 'New-AzCdnDeliveryRuleObject')) | ||
{ | ||
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' | ||
if (-Not (Test-Path -Path $loadEnvPath)) { | ||
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' | ||
} | ||
. ($loadEnvPath) | ||
$TestRecordingFile = Join-Path $PSScriptRoot 'New-AzCdnDeliveryRuleObject.Recording.json' | ||
$currentPath = $PSScriptRoot | ||
while(-not $mockingPath) { | ||
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File | ||
$currentPath = Split-Path -Path $currentPath -Parent | ||
} | ||
. ($mockingPath | Select-Object -First 1).FullName | ||
} | ||
|
||
Describe 'New-AzCdnDeliveryRuleObject' { | ||
It '__AllParameterSets' { | ||
{ | ||
$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)" | ||
$cond1 = New-AzCdnDeliveryRuleIsDeviceConditionObject -Name "IsDevice" -ParameterMatchValue "Desktop" | ||
$action1 = New-AzCdnUrlRewriteActionObject -Name "UrlRewrite" -ParameterDestination "/def" -ParameterSourcePattern "/abc" -ParameterPreserveUnmatchedPath $true | ||
$action2 = New-AzCdnDeliveryRuleCacheKeyQueryStringActionObject -Name "CacheKeyQueryString" -ParameterQueryStringBehavior "ExcludeAll" -ParameterQueryParameter "abc,def" | ||
$action3 = New-AzCdnDeliveryRuleCacheKeyQueryStringActionObject -Name "CacheKeyQueryString" -ParameterQueryStringBehavior "IncludeAll" | ||
$redirect = New-AzCdnUrlRedirectActionObject -Name "UrlRedirect" -ParameterRedirectType "Found" -ParameterDestinationProtocol "MatchRequest" | ||
$rule0 = New-AzCdnDeliveryRuleObject -Name "EmptyCondition" -Action $redirect,$action3 -Order 0 | ||
$rule1 = New-AzCdnDeliveryRuleObject -Name "Rule1" -Action $action1,$action2 -Condition $cond1 -Order 1 | ||
$deliverypolicy = @($rule0,$rule1) | ||
|
||
$endpoint = New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin -DeliveryPolicyRule $deliverypolicy | ||
|
||
$endpoint.DeliveryPolicyRule.Count | Should -Be 2 | ||
|
||
$endpointName2 = 'e-' + (RandomString -allChars $false -len 6); | ||
$action = New-AzCdnDeliveryRuleResponseHeaderActionObject -Name "ModifyResponseHeader" -ParameterHeaderAction "Append" -ParameterHeaderName "Access-Control-Allow-Origin" -ParameterValue "*" | ||
$condition = New-AzCdnDeliveryRuleUrlPathConditionObject -Name "UrlPath" -ParameterOperator "Contains" -ParameterMatchValue "abc" | ||
$newRule = New-AzCdnDeliveryRuleObject -Name "Rule1" -Condition $condition -Action $action -Order 1 | ||
$deliverypolicy = @($newRule) | ||
|
||
$endpoint = New-AzCdnEndpoint -Name $endpointName2 -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin -DeliveryPolicyRule $deliverypolicy | ||
|
||
$endpoint.DeliveryPolicyRule.Count | Should -Be 1 | ||
} Finally | ||
{ | ||
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait | ||
} | ||
} | Should -Not -Throw | ||
} | ||
} |