-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a handling for the null case when flattening over the map of sett…
…ings, for example when initial_recovery = null after copying or recovering an index (#3308) * Add a handling for the null case when flattening over the map of settings, for example when initial_recovery = null after copying or recovering an index * add tests for null edge case of the Maps class flatten function * formatting new MapsTest file
- Loading branch information
1 parent
c64d2ea
commit 9c7e011
Showing
2 changed files
with
59 additions
and
0 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
58 changes: 58 additions & 0 deletions
58
elastic4s-domain/src/test/scala/com/sksamuel/elastic4s/MapsTest.scala
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,58 @@ | ||
package com.sksamuel.elastic4s | ||
|
||
import com.sksamuel.elastic4s.ext.Maps | ||
import org.scalatest | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class MapsTest extends scalatest.flatspec.AnyFlatSpec with Matchers { | ||
"Maps flatten function" should "support null values" in { | ||
val jsonMap: Map[String, Any] = Map( | ||
"settings" -> Map( | ||
"index" -> Map( | ||
"routing" -> Map( | ||
"allocation" -> Map( | ||
"include" -> Map( | ||
"_tier_preference" -> "data_content" | ||
), | ||
"initial_recovery" -> Map( | ||
"_id" -> null | ||
) | ||
) | ||
), | ||
"number_of_shards" -> "1", | ||
"routing_partition_size" -> "1", | ||
"blocks" -> Map( | ||
"write" -> "true" | ||
), | ||
"provided_name" -> "test-two", | ||
"resize" -> Map( | ||
"source" -> Map( | ||
"name" -> "test-index", | ||
"uuid" -> "1234" | ||
) | ||
), | ||
"creation_date" -> "1234", | ||
"number_of_replicas" -> "1", | ||
"uuid" -> "1234", | ||
"version" -> Map( | ||
"created" -> "1234" | ||
) | ||
) | ||
) | ||
) | ||
Maps.flatten(jsonMap) shouldBe Map( | ||
"settings.index.resize.source.name" -> "test-index", | ||
"settings.index.resize.source.uuid" -> "1234", | ||
"settings.index.provided_name" -> "test-two", | ||
"settings.index.blocks.write" -> "true", | ||
"settings.index.routing_partition_size" -> "1", | ||
"settings.index.routing.allocation.include._tier_preference" -> "data_content", | ||
"settings.index.routing.allocation.initial_recovery._id" -> null, | ||
"settings.index.number_of_replicas" -> "1", | ||
"settings.index.version.created" -> "1234", | ||
"settings.index.number_of_shards" -> "1", | ||
"settings.index.creation_date" -> "1234", | ||
"settings.index.uuid" -> "1234" | ||
) | ||
} | ||
} |