-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgmt, fix dns cname update flow (#26400)
* mgmt, fix dns cname update flow * changelog * fix an unrelated changelog
- Loading branch information
1 parent
2025744
commit b512734
Showing
7 changed files
with
771 additions
and
56 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
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
59 changes: 59 additions & 0 deletions
59
...er/azure-resourcemanager-dns/src/test/java/com/azure/resourcemanager/dns/DnsTestBase.java
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,59 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.resourcemanager.dns; | ||
|
||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.http.HttpClient; | ||
import com.azure.core.http.HttpPipeline; | ||
import com.azure.core.http.policy.HttpLogOptions; | ||
import com.azure.core.http.policy.HttpPipelinePolicy; | ||
import com.azure.core.http.policy.RetryPolicy; | ||
import com.azure.core.management.profile.AzureProfile; | ||
import com.azure.resourcemanager.resources.ResourceManager; | ||
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider; | ||
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; | ||
import com.azure.resourcemanager.test.ResourceManagerTestBase; | ||
import com.azure.resourcemanager.test.utils.TestDelayProvider; | ||
|
||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
public class DnsTestBase extends ResourceManagerTestBase { | ||
|
||
protected String rgName = ""; | ||
|
||
protected ResourceManager resourceManager; | ||
protected DnsZoneManager zoneManager; | ||
|
||
@Override | ||
protected HttpPipeline buildHttpPipeline( | ||
TokenCredential credential, | ||
AzureProfile profile, | ||
HttpLogOptions httpLogOptions, | ||
List<HttpPipelinePolicy> policies, | ||
HttpClient httpClient) { | ||
return HttpPipelineProvider.buildHttpPipeline( | ||
credential, | ||
profile, | ||
null, | ||
httpLogOptions, | ||
null, | ||
new RetryPolicy("Retry-After", ChronoUnit.SECONDS), | ||
policies, | ||
httpClient); | ||
} | ||
|
||
@Override | ||
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) { | ||
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode())); | ||
zoneManager = buildManager(DnsZoneManager.class, httpPipeline, profile); | ||
resourceManager = zoneManager.resourceManager(); | ||
rgName = generateRandomResourceName("dnsetagtest", 15); | ||
} | ||
|
||
@Override | ||
protected void cleanUpResources() { | ||
resourceManager.resourceGroups().deleteByName(rgName); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...azure-resourcemanager-dns/src/test/java/com/azure/resourcemanager/dns/RecordSetTests.java
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,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.resourcemanager.dns; | ||
|
||
import com.azure.core.http.rest.PagedIterable; | ||
import com.azure.core.management.Region; | ||
import com.azure.resourcemanager.dns.models.CnameRecordSet; | ||
import com.azure.resourcemanager.dns.models.DnsZone; | ||
import com.azure.resourcemanager.test.utils.TestUtilities; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RecordSetTests extends DnsTestBase { | ||
|
||
@Test | ||
public void canCRUDCname() { | ||
final Region region = Region.US_EAST; | ||
final String topLevelDomain = "www.contoso" + rgName + ".com"; | ||
|
||
DnsZone dnsZone = | ||
zoneManager | ||
.zones() | ||
.define(topLevelDomain) | ||
.withNewResourceGroup(rgName, region) | ||
.defineCNameRecordSet("www") | ||
.withAlias("cname.contoso.com") | ||
.withTimeToLive(7200) | ||
.attach() | ||
.create(); | ||
|
||
// Check CNAME records | ||
dnsZone.refresh(); | ||
PagedIterable<CnameRecordSet> cnameRecordSets = dnsZone.cNameRecordSets().list(); | ||
Assertions.assertEquals(1, TestUtilities.getSize(cnameRecordSets)); | ||
CnameRecordSet cnameRecordSet = cnameRecordSets.iterator().next(); | ||
Assertions.assertEquals("www", cnameRecordSet.name()); | ||
Assertions.assertEquals(7200, cnameRecordSet.timeToLive()); | ||
Assertions.assertEquals("cname.contoso.com", cnameRecordSet.canonicalName()); | ||
|
||
// Update alias and ttl: | ||
dnsZone | ||
.update() | ||
.updateCNameRecordSet("www") | ||
.withAlias("new.contoso.com") | ||
.withTimeToLive(3600) | ||
.parent() | ||
.apply(); | ||
|
||
// Check CNAME records | ||
dnsZone.refresh(); | ||
PagedIterable<CnameRecordSet> updatedCnameRecordSets = dnsZone.cNameRecordSets().list(); | ||
Assertions.assertEquals(1, TestUtilities.getSize(updatedCnameRecordSets)); | ||
CnameRecordSet updatedCnameRecordSet = updatedCnameRecordSets.iterator().next(); | ||
Assertions.assertEquals(3600, updatedCnameRecordSet.timeToLive()); | ||
Assertions.assertEquals("new.contoso.com", updatedCnameRecordSet.canonicalName()); | ||
} | ||
} |
Oops, something went wrong.