Skip to content

Commit

Permalink
Add integ test
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jul 8, 2024
1 parent 5c466f7 commit f3e7606
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:
types: [opened, synchronize, reopened]

env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
Get-CI-Image-Tag:
uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,25 @@ protected Response updateWorkflow(RestClient client, String workflowId, Template
);
}

/**
* Helper method to invoke the Update Workflow API
* @param client the rest client
* @param workflowId the document id
* @param templateFields the JSON containing some template fields
* @throws Exception if the request fails
* @return a rest response
*/
protected Response updateWorkflowWithFields(RestClient client, String workflowId, String templateFields) throws Exception {
return TestHelpers.makeRequest(
client,
"PUT",
String.format(Locale.ROOT, "%s/%s?update_fields=true", WORKFLOW_URI, workflowId),
Collections.emptyMap(),
templateFields,
null
);
}

/**
* Helper method to invoke the Provision Workflow Rest Action
* @param client the rest client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,45 @@ public void testFailedUpdateWorkflow() throws Exception {
assertTrue(
exceptionProvisioned.getMessage().contains("The template can not be updated unless its provisioning state is NOT_STARTED")
);
}

public void testUpdateWorkflowUsingFields() throws Exception {
Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json");
Response response = createWorkflow(client(), template);
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

Map<String, Object> responseMap = entityAsMap(response);
String workflowId = (String) responseMap.get(WORKFLOW_ID);

// Ensure Ml config index is initialized as creating a connector requires this, then hit Provision API and assert status
Response provisionResponse;
if (!indexExistsWithAdminClient(".plugins-ml-config")) {
assertBusy(() -> assertTrue(indexExistsWithAdminClient(".plugins-ml-config")), 40, TimeUnit.SECONDS);
provisionResponse = provisionWorkflow(client(), workflowId);
} else {
provisionResponse = provisionWorkflow(client(), workflowId);
}
assertEquals(RestStatus.OK, TestHelpers.restStatus(provisionResponse));
getAndAssertWorkflowStatus(client(), workflowId, State.PROVISIONING, ProvisioningProgress.IN_PROGRESS);

// Attempt to update with update_fields with illegal field
// Fails because contains workflow field
ResponseException exceptionProvisioned = expectThrows(
ResponseException.class,
() -> updateWorkflowWithFields(client(), workflowId, "{\"workflows\":{}}")
);
assertTrue(
exceptionProvisioned.getMessage().contains("You can not update the field [workflows] without updating the whole template.")
);
// Change just the name and description
response = updateWorkflowWithFields(client(), workflowId, "{\"name\":\"foo\",\"description\":\"bar\"}");
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));
// Get the updated template
response = getWorkflow(client(), workflowId);
assertEquals(RestStatus.OK.getStatus(), response.getStatusLine().getStatusCode());
Template t = Template.parse(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
assertEquals("foo", t.name());
assertEquals("bar", t.description());
}

public void testCreateAndProvisionLocalModelWorkflow() throws Exception {
Expand Down

0 comments on commit f3e7606

Please sign in to comment.