Skip to content

Commit 920a59a

Browse files
authored
mgmt, postgresqlhsc, add live tests (Azure#37290)
mgmt, postgresqlhsc, add live tests
1 parent 406f478 commit 920a59a

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
<version>1.10.4</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
7070
<scope>test</scope>
7171
</dependency>
72+
<dependency>
73+
<groupId>com.azure.resourcemanager</groupId>
74+
<artifactId>azure-resourcemanager-resources</artifactId>
75+
<version>2.31.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
76+
<scope>test</scope>
77+
</dependency>
7278
<dependency>
7379
<groupId>org.junit.jupiter</groupId>
7480
<artifactId>junit-jupiter-api</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.cosmosdbforpostgresql;
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.cosmosdbforpostgresql.models.Cluster;
18+
import com.azure.resourcemanager.cosmosdbforpostgresql.models.MaintenanceWindow;
19+
import com.azure.resourcemanager.resources.ResourceManager;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.util.Random;
24+
25+
public class CosmosDBForPostgreSqlManagerTests extends TestBase {
26+
private static final Random RANDOM = new Random();
27+
private static final Region REGION = Region.US_EAST;
28+
private String resourceGroupName = "rg" + randomPadding();
29+
private CosmosDBForPostgreSqlManager cosmosDBForPostgreSqlManager;
30+
private ResourceManager resourceManager;
31+
private boolean testEnv;
32+
33+
@Override
34+
public void beforeTest() {
35+
final TokenCredential credential = new DefaultAzureCredentialBuilder().build();
36+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
37+
38+
cosmosDBForPostgreSqlManager = CosmosDBForPostgreSqlManager
39+
.configure()
40+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
41+
.authenticate(credential, profile);
42+
43+
resourceManager = ResourceManager
44+
.configure()
45+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
46+
.authenticate(credential, profile)
47+
.withDefaultSubscription();
48+
49+
// use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI
50+
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
51+
testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
52+
if (testEnv) {
53+
resourceGroupName = testResourceGroup;
54+
} else {
55+
resourceManager.resourceGroups()
56+
.define(resourceGroupName)
57+
.withRegion(REGION)
58+
.create();
59+
}
60+
}
61+
62+
@Override
63+
protected void afterTest() {
64+
if (!testEnv) {
65+
resourceManager.resourceGroups().beginDeleteByName(resourceGroupName);
66+
}
67+
}
68+
69+
@Test
70+
@DoNotRecord(skipInPlayback = true)
71+
public void testCreateCluster() {
72+
Cluster cluster = null;
73+
String randomPadding = randomPadding();
74+
try {
75+
String clusterName = "cluster" + randomPadding;
76+
String adminPwd = "Pass@" + randomPadding;
77+
// @embedmeStart
78+
cluster = cosmosDBForPostgreSqlManager
79+
.clusters()
80+
.define(clusterName)
81+
.withRegion(REGION)
82+
.withExistingResourceGroup(resourceGroupName)
83+
.withAdministratorLoginPassword(adminPwd)
84+
.withPostgresqlVersion("15")
85+
.withCitusVersion("12.1")
86+
.withMaintenanceWindow(new MaintenanceWindow()
87+
.withCustomWindow("Disabled")
88+
.withDayOfWeek(0)
89+
.withStartHour(0)
90+
.withStartMinute(0))
91+
.withEnableShardsOnCoordinator(true)
92+
.withEnableHa(false)
93+
.withCoordinatorServerEdition("GeneralPurpose")
94+
.withNodeServerEdition("MemoryOptimized")
95+
.withCoordinatorStorageQuotaInMb(131072)
96+
.withNodeStorageQuotaInMb(524288)
97+
.withCoordinatorVCores(2)
98+
.withNodeVCores(4)
99+
.withCoordinatorEnablePublicIpAccess(true)
100+
.withNodeEnablePublicIpAccess(true)
101+
.withNodeCount(0)
102+
.create();
103+
// @embedmeEnd
104+
cluster.refresh();
105+
Assertions.assertEquals(cluster.name(), clusterName);
106+
Assertions.assertEquals(cluster.name(), cosmosDBForPostgreSqlManager.clusters().getById(cluster.id()).name());
107+
Assertions.assertTrue(cosmosDBForPostgreSqlManager.clusters().list().stream().findAny().isPresent());
108+
} finally {
109+
if (cluster != null) {
110+
cosmosDBForPostgreSqlManager.clusters().deleteById(cluster.id());
111+
}
112+
}
113+
}
114+
115+
private static String randomPadding() {
116+
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
117+
}
118+
}
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
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: cosmosdbforpostgresql
9+
Artifacts:
10+
- name: azure-resourcemanager-cosmosdbforpostgresql
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagercosmosdbforpostgresql
13+
Clouds: 'Public'
14+
# Only run tests on Windows to save cost.
15+
MatrixFilters:
16+
- pool=.*(win).*

0 commit comments

Comments
 (0)