Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Integ test for datasource enabled setting with security plugin #2865

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading