Skip to content

Commit

Permalink
Add pattern to catAlias (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
KadekM authored Feb 12, 2021
1 parent a017389 commit 2b179e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ trait CatHandlers {
}

implicit object CatAliasesHandler extends Handler[CatAliases, Seq[CatAliasResponse]] {
override def build(request: CatAliases): ElasticRequest =
ElasticRequest("GET", "/_cat/aliases", Map("v" -> "", "format" -> "json"))
override def build(request: CatAliases): ElasticRequest = {
val endPoint = request.pattern match {
case Some(pattern) => s"/_cat/aliases/$pattern"
case _ => "/_cat/aliases"
}

ElasticRequest("GET", endPoint, Map("v" -> "", "format" -> "json"))
}
}

implicit object CatIndexesHandler extends Handler[CatIndexes, Seq[CatIndicesResponse]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.sksamuel.exts.OptionImplicits._

trait CatsApi {

def catAliases(): CatAliases = CatAliases()
def catAliases(): CatAliases = CatAliases(None)
def catAliases(pattern: String): CatAliases = CatAliases(pattern.some)

def catAllocation(): CatAllocation = CatAllocation()

def catCount(): CatCount = CatCount()
Expand Down Expand Up @@ -38,6 +40,6 @@ case class CatNodes()
case class CatHealth()
case class CatThreadPool()
case class CatAllocation()
case class CatAliases()
case class CatAliases(pattern: Option[String])
case class CatMaster()
case class CatIndexes(health: Option[HealthStatus], indexPattern: Option[String])
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CatAliasTest extends AnyFlatSpec with Matchers with DockerTests {
client.execute {
aliases(
addAlias("ally1", "catalias"),
addAlias("ally2", "catalias")
addAlias("ally2", "catalias"),
addAlias("ally22", "catalias")
)
}.await

Expand All @@ -25,4 +26,13 @@ class CatAliasTest extends AnyFlatSpec with Matchers with DockerTests {
result.result.map(_.alias).toSet.contains("ally1") shouldBe true
result.result.map(_.alias).toSet.contains("ally2") shouldBe true
}

it should "return aliases matching a pattern" in {
val result = client.execute {
catAliases("ally2*")
}.await
result.result.map(_.alias).toSet.contains("ally1") shouldBe false
result.result.map(_.alias).toSet.contains("ally2") shouldBe true
result.result.map(_.alias).toSet.contains("ally22") shouldBe true
}
}

0 comments on commit 2b179e7

Please sign in to comment.