From 8f17c16556a2b08412cacbea480fdccc54b6f5ae Mon Sep 17 00:00:00 2001 From: Sanjay Kumar Date: Tue, 23 Apr 2024 15:37:46 +0530 Subject: [PATCH] rebased commit Signed-off-by: Sanjay Kumar --- .../integ/rest/UpdateAutoFollowPatternIT.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt index 78e4ead4..d9de9341 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt @@ -456,6 +456,50 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() { fun getIndexReplicationTasks(clusterName: String): List { return getReplicationTaskList(clusterName, IndexReplicationExecutor.TASK_NAME + "*") } + fun `test auto follow should fail on indexPattern validation failure`() { + val followerClient = getClientForCluster(FOLLOWER) + createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias) + assertPatternValidation(followerClient, "testPattern,", + "Autofollow pattern: testPattern, must not contain the following characters") + assertPatternValidation(followerClient, "testPat?", + "Autofollow pattern: testPat? must not contain the following characters") + assertPatternValidation(followerClient, "test#", + "Autofollow pattern: test# must not contain '#' or ':'") + assertPatternValidation(followerClient, "test:", + "Autofollow pattern: test: must not contain '#' or ':'") + assertPatternValidation(followerClient, "_test", + "Autofollow pattern: _test must not start with '_' or '-'") + assertPatternValidation(followerClient, "-leader", + "Autofollow pattern: -leader must not start with '_' or '-'") + assertPatternValidation(followerClient, "", + "Autofollow pattern: must not be empty") + + } + private fun assertPatternValidation(followerClient: RestHighLevelClient, pattern: String, + errorMsg: String) { + Assertions.assertThatThrownBy { + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern) + }.isInstanceOf(ResponseException::class.java) + .hasMessageContaining(errorMsg) + } + + fun `test auto follow should succeed on valid indexPatterns`() { + val followerClient = getClientForCluster(FOLLOWER) + createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias) + assertValidPatternValidation(followerClient, "test-leader") + assertValidPatternValidation(followerClient, "test*") + assertValidPatternValidation(followerClient, "leader-*") + assertValidPatternValidation(followerClient, "leader_test") + assertValidPatternValidation(followerClient, "Leader_Test-*") + assertValidPatternValidation(followerClient, "Leader_*") + + } + + private fun assertValidPatternValidation(followerClient: RestHighLevelClient, pattern: String) { + Assertions.assertThatCode { + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern) + }.doesNotThrowAnyException() + } fun createDummyConnection(fromClusterName: String, connectionName: String="source") { val fromCluster = getNamedCluster(fromClusterName)