Skip to content

Commit

Permalink
test on one resource group (#8469)
Browse files Browse the repository at this point in the history
* add minimum set of json
  • Loading branch information
sima-zhu authored Feb 26, 2020
1 parent d425efd commit 057090e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,21 @@ public abstract class SearchServiceTestBase extends TestBase {
@BeforeAll
public static void beforeAll() {
initializeAzureResources();
if (!playbackMode()) {
azureSearchResources.initialize();
azureSearchResources.createResourceGroup();
}
}

@AfterAll
public static void afterAll() {
azureSearchResources.deleteResourceGroup();
}

@Override
protected void beforeTest() {
searchDnsSuffix = testEnvironment.equals("DOGFOOD") ? DOGFOOD_DNS_SUFFIX : DEFAULT_DNS_SUFFIX;

if (!interceptorManager.isPlaybackMode()) {
azureSearchResources.initialize();
azureSearchResources.createResourceGroup(testResourceNamer);
azureSearchResources.createService(testResourceNamer);
searchApiKeyCredential = new SearchApiKeyCredential(azureSearchResources.getSearchAdminKey());
}
Expand Down Expand Up @@ -640,6 +641,10 @@ static boolean liveMode() {
return setupTestMode() == TestMode.LIVE;
}

static boolean playbackMode() {
return setupTestMode() == TestMode.PLAYBACK;
}

static TestMode setupTestMode() {
String testMode = Configuration.getGlobalConfiguration().get(AZURE_TEST_MODE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.search.test.environment.setup;

import com.azure.core.test.utils.TestResourceNamer;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
Expand All @@ -22,6 +23,7 @@ public class AzureSearchResources {
private static final String SEARCH_SERVICE_NAME_PREFIX = "azs-sdk";
private static final String BLOB_DATASOURCE_NAME_PREFIX = "azsblob";
private static final String STORAGE_NAME_PREFIX = "azsstor";
private static final String AZURE_RESOURCEGROUP_NAME = "AZURE_RESOURCEGROUP_NAME";


private String searchServiceName;
Expand All @@ -32,7 +34,7 @@ public class AzureSearchResources {
private Region location;

private Azure azure = null;
private ResourceGroup resourceGroup = null;
private static ResourceGroup resourceGroup;
private SearchService searchService = null;

/**
Expand Down Expand Up @@ -113,9 +115,13 @@ public void deleteService() {
/**
* Creates the Resource Group in Azure. This should be run at @BeforeAll
*/
public void createResourceGroup(TestResourceNamer testResourceNamer) {
if (resourceGroup == null) {
String resourceGroupName = testResourceNamer.randomName(RESOURCE_GROUP_NAME_PREFIX, 24);
public void createResourceGroup() {
String resourceGroupName = Configuration.getGlobalConfiguration().get(AZURE_RESOURCEGROUP_NAME);
if (azure.resourceGroups().checkExistence(resourceGroupName)) {
System.out.println("Fetching Resource Group: " + resourceGroupName);
resourceGroup = azure.resourceGroups()
.getByName(resourceGroupName);
} else {
System.out.println("Creating Resource Group: " + resourceGroupName);
resourceGroup = azure.resourceGroups()
.define(resourceGroupName)
Expand Down
8 changes: 8 additions & 0 deletions sdk/search/test-resources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
}

0 comments on commit 057090e

Please sign in to comment.