Skip to content

Commit 98bf007

Browse files
committed
Add test for deleting connector not in a model
Signed-off-by: Daniel Widdis <[email protected]>
1 parent 90d56ca commit 98bf007

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

plugin/src/test/java/org/opensearch/ml/rest/RestMLModelTenantAwareIT.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static org.opensearch.ml.common.CommonValue.TENANT_ID_FIELD;
99
import static org.opensearch.ml.common.MLTask.MODEL_ID_FIELD;
10+
import static org.opensearch.ml.common.input.Constants.TENANT_ID_HEADER;
1011
import static org.opensearch.ml.rest.RestMLRAGSearchProcessorIT.COHERE_CONNECTOR_BLUEPRINT;
1112

1213
import java.util.Map;
@@ -15,6 +16,7 @@
1516
import org.opensearch.action.search.SearchResponse;
1617
import org.opensearch.client.Response;
1718
import org.opensearch.client.ResponseException;
19+
import org.opensearch.core.rest.RestStatus;
1820
import org.opensearch.rest.RestRequest;
1921

2022
public class RestMLModelTenantAwareIT extends MLCommonsTenantAwareRestTestCase {
@@ -32,7 +34,14 @@ public void testModelCRUD() throws Exception {
3234
Map<String, Object> map = responseToMap(response);
3335
assertTrue(map.containsKey(CONNECTOR_ID));
3436
String connectorId = map.get(CONNECTOR_ID).toString();
35-
// Create a second connector from other tenant
37+
// Create a second connector with same tenant for deletion tests later
38+
response = makeRequest(createConnectorRequest, POST, CONNECTORS_PATH + "_create");
39+
assertOK(response);
40+
map = responseToMap(response);
41+
assertTrue(map.containsKey(CONNECTOR_ID));
42+
String secondConnectorId = map.get(CONNECTOR_ID).toString();
43+
44+
// Create a third connector from other tenant
3645
createConnectorRequest = getRestRequestWithHeadersAndContent(otherTenantId, COHERE_CONNECTOR_BLUEPRINT);
3746
response = makeRequest(createConnectorRequest, POST, CONNECTORS_PATH + "_create");
3847
assertOK(response);
@@ -308,6 +317,17 @@ public void testModelCRUD() throws Exception {
308317
assertEquals(MISSING_TENANT_REASON, getErrorReasonFromResponseMap(map));
309318
}
310319

320+
// Try to delete connector while model exists
321+
ResponseException ex = assertThrows(
322+
ResponseException.class,
323+
() -> makeRequest(tenantRequest, DELETE, CONNECTORS_PATH + connectorId)
324+
);
325+
response = ex.getResponse();
326+
assertEquals(RestStatus.CONFLICT.getStatus(), response.getStatusLine().getStatusCode());
327+
// but it should work with the connector not in a model
328+
response = makeRequest(tenantRequest, DELETE, CONNECTORS_PATH + secondConnectorId);
329+
assertOK(response);
330+
311331
// Now actually do the deletions. Same result whether multi-tenancy is enabled.
312332
// Verify still exists
313333
response = makeRequest(tenantRequest, GET, MODELS_PATH + modelId);
@@ -320,7 +340,7 @@ public void testModelCRUD() throws Exception {
320340
assertEquals(modelId, map.get(DOC_ID).toString());
321341

322342
// Verify the deletion
323-
ResponseException ex = assertThrows(ResponseException.class, () -> makeRequest(tenantRequest, GET, MODELS_PATH + modelId));
343+
ex = assertThrows(ResponseException.class, () -> makeRequest(tenantRequest, GET, MODELS_PATH + modelId));
324344
response = ex.getResponse();
325345
assertNotFound(response);
326346
map = responseToMap(response);

0 commit comments

Comments
 (0)