Skip to content

Commit 9a23cc1

Browse files
committed
Merge pull request #1 from t-alguer/ignite_team
Filtering and Pagination
2 parents 7c5772d + 8e191cc commit 9a23cc1

File tree

15 files changed

+1875
-209
lines changed

15 files changed

+1875
-209
lines changed

src/ResourceManager/Dns/Commands.Dns.Test/Commands.Dns.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
<Compile Include="ScenarioTests\ZoneTests.cs" />
138138
<Compile Include="ScenarioTests\RecordsTests.cs" />
139139
<Compile Include="ScenarioTests\DnsTestsBase.cs" />
140+
<Compile Include="UnitTests\GetAzureDnsRecordSetTests.cs" />
141+
<Compile Include="UnitTests\GetAzureDnsZoneTests.cs" />
140142
</ItemGroup>
141143
<ItemGroup>
142144
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
@@ -194,6 +196,7 @@
194196
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetCrudWithPiping.json" />
195197
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetEtagMismatch.json" />
196198
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetGet.json" />
199+
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetGetWithEndsWith.json" />
197200
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetMX.json" />
198201
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetNS.json" />
199202
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests\TestRecordSetRemoveRecordTypeMismatch.json" />
@@ -202,6 +205,7 @@
202205
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneCrud.json" />
203206
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneCrudWithPiping.json" />
204207
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneList.json" />
208+
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneListWithEndsWith.json" />
205209
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneRemoveEtagMismatch.json" />
206210
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneRemoveNotFound.json" />
207211
<None Include="SessionRecords\Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests\TestZoneSetEtagMismatch.json" />

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/RecordsTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,12 @@ public void TestRecordSetGet()
138138
{
139139
RunPowerShellTest("Test-RecordSetGet");
140140
}
141+
142+
[Fact]
143+
[Trait(Category.AcceptanceType, Category.CheckIn)]
144+
public void TestRecordSetGetWithEndsWith()
145+
{
146+
RunPowerShellTest("Test-RecordSetGetWithEndsWith");
147+
}
141148
}
142149
}

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/RecordsTests.ps1

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ function Test-RecordSetSRV
362362
$record = $record | Add-AzureDnsRecordConfig -Port 53 -Priority 1 -Target ns1.example.com -Weight 5
363363
$record = $record | Add-AzureDnsRecordConfig -Port 53 -Priority 2 -Target ns2.example.com -Weight 10
364364
$record = $record | Remove-AzureDnsRecordConfig -Port 53 -Priority 2 -Target ns2.example.com -Weight 10
365-
$record = $record | Remove-AzureDnsRecordConfig -Port 42 -Priority 2435435 -Target ns5.example.com -Weight 1600
365+
$record = $record | Remove-AzureDnsRecordConfig -Port 42 -Priority 999 -Target ns5.example.com -Weight 1600
366366

367367
$record | Set-AzureDnsRecordSet
368368
$getResult = Get-AzureDnsRecordSet -Name $recordName -ZoneName $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -RecordType SRV
@@ -518,7 +518,7 @@ function Test-RecordSetRemoveRecordTypeMismatch
518518

519519
<#
520520
.SYNOPSIS
521-
Zone CRUD with piping
521+
Record Set Etag Mismatch
522522
#>
523523
function Test-RecordSetEtagMismatch
524524
{
@@ -543,7 +543,7 @@ function Test-RecordSetEtagMismatch
543543

544544
<#
545545
.SYNOPSIS
546-
Zone CRUD with piping
546+
Record Set Get
547547
#>
548548
function Test-RecordSetGet
549549
{
@@ -582,5 +582,51 @@ function Test-RecordSetGet
582582
$zone | Remove-AzureDnsRecordSet -Name $recordName2 -RecordType AAAA -Force
583583
$zone | Remove-AzureDnsRecordSet -Name $recordName3 -RecordType MX -Force
584584

585+
$zone | Remove-AzureDnsZone -Force -IgnoreEtag
586+
}
587+
588+
<#
589+
.SYNOPSIS
590+
Record Set Get using EndsWith parameter
591+
#>
592+
function Test-RecordSetGetWithEndsWith
593+
{
594+
$rootRecordName = "@"
595+
$recordSuffix = ".com"
596+
$anotherSuffix = ".con"
597+
598+
$zoneName = getAssetname
599+
600+
$recordName1 = (getAssetname) + $recordSuffix
601+
$recordName2 = (getAssetname) + $anotherSuffix
602+
$recordName3 = (getAssetname) + $recordSuffix
603+
604+
$zone = TestSetup-CreateResourceGroup | New-AzureDnsZone -Name $zoneName
605+
606+
# test for root records
607+
$rootRecords = $zone | Get-AzureDnsRecordSet -EndsWith $rootRecordName
608+
609+
Assert-AreEqual 2 $rootRecords.Count -Message ("Expected 2 root records. Actual: " + $rootRecords.Count)
610+
611+
New-AzureDnsRecordSet -Zone $zone -Name $recordName1 -Ttl 100 -RecordType AAAA
612+
New-AzureDnsRecordSet -Zone $zone -Name $recordName2 -Ttl 1200 -RecordType AAAA
613+
New-AzureDnsRecordSet -Zone $zone -Name $recordName3 -Ttl 1500 -RecordType MX
614+
615+
# test for records within type
616+
$aaaaRecords = $zone | Get-AzureDnsRecordSet -RecordType AAAA -EndsWith $recordSuffix
617+
$mxRecords = $zone | Get-AzureDnsRecordSet -RecordType MX -EndsWith $recordSuffix
618+
619+
Assert-AreEqual 1 $aaaaRecords.Count -Message ("Expected 1 AAAA record. Actual: " + $aaaaRecords.Count)
620+
Assert-AreEqual 1 $mxRecords.Count -Message ("Expected 1 MX record. Actual: " + $mxRecords.Count)
621+
622+
# all records
623+
$allRecords = $zone | Get-AzureDnsRecordSet -EndsWith $recordSuffix
624+
625+
Assert-AreEqual 2 $allRecords.Count -Message ("Expected 2 records across types. Actual: " + $allRecords.Count)
626+
627+
$zone | Remove-AzureDnsRecordSet -Name $recordName1 -RecordType AAAA -Force
628+
$zone | Remove-AzureDnsRecordSet -Name $recordName2 -RecordType AAAA -Force
629+
$zone | Remove-AzureDnsRecordSet -Name $recordName3 -RecordType MX -Force
630+
585631
$zone | Remove-AzureDnsZone -Force -IgnoreEtag
586632
}

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/ZoneTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public void TestZoneList()
4040
{
4141
RunPowerShellTest("Test-ZoneList");
4242
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void TestZoneListWithEndsWith()
47+
{
48+
RunPowerShellTest("Test-ZoneListWithEndsWith");
49+
}
4350

4451
[Fact(Skip = "Service does not yet support this")]
4552
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/ZoneTests.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,30 @@ function Test-ZoneList
201201
Assert-NotNull $resourceGroup.ResourceGroupName $result[1].ResourceGroupName
202202
Assert-AreEqual 0 $result[1].Tags.Count
203203

204+
$result | Remove-AzureDnsZone -PassThru -Force
205+
}
206+
207+
<#
208+
.SYNOPSIS
209+
Zone List With EndsWith
210+
#>
211+
function Test-ZoneListWithEndsWith
212+
{
213+
$suffix = ".com"
214+
$suffixWithDot = ".com."
215+
$zoneName1 = getAssetname
216+
$zoneName2 = $zoneName1 + $suffix
217+
$resourceGroup = TestSetup-CreateResourceGroup
218+
$createdZone1 = $resourceGroup | New-AzureDnsZone -Name $zoneName1
219+
$createdZone2 = $resourceGroup | New-AzureDnsZone -Name $zoneName2
220+
221+
$result = Get-AzureDnsZone -ResourceGroupName $resourceGroup.ResourceGroupName -EndsWith $suffixWithDot
222+
223+
Assert-AreEqual 1 $result.Count
224+
225+
Assert-AreEqual $createdZone2.Etag $result[0].Etag
226+
Assert-AreEqual $createdZone2.Name $result[0].Name
227+
Assert-NotNull $resourceGroup.ResourceGroupName $result[0].ResourceGroupName
228+
204229
$result | Remove-AzureDnsZone -PassThru -Force
205230
}

src/ResourceManager/Dns/Commands.Dns.Test/SessionRecords/Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests/TestRecordSetGet.json

Lines changed: 179 additions & 194 deletions
Large diffs are not rendered by default.

src/ResourceManager/Dns/Commands.Dns.Test/SessionRecords/Microsoft.Azure.Commands.ScenarioTest.DnsTests.RecordsTests/TestRecordSetGetWithEndsWith.json

Lines changed: 961 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Dns/Commands.Dns.Test/SessionRecords/Microsoft.Azure.Commands.ScenarioTest.DnsTests.ZoneTests/TestZoneListWithEndsWith.json

Lines changed: 505 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
16+
{
17+
using System.Management.Automation;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
21+
public class GetAzureDnsRecordSetTests
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void GetAzureDnsRecordSetThrowsExceptionWhenUsingNameAndEndsWith()
26+
{
27+
var cmdlet = new GetAzureDnsRecordSet
28+
{
29+
Name = "record",
30+
ZoneName = "zone.com",
31+
ResourceGroupName = "resourceGroup",
32+
Zone = new DnsZone
33+
{
34+
Name = "zone.com",
35+
ResourceGroupName = "resourceGroup"
36+
},
37+
RecordType = "A",
38+
EndsWith = ".com."
39+
};
40+
41+
Assert.Throws<PSArgumentException>(() => cmdlet.ExecuteCmdlet());
42+
}
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
16+
{
17+
using System.Management.Automation;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
21+
public class GetAzureDnsZoneTests
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void GetAzureDnsZoneThrowsExceptionWhenUsingNameAndEndsWith()
26+
{
27+
var cmdlet = new GetAzureDnsZone
28+
{
29+
Name = "record",
30+
ResourceGroupName = "resourceGroup",
31+
EndsWith = ".com."
32+
};
33+
34+
Assert.Throws<PSArgumentException>(() => cmdlet.ExecuteCmdlet());
35+
}
36+
}
37+
}

src/ResourceManager/Dns/Commands.Dns/Models/DnsClient.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ public DnsZone GetDnsZone(string name, string resourceGroupName)
126126
};
127127
}
128128

129-
public List<DnsZone> ListDnsZones(string resourceGroupName)
129+
public List<DnsZone> ListDnsZones(string resourceGroupName, string endsWith)
130130
{
131-
ZoneListResponse getResponse = this.DnsManagementClient.Zones.List(resourceGroupName);
131+
ZoneListParameters zoneListParameters = new ZoneListParameters
132+
{
133+
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
134+
};
135+
136+
ZoneListResponse getResponse = this.DnsManagementClient.Zones.List(resourceGroupName, zoneListParameters);
132137
return getResponse.Zones.Select(zoneInResponse => new DnsZone
133138
{
134139
Name = zoneInResponse.Name,
@@ -229,18 +234,28 @@ public DnsRecordSet GetDnsRecordSet(string name, string zoneName, string resourc
229234
return GetPowerShellRecordSet(zoneName, resourceGroupName, getResponse.RecordSet);
230235
}
231236

232-
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, RecordType recordType)
237+
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, RecordType recordType, string endsWith)
233238
{
234-
RecordListResponse listResponse = this.DnsManagementClient.Records.List(resourceGroupName, zoneName, recordType);
239+
RecordListParameters recordListParameters = new RecordListParameters
240+
{
241+
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
242+
};
243+
244+
RecordListResponse listResponse = this.DnsManagementClient.Records.List(resourceGroupName, zoneName, recordType, recordListParameters);
235245
return listResponse
236246
.RecordSets
237247
.Select(recordSetInResponse => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSetInResponse))
238248
.ToList();
239249
}
240250

241-
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName)
251+
public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupName, string endsWith)
242252
{
243-
RecordListResponse listResponse = this.DnsManagementClient.Records.ListAll(resourceGroupName, zoneName);
253+
RecordListParameters recordListParameters = new RecordListParameters
254+
{
255+
Filter = endsWith == null ? null : string.Format("endswith(Name,'{0}')", endsWith)
256+
};
257+
258+
RecordListResponse listResponse = this.DnsManagementClient.Records.ListAll(resourceGroupName, zoneName, recordListParameters);
244259
return listResponse
245260
.RecordSets
246261
.Select(recordSetInResponse => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSetInResponse))

src/ResourceManager/Dns/Commands.Dns/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Dns/Commands.Dns/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
<data name="Error_EtagNotSpecified" xml:space="preserve">
136136
<value>The ETag property of the {0} object is empty or "*". In order to perform this operation with optimistic concurrency checks, please set the Etag property (you may need to Get the {0} first). In order to perform the operation without optimistic concurrency checks, please specify the -IgnoreEtag switch. </value>
137137
</data>
138+
<data name="Error_NameAndEndsWith" xml:space="preserve">
139+
<value>Name parameter cannot be used with EndsWith.</value>
140+
</data>
138141
<data name="Error_RemoveRecordTypeMismatch" xml:space="preserve">
139142
<value>Cannot remove a record of type {0} from a record set of type {1}. The types must match.</value>
140143
</data>

src/ResourceManager/Dns/Commands.Dns/Records/GetAzureDnsRescordSet.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public class GetAzureDnsRecordSet : DnsBaseCmdlet
5050
[ValidateNotNullOrEmpty]
5151
public string RecordType { get; set; }
5252

53+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The single or multiple label suffix to search in the relative name.")]
54+
[ValidateNotNullOrEmpty]
55+
public string EndsWith { get; set; }
56+
5357
public override void ExecuteCmdlet()
5458
{
5559
RecordType recordType = default(RecordType);
@@ -72,7 +76,11 @@ public override void ExecuteCmdlet()
7276
resourceGroupName = this.Zone.ResourceGroupName;
7377
}
7478

75-
if (this.Name != null)
79+
if (this.Name != null && this.EndsWith != null)
80+
{
81+
throw new PSArgumentException(ProjectResources.Error_NameAndEndsWith);
82+
}
83+
else if (this.Name != null)
7684
{
7785
if (this.RecordType == null)
7886
{
@@ -87,11 +95,11 @@ public override void ExecuteCmdlet()
8795
List<DnsRecordSet> result = null;
8896
if (this.RecordType == null)
8997
{
90-
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName);
98+
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, this.EndsWith);
9199
}
92100
else
93101
{
94-
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, recordType);
102+
result = this.DnsClient.ListRecordSets(zoneName, resourceGroupName, recordType, this.EndsWith);
95103
}
96104

97105
this.WriteObject(result);

0 commit comments

Comments
 (0)