Skip to content

Commit 6a902a1

Browse files
authored
Merge pull request #7 from ZianWang02/feature/Cdn
Add AzCdnEndpointContent Tests
2 parents 8619c6d + d47aa24 commit 6a902a1

File tree

2 files changed

+328
-16
lines changed

2 files changed

+328
-16
lines changed

src/Cdn/Cdn.Autorest/test/Clear-AzCdnEndpointContent.Tests.ps1

Lines changed: 164 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,175 @@ if(($null -eq $TestName) -or ($TestName -contains 'Clear-AzCdnEndpointContent'))
1515
}
1616

1717
Describe 'Clear-AzCdnEndpointContent' {
18-
It 'PurgeExpanded' -skip {
19-
{ throw [System.NotImplementedException] } | Should -Not -Throw
18+
It 'PurgeExpanded' {
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_Verizon";
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+
40+
New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -IsHttpAllowed -IsHttpsAllowed `
41+
-Location $location -Origin $origin -IsCompressionEnabled -ContentTypesToCompress "text/html","text/css" `
42+
-OriginHostHeader "www.bing.com" -OriginPath "/photos" -QueryStringCachingBehavior "IgnoreQueryString"
43+
$contentPath = @("/movies/*","/pictures/pic1.jpg")
44+
45+
# Purge content on endpoint should succeed
46+
Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentPath $contentPath
47+
# Purge content on non-existing endpoint should fail
48+
{ Clear-AzCdnEndpointContent -EndpointName "fakeEndpoint" -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentPath $contentPath } | Should -Throw
49+
# Purge content on endpoint with invalid content paths should fail
50+
{ Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentPath "invalidpath!" } | Should -Throw
51+
# Purge content on stopped endpoint should fail
52+
Stop-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName
53+
{ Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentPath $contentPath } | Should -Throw
54+
} Finally
55+
{
56+
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait
57+
}
58+
} | Should -Not -Throw
2059
}
2160

22-
It 'Purge' -skip {
23-
{ throw [System.NotImplementedException] } | Should -Not -Throw
61+
It 'Purge' {
62+
{
63+
$ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6)
64+
try
65+
{
66+
Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)"
67+
New-AzResourceGroup -Name $ResourceGroupName -Location $env.location;
68+
69+
$cdnProfileName = 'p-' + (RandomString -allChars $false -len 6);
70+
Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)"
71+
72+
$profileSku = "Standard_Verizon";
73+
New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global
74+
75+
$endpointName = 'e-' + (RandomString -allChars $false -len 6);
76+
$origin = @{
77+
Name = "origin1"
78+
HostName = "host1.hello.com"
79+
};
80+
$location = "westus"
81+
Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)"
82+
83+
New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -IsHttpAllowed -IsHttpsAllowed `
84+
-Location $location -Origin $origin -IsCompressionEnabled -ContentTypesToCompress "text/html","text/css" `
85+
-OriginHostHeader "www.bing.com" -OriginPath "/photos" -QueryStringCachingBehavior "IgnoreQueryString"
86+
$contentPath = @{ ContentPath = @("/movies/*","/pictures/pic1.jpg") }
87+
88+
# Purge content on endpoint should succeed
89+
Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentFilePath $contentPath
90+
# Purge content on non-existing endpoint should fail
91+
{ Clear-AzCdnEndpointContent -EndpointName "fakeEndpoint" -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentFilePath $contentPath } | Should -Throw
92+
# Purge content on endpoint with invalid content paths should fail
93+
{ Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentFilePath @{ ContentPath = "invalidpath!" } } | Should -Throw
94+
# Purge content on stopped endpoint should fail
95+
Stop-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName
96+
{ Clear-AzCdnEndpointContent -EndpointName $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName -ContentFilePath $contentPath } | Should -Throw
97+
} Finally
98+
{
99+
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait
100+
}
101+
} | Should -Not -Throw
24102
}
25103

26-
It 'PurgeViaIdentityExpanded' -skip {
27-
{ throw [System.NotImplementedException] } | Should -Not -Throw
104+
It 'PurgeViaIdentityExpanded' {
105+
{
106+
$PSDefaultParameterValues['Disabled'] = $true
107+
$ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6)
108+
try
109+
{
110+
Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)"
111+
New-AzResourceGroup -Name $ResourceGroupName -Location $env.location;
112+
113+
$cdnProfileName = 'p-' + (RandomString -allChars $false -len 6);
114+
Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)"
115+
116+
$profileSku = "Standard_Verizon";
117+
New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global
118+
119+
$endpointName = 'e-' + (RandomString -allChars $false -len 6);
120+
$origin = @{
121+
Name = "origin1"
122+
HostName = "host1.hello.com"
123+
};
124+
$location = "westus"
125+
Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)"
126+
127+
New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -IsHttpAllowed -IsHttpsAllowed `
128+
-Location $location -Origin $origin -IsCompressionEnabled -ContentTypesToCompress "text/html","text/css" `
129+
-OriginHostHeader "www.bing.com" -OriginPath "/photos" -QueryStringCachingBehavior "IgnoreQueryString"
130+
$contentPath = @("/movies/*","/pictures/pic1.jpg")
131+
132+
# Purge content on endpoint should succeed
133+
$endpoint = Get-AzCdnEndpoint -Name $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName
134+
$endpoint | Clear-AzCdnEndpointContent -ContentPath $contentPath
135+
# Purge content on endpoint with invalid content paths should fail
136+
{ $endpoint | Clear-AzCdnEndpointContent -ContentPath "invalidpath!" } | Should -Throw
137+
# Purge content on stopped endpoint should fail
138+
Stop-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName
139+
{ $endpoint | Clear-AzCdnEndpointContent -ContentPath $contentPath } | Should -Throw
140+
} Finally
141+
{
142+
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait
143+
}
144+
} | Should -Not -Throw
28145
}
29146

30-
It 'PurgeViaIdentity' -skip {
31-
{ throw [System.NotImplementedException] } | Should -Not -Throw
147+
It 'PurgeViaIdentity' {
148+
{
149+
$PSDefaultParameterValues['Disabled'] = $true
150+
$ResourceGroupName = 'testps-rg-' + (RandomString -allChars $false -len 6)
151+
try
152+
{
153+
Write-Host -ForegroundColor Green "Create test group $($ResourceGroupName)"
154+
New-AzResourceGroup -Name $ResourceGroupName -Location $env.location;
155+
156+
$cdnProfileName = 'p-' + (RandomString -allChars $false -len 6);
157+
Write-Host -ForegroundColor Green "Use cdnProfileName : $($cdnProfileName)"
158+
159+
$profileSku = "Standard_Verizon";
160+
New-AzCdnProfile -SkuName $profileSku -Name $cdnProfileName -ResourceGroupName $ResourceGroupName -Location Global
161+
162+
$endpointName = 'e-' + (RandomString -allChars $false -len 6);
163+
$origin = @{
164+
Name = "origin1"
165+
HostName = "host1.hello.com"
166+
};
167+
$location = "westus"
168+
Write-Host -ForegroundColor Green "Create endpointName : $($endpointName), origin.Name : $($origin.Name), origin.HostName : $($origin.HostName)"
169+
170+
New-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName -IsHttpAllowed -IsHttpsAllowed `
171+
-Location $location -Origin $origin -IsCompressionEnabled -ContentTypesToCompress "text/html","text/css" `
172+
-OriginHostHeader "www.bing.com" -OriginPath "/photos" -QueryStringCachingBehavior "IgnoreQueryString"
173+
$contentPath = @{ ContentPath = @("/movies/*","/pictures/pic1.jpg") }
174+
175+
# Purge content on endpoint should succeed
176+
$endpoint = Get-AzCdnEndpoint -Name $endpointName -ProfileName $cdnProfileName -ResourceGroupName $ResourceGroupName
177+
$endpoint | Clear-AzCdnEndpointContent -ContentFilePath $contentPath
178+
# Purge content on endpoint with invalid content paths should fail
179+
{ $endpoint | Clear-AzCdnEndpointContent -ContentFilePath @{ ContentPath = "invalidpath!" } } | Should -Throw
180+
# Purge content on stopped endpoint should fail
181+
Stop-AzCdnEndpoint -Name $endpointName -ResourceGroupName $ResourceGroupName -ProfileName $cdnProfileName
182+
{ $endpoint | Clear-AzCdnEndpointContent -ContentFilePath $contentPath } | Should -Throw
183+
} Finally
184+
{
185+
Remove-AzResourceGroup -Name $ResourceGroupName -NoWait
186+
}
187+
} | Should -Not -Throw
32188
}
33189
}

0 commit comments

Comments
 (0)