Skip to content

Commit

Permalink
add integ test for lacking _meta field
Browse files Browse the repository at this point in the history
Signed-off-by: zhichao-aws <[email protected]>
  • Loading branch information
zhichao-aws committed Aug 7, 2023
1 parent c8faf09 commit db21335
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.opensearch.commons.notifications.model.Webhook
import org.opensearch.core.rest.RestStatus
import org.opensearch.integtest.PluginRestTestCase
import org.opensearch.notifications.NotificationPlugin.Companion.PLUGIN_BASE_URI
import org.opensearch.notifications.index.NotificationConfigIndex
import org.opensearch.notifications.verifySingleConfigEquals
import org.opensearch.rest.RestRequest

Expand Down Expand Up @@ -275,4 +276,61 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
createConfig()
Assert.assertEquals(1, getCurrentMappingsSchemaVersion())
}

fun `test _meta field not exists in current mappings`() {
val indexName = ".opensearch-notifications-config"
val deleteIndexRequest = Request(RestRequest.Method.DELETE.name, indexName)
try {
adminClient().performRequest(deleteIndexRequest)
} catch (e: ResponseException) {
/* ignore if the index has not been created */
assertEquals("Unexpected status", RestStatus.NOT_FOUND, RestStatus.fromCode(e.response.statusLine.statusCode))
}

val pseudoMappingString = """
{
"mappings": {
"dynamic": "false",
"properties": {
"config": {
"properties": {
"chime": {
"properties": {
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
""".trimIndent()
try {
executeRequest(
RestRequest.Method.PUT.name,
indexName,
pseudoMappingString,
RestStatus.OK.status
)
} catch (e: Exception) {
/* ignore warnings */
assert(e is WarningFailureException)
}

val getMappingRequest = Request(RestRequest.Method.GET.name, "$indexName/_mappings")
val responseBefore = executeRequest(getMappingRequest, RestStatus.OK.status, client())
val mappingsObjectBefore = responseBefore.get(indexName).asJsonObject.get("mappings").asJsonObject
Assert.assertNull("mappings should not have _meta field", mappingsObjectBefore.get(NotificationConfigIndex._META))
createConfig()
val responseAfter = executeRequest(getMappingRequest, RestStatus.OK.status, client())
val mappingsObjectAfter = responseAfter.get(indexName).asJsonObject.get("mappings").asJsonObject
Assert.assertEquals(mappingsObjectAfter, mappingsObjectBefore)
}
}

0 comments on commit db21335

Please sign in to comment.