Skip to content

Commit 41353eb

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

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.opensearch.action.search.SearchResponse;
1616
import org.opensearch.client.Response;
1717
import org.opensearch.client.ResponseException;
18+
import org.opensearch.core.rest.RestStatus;
1819
import org.opensearch.rest.RestRequest;
1920

2021
public class RestMLModelTenantAwareIT extends MLCommonsTenantAwareRestTestCase {
@@ -32,7 +33,14 @@ public void testModelCRUD() throws Exception {
3233
Map<String, Object> map = responseToMap(response);
3334
assertTrue(map.containsKey(CONNECTOR_ID));
3435
String connectorId = map.get(CONNECTOR_ID).toString();
35-
// Create a second connector from other tenant
36+
// Create a second connector with same tenant for deletion tests later
37+
response = makeRequest(createConnectorRequest, POST, CONNECTORS_PATH + "_create");
38+
assertOK(response);
39+
map = responseToMap(response);
40+
assertTrue(map.containsKey(CONNECTOR_ID));
41+
String secondConnectorId = map.get(CONNECTOR_ID).toString();
42+
43+
// Create a third connector from other tenant
3644
createConnectorRequest = getRestRequestWithHeadersAndContent(otherTenantId, COHERE_CONNECTOR_BLUEPRINT);
3745
response = makeRequest(createConnectorRequest, POST, CONNECTORS_PATH + "_create");
3846
assertOK(response);
@@ -308,6 +316,17 @@ public void testModelCRUD() throws Exception {
308316
assertEquals(MISSING_TENANT_REASON, getErrorReasonFromResponseMap(map));
309317
}
310318

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

322341
// Verify the deletion
323-
ResponseException ex = assertThrows(ResponseException.class, () -> makeRequest(tenantRequest, GET, MODELS_PATH + modelId));
342+
ex = assertThrows(ResponseException.class, () -> makeRequest(tenantRequest, GET, MODELS_PATH + modelId));
324343
response = ex.getResponse();
325344
assertNotFound(response);
326345
map = responseToMap(response);

0 commit comments

Comments
 (0)