Skip to content

Commit

Permalink
Update to CnameRecordSet no longer ignores changes to the cname prope…
Browse files Browse the repository at this point in the history
…rty (#26128)

Fixes #26357.
  • Loading branch information
anderius authored Jan 11, 2022
1 parent b512734 commit 2d5adc1
Show file tree
Hide file tree
Showing 4 changed files with 507 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Update CnameRecordSet to make it no longer ignore changes to the cname property

### Other Changes

## 2.10.0 (2021-11-22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public String canonicalName() {

@Override
protected RecordSetInner prepareForUpdate(RecordSetInner resource) {
if (resource.cnameRecord() == null) {
resource.withCnameRecord(new CnameRecord());
}
if (innerModel().cnameRecord().cname() != null) {
resource.cnameRecord().withCname(innerModel().cnameRecord().cname());
}
innerModel().withCnameRecord(new CnameRecord());
return resource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.resourcemanager.privatedns;

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.http.rest.PagedIterable;
import com.azure.core.management.Region;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.privatedns.models.CnameRecordSet;
import com.azure.resourcemanager.privatedns.models.PrivateDnsZone;
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 com.azure.resourcemanager.test.utils.TestUtilities;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.temporal.ChronoUnit;
import java.util.List;

public class PrivateDnsZoneCnameRecordSetTests extends ResourceManagerTestBase {
private String rgName = "";

protected ResourceManager resourceManager;
protected PrivateDnsZoneManager privateZoneManager;

@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()));
privateZoneManager = buildManager(PrivateDnsZoneManager.class, httpPipeline, profile);
resourceManager = privateZoneManager.resourceManager();
rgName = generateRandomResourceName("prdncsrstest", 15);
}

@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().beginDeleteByName(rgName);
}

@Test
public void canUpdateCname() {
final Region region = Region.US_EAST;
final String topLevelDomain = "www.contoso" + generateRandomResourceName("z", 10) + ".com";

PrivateDnsZone dnsZone =
privateZoneManager
.privateZones()
.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(1234)
.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(1234, updatedCnameRecordSet.timeToLive());
Assertions.assertEquals("new.contoso.com", updatedCnameRecordSet.canonicalName());
}
}
Loading

0 comments on commit 2d5adc1

Please sign in to comment.