Skip to content

Commit 28f1a93

Browse files
authored
mgmt, storagemover, add live tests (Azure#35561)
mgmt, storagemover, add live tests
1 parent 86b1b53 commit 28f1a93

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<artifactId>azure-core-management</artifactId>
5858
<version>1.11.2</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
5959
</dependency>
60+
<dependency>
61+
<groupId>com.azure.resourcemanager</groupId>
62+
<artifactId>azure-resourcemanager-resources</artifactId>
63+
<version>2.27.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
64+
<scope>test</scope>
65+
</dependency>
6066
<dependency>
6167
<groupId>com.azure</groupId>
6268
<artifactId>azure-core-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.storagemover;
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.resources.ResourceManager;
18+
import com.azure.resourcemanager.storagemover.models.StorageMover;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.Random;
23+
24+
public class StorageMoverManagerTests extends TestBase {
25+
private static final Random RANDOM = new Random();
26+
private static final Region REGION = Region.US_EAST2;
27+
private String resourceGroupName = "rg" + randomPadding();
28+
private StorageMoverManager storageMoverManager;
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+
storageMoverManager = StorageMoverManager
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 testCreateStorageMover() {
71+
StorageMover storageMover = null;
72+
try {
73+
String moveName = "move" + randomPadding();
74+
// @embedmeStart
75+
storageMover = storageMoverManager.storageMovers()
76+
.define(moveName)
77+
.withRegion(REGION)
78+
.withExistingResourceGroup(resourceGroupName)
79+
.create();
80+
// @embedmeEnd
81+
storageMover.refresh();
82+
Assertions.assertEquals(storageMover.name(), moveName);
83+
Assertions.assertEquals(storageMover.name(), storageMoverManager.storageMovers().getById(storageMover.id()).name());
84+
Assertions.assertTrue(storageMoverManager.storageMovers().list().stream().count() > 0);
85+
} finally {
86+
if (storageMover != null) {
87+
storageMoverManager.storageMovers().deleteById(storageMover.id());
88+
}
89+
}
90+
}
91+
92+
private static String randomPadding() {
93+
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
94+
}
95+
}
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/storagemover/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: storagemover
9+
Artifacts:
10+
- name: azure-resourcemanager-storagemover
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagerstoragemover
13+
Clouds: 'Public'
14+
# Only run tests on Windows to save cost.
15+
MatrixFilters:
16+
- pool=.*(win).*

0 commit comments

Comments
 (0)