Skip to content

Commit 6a31c5b

Browse files
authored
Merge pull request #23 from ZianWang02/feature/Cdn
Add DeliveryPolicy & Rule Tests
2 parents 3ab1c3b + d733502 commit 6a31c5b

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed

src/Cdn/Cdn.Autorest/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ directive:
6666
- model-cmdlet:
6767
- UserManagedHttpsParameters
6868
- CdnManagedHttpsParameters
69+
- DeliveryRule
6970
# CDN condition
7071
- DeliveryRuleRemoteAddressCondition
7172
- DeliveryRuleRequestMethodCondition

src/Cdn/Cdn.Autorest/docs/Az.Cdn.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ Create an in-memory object for DeliveryRuleHttpVersionCondition.
118118
### [New-AzCdnDeliveryRuleIsDeviceConditionObject](New-AzCdnDeliveryRuleIsDeviceConditionObject.md)
119119
Create an in-memory object for DeliveryRuleIsDeviceCondition.
120120

121+
### [New-AzCdnDeliveryRuleObject](New-AzCdnDeliveryRuleObject.md)
122+
Create an in-memory object for DeliveryRule.
123+
121124
### [New-AzCdnDeliveryRulePostArgsConditionObject](New-AzCdnDeliveryRulePostArgsConditionObject.md)
122125
Create an in-memory object for DeliveryRulePostArgsCondition.
123126

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
external help file:
3+
Module Name: Az.Cdn
4+
online version: https://docs.microsoft.com/powershell/module/az.Cdn/new-AzCdnDeliveryRuleObject
5+
schema: 2.0.0
6+
---
7+
8+
# New-AzCdnDeliveryRuleObject
9+
10+
## SYNOPSIS
11+
Create an in-memory object for DeliveryRule.
12+
13+
## SYNTAX
14+
15+
```
16+
New-AzCdnDeliveryRuleObject -Action <IDeliveryRuleAction1[]> -Order <Int32>
17+
[-Condition <IDeliveryRuleCondition[]>] [-Name <String>] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
Create an in-memory object for DeliveryRule.
22+
23+
## EXAMPLES
24+
25+
### Example 1: {{ Add title here }}
26+
```powershell
27+
{{ Add code here }}
28+
```
29+
30+
```output
31+
{{ Add output here }}
32+
```
33+
34+
{{ Add description here }}
35+
36+
### Example 2: {{ Add title here }}
37+
```powershell
38+
{{ Add code here }}
39+
```
40+
41+
```output
42+
{{ Add output here }}
43+
```
44+
45+
{{ Add description here }}
46+
47+
## PARAMETERS
48+
49+
### -Action
50+
A list of actions that are executed when all the conditions of a rule are satisfied.
51+
To construct, see NOTES section for ACTION properties and create a hash table.
52+
53+
```yaml
54+
Type: Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.IDeliveryRuleAction1[]
55+
Parameter Sets: (All)
56+
Aliases:
57+
58+
Required: True
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: False
62+
Accept wildcard characters: False
63+
```
64+
65+
### -Condition
66+
A list of conditions that must be matched for the actions to be executed.
67+
To construct, see NOTES section for CONDITION properties and create a hash table.
68+
69+
```yaml
70+
Type: Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.IDeliveryRuleCondition[]
71+
Parameter Sets: (All)
72+
Aliases:
73+
74+
Required: False
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### -Name
82+
Name of the rule.
83+
84+
```yaml
85+
Type: System.String
86+
Parameter Sets: (All)
87+
Aliases:
88+
89+
Required: False
90+
Position: Named
91+
Default value: None
92+
Accept pipeline input: False
93+
Accept wildcard characters: False
94+
```
95+
96+
### -Order
97+
The order in which the rules are applied for the endpoint.
98+
Possible values {0,1,2,3,………}.
99+
A rule with a lesser order will be applied before a rule with a greater order.
100+
Rule with order 0 is a special rule.
101+
It does not require any condition and actions listed in it will always be applied.
102+
103+
```yaml
104+
Type: System.Int32
105+
Parameter Sets: (All)
106+
Aliases:
107+
108+
Required: True
109+
Position: Named
110+
Default value: None
111+
Accept pipeline input: False
112+
Accept wildcard characters: False
113+
```
114+
115+
### CommonParameters
116+
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).
117+
118+
## INPUTS
119+
120+
## OUTPUTS
121+
122+
### Microsoft.Azure.PowerShell.Cmdlets.Cdn.Models.Api20210601.DeliveryRule
123+
124+
## NOTES
125+
126+
ALIASES
127+
128+
COMPLEX PARAMETER PROPERTIES
129+
130+
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.
131+
132+
133+
ACTION <IDeliveryRuleAction1[]>: A list of actions that are executed when all the conditions of a rule are satisfied.
134+
- `Name <DeliveryRuleAction>`: The name of the action for the delivery rule.
135+
136+
CONDITION <IDeliveryRuleCondition[]>: A list of conditions that must be matched for the actions to be executed.
137+
- `Name <MatchVariable>`: The name of the condition for the delivery rule.
138+
139+
## RELATED LINKS
140+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Example 1: {{ Add title here }}
2+
```powershell
3+
{{ Add code here }}
4+
```
5+
6+
```output
7+
{{ Add output here }}
8+
```
9+
10+
{{ Add description here }}
11+
12+
### Example 2: {{ Add title here }}
13+
```powershell
14+
{{ Add code here }}
15+
```
16+
17+
```output
18+
{{ Add output here }}
19+
```
20+
21+
{{ Add description here }}
22+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
if(($null -eq $TestName) -or ($TestName -contains 'New-AzCdnDeliveryRuleObject'))
2+
{
3+
$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1'
4+
if (-Not (Test-Path -Path $loadEnvPath)) {
5+
$loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1'
6+
}
7+
. ($loadEnvPath)
8+
$TestRecordingFile = Join-Path $PSScriptRoot 'New-AzCdnDeliveryRuleObject.Recording.json'
9+
$currentPath = $PSScriptRoot
10+
while(-not $mockingPath) {
11+
$mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File
12+
$currentPath = Split-Path -Path $currentPath -Parent
13+
}
14+
. ($mockingPath | Select-Object -First 1).FullName
15+
}
16+
17+
Describe 'New-AzCdnDeliveryRuleObject' {
18+
It '__AllParameterSets' {
19+
{
20+
$ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6)
21+
try
22+
{
23+
Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)"
24+
New-AzResourceGroup -Name $ResourceGroupName -Location $env.location
25+
26+
$cdnProfileName = 'p-' + (RandomString -allChars $false -len 6);
27+
Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)"
28+
29+
$profileSku = "Standard_Microsoft";
30+
New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global
31+
32+
$endpointName = 'e-' + (RandomString -allChars $false -len 6);
33+
$origin = @{
34+
Name = "origin1"
35+
HostName = "host1.hello.com"
36+
};
37+
$location = "westus"
38+
Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)"
39+
$cond1 = New-AzCdnDeliveryRuleIsDeviceConditionObject -Name "IsDevice" -ParameterMatchValue "Desktop"
40+
$action1 = New-AzCdnUrlRewriteActionObject -Name "UrlRewrite" -ParameterDestination "/def" -ParameterSourcePattern "/abc" -ParameterPreserveUnmatchedPath $true
41+
$action2 = New-AzCdnDeliveryRuleCacheKeyQueryStringActionObject -Name "CacheKeyQueryString" -ParameterQueryStringBehavior "ExcludeAll" -ParameterQueryParameter "abc,def"
42+
$action3 = New-AzCdnDeliveryRuleCacheKeyQueryStringActionObject -Name "CacheKeyQueryString" -ParameterQueryStringBehavior "IncludeAll"
43+
$redirect = New-AzCdnUrlRedirectActionObject -Name "UrlRedirect" -ParameterRedirectType "Found" -ParameterDestinationProtocol "MatchRequest"
44+
$rule0 = New-AzCdnDeliveryRuleObject -Name "EmptyCondition" -Action $redirect,$action3 -Order 0
45+
$rule1 = New-AzCdnDeliveryRuleObject -Name "Rule1" -Action $action1,$action2 -Condition $cond1 -Order 1
46+
$deliverypolicy = @($rule0,$rule1)
47+
48+
$endpoint = New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin -DeliveryPolicyRule $deliverypolicy
49+
50+
$endpoint.DeliveryPolicyRule.Count | Should -Be 2
51+
52+
$endpointName2 = 'e-' + (RandomString -allChars $false -len 6);
53+
$action = New-AzCdnDeliveryRuleResponseHeaderActionObject -Name "ModifyResponseHeader" -ParameterHeaderAction "Append" -ParameterHeaderName "Access-Control-Allow-Origin" -ParameterValue "*"
54+
$condition = New-AzCdnDeliveryRuleUrlPathConditionObject -Name "UrlPath" -ParameterOperator "Contains" -ParameterMatchValue "abc"
55+
$newRule = New-AzCdnDeliveryRuleObject -Name "Rule1" -Condition $condition -Action $action -Order 1
56+
$deliverypolicy = @($newRule)
57+
58+
$endpoint = New-AzCdnEndpoint -Name $endpointName2 -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -Location $location -Origin $origin -DeliveryPolicyRule $deliverypolicy
59+
60+
$endpoint.DeliveryPolicyRule.Count | Should -Be 1
61+
} Finally
62+
{
63+
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait
64+
}
65+
} | Should -Not -Throw
66+
}
67+
}

0 commit comments

Comments
 (0)