Skip to content

Commit

Permalink
Fixed tests for ExplainRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Au <[email protected]>
  • Loading branch information
Joshua152 committed Oct 11, 2023
1 parent 828f8d2 commit cae9460
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ data class ExplainFilter(

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
filterPolicyID = sin.readString(),
filterState = sin.readString(),
filterAction = sin.readString()
filterPolicyID = sin.readOptionalString(),
filterState = sin.readOptionalString(),
filterAction = sin.readOptionalString()
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(filterPolicyID)
out.writeString(filterState)
out.writeString(filterAction)
out.writeOptionalString(filterPolicyID)
out.writeOptionalString(filterState)
out.writeOptionalString(filterAction)
}

fun isValid(managedIndexConfig: ManagedIndexConfig): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.opensearch.common.io.stream.BytesStreamOutput
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.common.unit.TimeValue
import org.opensearch.indexmanagement.common.model.rest.SearchParams
import org.opensearch.indexmanagement.indexstatemanagement.model.ExplainFilter
import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE
import org.opensearch.test.OpenSearchTestCase

Expand All @@ -19,9 +20,10 @@ class ExplainRequestTests : OpenSearchTestCase() {
val local = true
val clusterManagerTimeout = TimeValue.timeValueSeconds(30)
val params = SearchParams(0, 20, "sort-field", "asc", "*")
val filter = ExplainFilter()
val showPolicy = false
val showValidationResult = false
val req = ExplainRequest(indices, local, clusterManagerTimeout, params, showPolicy, showValidationResult, DEFAULT_INDEX_TYPE)
val req = ExplainRequest(indices, local, clusterManagerTimeout, params, filter, showPolicy, showValidationResult, DEFAULT_INDEX_TYPE)

val out = BytesStreamOutput()
req.writeTo(out)
Expand All @@ -36,9 +38,10 @@ class ExplainRequestTests : OpenSearchTestCase() {
val local = true
val clusterManagerTimeout = TimeValue.timeValueSeconds(30)
val params = SearchParams(0, 20, "sort-field", "asc", "*")
val filter = ExplainFilter()
val showPolicy = false
val showValidationResult = false
val req = ExplainRequest(indices, local, clusterManagerTimeout, params, showPolicy, showValidationResult, "non-existent-index-type")
val req = ExplainRequest(indices, local, clusterManagerTimeout, params, filter, showPolicy, showValidationResult, "non-existent-index-type")

val actualException: String? = req.validate()?.validationErrors()?.firstOrNull()
val expectedException: String = ExplainRequest.MULTIPLE_INDICES_CUSTOM_INDEX_TYPE_ERROR
Expand Down

0 comments on commit cae9460

Please sign in to comment.