Skip to content

Commit 019c367

Browse files
authored
mgmt, prepare release azure-resourcemanager-test (#46369)
* prepare release azure-resourcemanager-test update changelog * update readme * address comments * use 1. to allow for auto-numbering in Markdown
1 parent e6a9328 commit 019c367

File tree

3 files changed

+151
-6
lines changed

3 files changed

+151
-6
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Release History
22

3-
## 2.0.0-beta.1 (Unreleased)
3+
## 2.0.0-beta.1 (2025-08-12)
44

5-
- TODO
5+
### Features Added
6+
7+
- Initial release of the `azure-resourcemanager-test` library.

sdk/resourcemanager/azure-resourcemanager-test/README.md

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,151 @@ For documentation on how to use this package, please see [Azure Management Libra
2222
```
2323
[//]: # ({x-version-update-end})
2424

25+
### (Optional) Install TestProxy
26+
27+
TestProxy will be automatically downloaded when running tests. Though you may need to install it to push the recordings to remote repository.
28+
Refer to [TestProxy documentation](https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md).
29+
2530
## Key concepts
2631

32+
The Azure Resource Manager Test library provides a specialized test base class and utilities for testing Azure Resource Manager SDKs. It extends the core testing framework with ARM-specific functionality.
33+
34+
### Core Components
35+
36+
* **ResourceManagerTestProxyTestBase**: The main test base class that provides Azure Resource Manager-specific testing capabilities. It extends `TestProxyTestBase` from azure-core-test and adds:
37+
- Azure credential management using `DefaultAzureCredential`
38+
- Azure profile configuration with tenant, subscription, and environment
39+
- HTTP pipeline configuration with Azure-specific policies
40+
- Built-in sanitizers for common Azure secrets and sensitive data
41+
- Resource naming utilities for generating unique test resource names
42+
43+
* **Test Modes**: Like the core test framework, supports three test modes:
44+
- **LIVE**: Tests run against actual Azure resources
45+
- **RECORD**: Tests run against Azure resources and HTTP interactions are recorded
46+
- **PLAYBACK**: Tests use recorded HTTP interactions without hitting Azure services
47+
48+
* **Azure-specific Sanitization**: Automatically sanitizes common Azure secrets including:
49+
- Subscription IDs, tenant IDs, and client IDs
50+
- Storage account keys and connection strings
51+
- Database passwords and connection strings
52+
- Service principal secrets and certificates
53+
- API keys and access tokens
54+
55+
### Test Environment Setup
56+
57+
For LIVE/RECORD tests, you need:
58+
1. Azure CLI authentication (`az login`)
59+
2. Environment variables:
60+
- `AZURE_TENANT_ID`: Your Azure tenant ID
61+
- `AZURE_SUBSCRIPTION_ID`: Your target subscription ID
62+
63+
### Utility Methods
64+
65+
The base class provides several utility methods:
66+
- `generateRandomResourceName(prefix, maxLen)`: Creates unique resource names for tests
67+
- `generateRandomUuid()`: Generates random UUIDs
68+
- `password()`: Generates random passwords for test resources
69+
- `sshPublicKey()`: Generates SSH public keys for VM tests
70+
- `profile()`: Access to the Azure profile being used
71+
- `isPlaybackMode()`: Check if running in playback mode
72+
- `skipInPlayback()`: Skip test execution in playback mode
73+
2774
## Examples
2875

76+
Here's how to create a test class for RECORD/PLAYBACK using ResourceManagerTestProxyTestBase:
77+
78+
### For azure-resourcemanager libraries
79+
80+
```java
81+
public class AzureResourceManagerTests extends ResourceManagerTestProxyTestBase {
82+
private AzureResourceManager manager;
83+
private ResourceManager resourceManager;
84+
private String resourceGroupName;
85+
86+
public MyServiceManagerTests() {
87+
// Add any custom sanitizers in constructor
88+
addSanitizers(
89+
new TestProxySanitizer("$.properties.customSecret", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY)
90+
);
91+
}
92+
93+
@Override
94+
protected HttpPipeline buildHttpPipeline(TokenCredential credential, AzureProfile profile,
95+
HttpLogOptions httpLogOptions, List<HttpPipelinePolicy> policies, HttpClient httpClient) {
96+
// Build HTTP pipeline with your service-specific requirements
97+
return HttpPipelineProvider.buildHttpPipeline(credential, profile, null, httpLogOptions, null,
98+
new RetryPolicy("Retry-After", ChronoUnit.SECONDS), policies, httpClient);
99+
}
100+
101+
@Override
102+
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
103+
// Set up correct delay configuration for recording/playback. In RECORD mode, LROs (long-running operations) need a configured delay between each polling. While in PLAYBACK, no delay is needed.
104+
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
105+
ResourceManagerUtils.InternalRuntimeContext internalContext = new ResourceManagerUtils.InternalRuntimeContext();
106+
// Set up namer context for recording/playback, in case random names are used for implicit resource creation. Otherwise, PLAYBACK won't be able to pick up the names during RECORD.
107+
internalContext.setIdentifierFunction(name -> new TestIdentifierProvider(testResourceNamer));
108+
109+
// Initialize your service manager and any other required clients
110+
resourceManager = ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
111+
manager = AzureResourceManager.authenticate(httpPipeline, profile);
112+
113+
// Reflectively set the test context for Manager classes
114+
setInternalContext(internalContext, manager, resourceManager);
115+
116+
// Generate resource group name for tests
117+
resourceGroupName = generateRandomResourceName("rg", 20);
118+
}
119+
120+
@Override
121+
protected void cleanUpResources() {
122+
// Clean up any resources created during tests
123+
resourceManager.resourceGroups().beginDeleteByName(resourceGroupName);
124+
}
125+
126+
@Test
127+
public void testCreateResource() {
128+
// Write your own test case here
129+
}
130+
}
131+
```
132+
133+
### For libraries not listed in azure-resourcemanager
134+
135+
Mostly same as [For azure-resourcemanager libraries](#for-azure-resourcemanager-libraries).
136+
Except that in `initializeClient`, you'll need to set the defaultPollInterval in the entry class(XXManager).
137+
```java
138+
ContainerAppsApiManager manager = ContainerAppsApiManager
139+
.configure()
140+
.withDefaultPollInterval(ResourceManagerUtils.InternalRuntimeContext.getDelayDuration(Duration.ofSeconds(30)))
141+
.withHttpClient(httpPipeline.getHttpClient())
142+
.authenticate(new DefaultAzureCredentialBuilder().build(), profile);
143+
144+
// instead of ContainerAppsApiManager.authenticate(httpPipeline, profile);
145+
```
146+
29147
## Troubleshooting
30148

31-
## Next steps
149+
### Common Issues
150+
151+
**Authentication Errors in Live/Record Mode**
152+
- Ensure you have run `az login` and have valid Azure credentials
153+
- Verify that `AZURE_TENANT_ID` and `AZURE_SUBSCRIPTION_ID` environment variables are set
154+
- Check that your account has sufficient permissions in the target subscription
155+
156+
**Recording Issues**
157+
- Recordings may contain secrets if sanitizers are not properly configured
158+
159+
**Resource Naming Conflicts**
160+
- Use `generateRandomResourceName()` to ensure unique resource names
161+
- Be aware that some Azure resources require globally unique names
162+
- Clean up resources properly in `cleanUpResources()` to avoid conflicts
163+
164+
### Debug Options
165+
166+
Enable detailed HTTP logging by setting the `AZURE_TEST_LOG_LEVEL` environment variable:
167+
```bash
168+
export AZURE_TEST_LOG_LEVEL=BODY_AND_HEADERS
169+
```
32170

33171
## Contributing
34172

sdk/resourcemanager/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ parameters:
170170
displayName: 'azure-resourcemanager-trafficmanager'
171171
type: boolean
172172
default: true
173+
- name: release_azureresourcemanagertest
174+
displayName: 'azure-resourcemanager-test'
175+
type: boolean
176+
default: false
173177

174178
extends:
175179
template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
@@ -268,14 +272,15 @@ extends:
268272
groupId: com.azure.resourcemanager
269273
safeName: azureresourcemanagertrafficmanager
270274
releaseInBatch: ${{ parameters.release_azureresourcemanagertrafficmanager }}
275+
- name: azure-resourcemanager-test
276+
groupId: com.azure.resourcemanager
277+
safeName: azureresourcemanagertest
278+
releaseInBatch: ${{ parameters.release_azureresourcemanagertest }}
271279
AdditionalModules:
272280
- name: azure-resourcemanager-samples
273281
groupId: com.azure.resourcemanager
274282
safeName: azureresourcemanagersamples
275283
- name: azure-resourcemanager-perf
276284
groupId: com.azure.resourcemanager
277-
- name: azure-resourcemanager-test
278-
groupId: com.azure.resourcemanager
279-
# required by the above perf library
280285
- name: perf-test-core
281286
groupId: com.azure

0 commit comments

Comments
 (0)