Skip to content

Commit 5032c95

Browse files
authored
mgmt, redisenterprise, add live tests (Azure#35400)
mgmt, redisenterprise, add live tests
1 parent b3ddaea commit 5032c95

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

sdk/redisenterprise/azure-resourcemanager-redisenterprise/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
<artifactId>azure-core-management</artifactId>
5959
<version>1.11.2</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
6060
</dependency>
61+
<dependency>
62+
<groupId>com.azure.resourcemanager</groupId>
63+
<artifactId>azure-resourcemanager-resources</artifactId>
64+
<version>2.27.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
65+
<scope>test</scope>
66+
</dependency>
6167
<dependency>
6268
<groupId>com.azure</groupId>
6369
<artifactId>azure-core-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.redisenterprise;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.core.http.policy.HttpLogDetailLevel;
8+
import com.azure.core.http.policy.HttpLogOptions;
9+
import com.azure.core.management.AzureEnvironment;
10+
import com.azure.core.management.Region;
11+
import com.azure.core.management.profile.AzureProfile;
12+
import com.azure.core.test.TestBase;
13+
import com.azure.core.test.annotation.DoNotRecord;
14+
import com.azure.core.util.Configuration;
15+
import com.azure.core.util.CoreUtils;
16+
import com.azure.identity.DefaultAzureCredentialBuilder;
17+
import com.azure.resourcemanager.redisenterprise.models.*;
18+
import com.azure.resourcemanager.resources.ResourceManager;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.Random;
23+
24+
public class RedisEnterpriseManagerTests extends TestBase {
25+
private static final Random RANDOM = new Random();
26+
private static final Region REGION = Region.US_WEST2;
27+
private String resourceGroupName = "rg" + randomPadding();
28+
private RedisEnterpriseManager redisEnterpriseManager;
29+
private ResourceManager resourceManager;
30+
private boolean testEnv;
31+
32+
@Override
33+
public void beforeTest() {
34+
final TokenCredential credential = new DefaultAzureCredentialBuilder().build();
35+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
36+
37+
redisEnterpriseManager = RedisEnterpriseManager
38+
.configure()
39+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
40+
.authenticate(credential, profile);
41+
42+
resourceManager = ResourceManager
43+
.configure()
44+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
45+
.authenticate(credential, profile)
46+
.withDefaultSubscription();
47+
48+
// use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI
49+
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
50+
testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
51+
if (testEnv) {
52+
resourceGroupName = testResourceGroup;
53+
} else {
54+
resourceManager.resourceGroups()
55+
.define(resourceGroupName)
56+
.withRegion(REGION)
57+
.create();
58+
}
59+
}
60+
61+
@Override
62+
protected void afterTest() {
63+
if (!testEnv) {
64+
resourceManager.resourceGroups().beginDeleteByName(resourceGroupName);
65+
}
66+
}
67+
68+
@Test
69+
@DoNotRecord(skipInPlayback = true)
70+
public void testCreate() {
71+
Cluster cluster = null;
72+
try {
73+
String clusterName = "cluster" + randomPadding();
74+
// @embedmeStart
75+
cluster = redisEnterpriseManager.redisEnterprises()
76+
.define(clusterName)
77+
.withRegion(REGION)
78+
.withExistingResourceGroup(resourceGroupName)
79+
.withSku(new Sku().withName(SkuName.ENTERPRISE_E10).withCapacity(2))
80+
.withIdentity(new ManagedServiceIdentity().withType(ManagedServiceIdentityType.NONE))
81+
.withMinimumTlsVersion(TlsVersion.ONE_TWO)
82+
.create();
83+
// @embedmeEnd
84+
cluster.refresh();
85+
Assertions.assertEquals(cluster.name(), clusterName);
86+
Assertions.assertEquals(cluster.name(), redisEnterpriseManager.redisEnterprises().getById(cluster.id()).name());
87+
Assertions.assertTrue(redisEnterpriseManager.redisEnterprises().list().stream().count() > 0);
88+
} finally {
89+
if (cluster != null) {
90+
redisEnterpriseManager.redisEnterprises().deleteById(cluster.id());
91+
}
92+
}
93+
}
94+
95+
private static String randomPadding() {
96+
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
97+
}
98+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@description('The tenant id to which the application and resources belong.')
2+
param tenantId string = '72f988bf-86f1-41af-91ab-2d7cd011db47'
3+
4+
@description('The client id of the service principal used to run tests.')
5+
param testApplicationId string
6+
7+
@description('This is the object id of the service principal used to run tests.')
8+
param testApplicationOid string
9+
10+
@description('The application client secret used to run tests.')
11+
param testApplicationSecret string
12+
13+
var contributorRoleId = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c'
14+
15+
resource contributorRoleId_name 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
16+
name: guid('contributorRoleId${resourceGroup().name}')
17+
properties: {
18+
roleDefinitionId: contributorRoleId
19+
principalId: testApplicationOid
20+
}
21+
}
22+
23+
output AZURE_TENANT_ID string = tenantId
24+
output AZURE_CLIENT_ID string = testApplicationId
25+
output AZURE_CLIENT_SECRET string = testApplicationSecret
26+
output AZURE_SUBSCRIPTION_ID string = subscription().subscriptionId
27+
output AZURE_RESOURCE_GROUP_NAME string = resourceGroup().name

sdk/redisenterprise/tests.mgmt.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trigger: none
2+
3+
pr: none
4+
5+
stages:
6+
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
7+
parameters:
8+
ServiceDirectory: redisenterprise
9+
Artifacts:
10+
- name: azure-resourcemanager-redisenterprise
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagerredisenterprise
13+
Clouds: 'Public'
14+
# Only run tests on Windows to save cost.
15+
MatrixFilters:
16+
- pool=.*(win).*

0 commit comments

Comments
 (0)