forked from opensearch-project/index-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for mustache scripting of rollup.target_index field (op…
…ensearch-project#435) * tests * small refactor/improvements * added wildcard check when creating rollup job; removed resolving targetIndex on Rollup init; added test for wildcards * lint fixes * moved target_index validation in getRollup resp handler * removed catch block * exception fix * linter fix * fixed IT fail * added Exception catch block Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
- Loading branch information
Showing
6 changed files
with
204 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...lin/org/opensearch/indexmanagement/rollup/util/RollupFieldValueExpressionResolverTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.rollup.util | ||
|
||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.eq | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import com.nhaarman.mockitokotlin2.doReturn | ||
import org.junit.Before | ||
import org.opensearch.indexmanagement.rollup.randomRollup | ||
import org.opensearch.ingest.TestTemplateService | ||
import org.opensearch.script.ScriptService | ||
import org.opensearch.script.TemplateScript | ||
import org.opensearch.test.OpenSearchTestCase | ||
|
||
class RollupFieldValueExpressionResolverTests : OpenSearchTestCase() { | ||
|
||
private val scriptService: ScriptService = mock() | ||
|
||
@Before | ||
fun settings() { | ||
RollupFieldValueExpressionResolver.registerScriptService(scriptService) | ||
} | ||
|
||
fun `test resolving successfully`() { | ||
whenever(scriptService.compile(any(), eq(TemplateScript.CONTEXT))).doReturn(TestTemplateService.MockTemplateScript.Factory("test_index_123")) | ||
val rollup = randomRollup().copy(sourceIndex = "test_index_123", targetIndex = "{{ctx.source_index}}") | ||
val targetIndexResolvedName = RollupFieldValueExpressionResolver.resolve(rollup, rollup.targetIndex) | ||
assertEquals("test_index_123", targetIndexResolvedName) | ||
} | ||
|
||
fun `test resolving failed returned passed value`() { | ||
whenever(scriptService.compile(any(), eq(TemplateScript.CONTEXT))).doReturn(TestTemplateService.MockTemplateScript.Factory("")) | ||
val rollup = randomRollup().copy(sourceIndex = "test_index_123", targetIndex = "{{ctx.source_index}}") | ||
val targetIndexResolvedName = RollupFieldValueExpressionResolver.resolve(rollup, rollup.targetIndex) | ||
assertEquals("{{ctx.source_index}}", targetIndexResolvedName) | ||
} | ||
} |