Skip to content

Commit

Permalink
Fix Integ test for datasource enabled setting with security plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <[email protected]>
  • Loading branch information
vamsi-amazon committed Jul 29, 2024
1 parent a5ede64 commit ef5814b
Showing 1 changed file with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.sql.datasource;

import static org.opensearch.sql.legacy.TestUtils.getResponseBody;
import static org.opensearch.sql.legacy.TestsConstants.DATASOURCES;

import lombok.SneakyThrows;
import org.json.JSONObject;
Expand All @@ -25,31 +24,25 @@ protected boolean preserveClusterUponCompletion() {
}

@Test
public void testDataSourceIndexIsCreatedByDefault() {
assertDataSourceCount(0);
assertSelectFromDataSourceReturnsDoesNotExist();
assertDataSourceIndexCreated(true);
}

@Test
public void testDataSourceIndexIsCreatedIfSettingIsEnabled() {
setDataSourcesEnabled("transient", true);
public void testAsyncQueryAPIFailureIfSettingIsDisabled() {
setDataSourcesEnabled("transient", false);
assertDataSourceCount(0);
assertSelectFromDataSourceReturnsDoesNotExist();
assertDataSourceIndexCreated(true);
assertAsyncQueryApiDisabled();
}

@Test
public void testDataSourceIndexIsNotCreatedIfSettingIsDisabled() {
setDataSourcesEnabled("transient", false);
assertDataSourceCount(0);
assertSelectFromDataSourceReturnsDoesNotExist();
assertDataSourceIndexCreated(false);
assertAsyncQueryApiDisabled();
public void testDataSourceCreationWithDefaultSettings() {
createOpenSearchDataSource();
createIndex();
assertDataSourceCount(1);
assertSelectFromDataSourceReturnsSuccess();
assertSelectFromDummyIndexInValidDataSourceDataSourceReturnsDoesNotExist();
}

@Test
public void testAfterPreviousEnable() {
setDataSourcesEnabled("transient", true);
createOpenSearchDataSource();
createIndex();
assertDataSourceCount(1);
Expand Down Expand Up @@ -141,18 +134,6 @@ private void assertDataSourceCount(int expected) {
Assert.assertEquals(expected, jsonBody.getJSONArray("datarows").length());
}

@SneakyThrows
private void assertDataSourceIndexCreated(boolean expected) {
Request request = new Request("GET", "/" + DATASOURCES);
Response response = performRequest(request);
String responseBody = getResponseBody(response);
boolean indexDoesExist =
response.getStatusLine().getStatusCode() == 200
&& responseBody.contains(DATASOURCES)
&& responseBody.contains("mappings");
Assert.assertEquals(expected, indexDoesExist);
}

@SneakyThrows
private Response performRequest(Request request) {
try {
Expand Down

0 comments on commit ef5814b

Please sign in to comment.