Skip to content

Commit

Permalink
Merge pull request #23 from ZianWang02/feature/Cdn
Browse files Browse the repository at this point in the history
Add DeliveryPolicy & Rule Tests
  • Loading branch information
ChenglongLiu authored Apr 12, 2022
2 parents 3ab1c3b + d733502 commit 6a31c5b
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Cdn/Cdn.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ directive:
- model-cmdlet:
- UserManagedHttpsParameters
- CdnManagedHttpsParameters
- DeliveryRule
# CDN condition
- DeliveryRuleRemoteAddressCondition
- DeliveryRuleRequestMethodCondition
Expand Down
3 changes: 3 additions & 0 deletions src/Cdn/Cdn.Autorest/docs/Az.Cdn.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ Create an in-memory object for DeliveryRuleHttpVersionCondition.
### [New-AzCdnDeliveryRuleIsDeviceConditionObject](New-AzCdnDeliveryRuleIsDeviceConditionObject.md)
Create an in-memory object for DeliveryRuleIsDeviceCondition.

### [New-AzCdnDeliveryRuleObject](New-AzCdnDeliveryRuleObject.md)
Create an in-memory object for DeliveryRule.

### [New-AzCdnDeliveryRulePostArgsConditionObject](New-AzCdnDeliveryRulePostArgsConditionObject.md)
Create an in-memory object for DeliveryRulePostArgsCondition.

Expand Down
140 changes: 140 additions & 0 deletions src/Cdn/Cdn.Autorest/docs/New-AzCdnDeliveryRuleObject.md
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 src/Cdn/Cdn.Autorest/examples/New-AzCdnDeliveryRuleObject.md
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 src/Cdn/Cdn.Autorest/test/New-AzCdnDeliveryRuleObject.Tests.ps1
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
}
}

0 comments on commit 6a31c5b

Please sign in to comment.