Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rafal Augustyniak <[email protected]>
  • Loading branch information
Augustyniak committed Jul 5, 2022
1 parent 9e2cbbb commit 363fa4f
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions test/kotlin/io/envoyproxy/envoymobile/HeadersContainerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,70 @@ class HeadersContainerest {
}

@Test
fun `instantiation with mutable list of values is case insensitive, preserves casing and processes in alphabetical order`() {
fun `instantiation with mutable list of values is case-insensitive, preserves casing and processes in alphabetical order`() {
val container = HeadersContainer(mapOf("a" to mutableListOf<String>("456"), "A" to mutableListOf<String>("123")))
assertThat(container.caseSensitiveHeaders()).isEqualTo(mapOf("A" to listOf("123", "456")))
}

@Test
fun `creation with immutable list of values is case insensitive, preserves casing and processes in alphabetical order`() {
fun `creation with immutable list of values is case-insensitive, preserves casing and processes in alphabetical order`() {
val container = HeadersContainer.create(mapOf("a" to listOf<String>("456"), "A" to listOf<String>("123")))
assertThat(container.caseSensitiveHeaders()).isEqualTo(mapOf("A" to listOf("123", "456")))
}

@Test
fun `adding header adds to list of header keys`() {
fun `adding header adds to list of headers keys`() {
val container = HeadersContainer(mutableMapOf())
container.add("x-foo", "1")
container.add("x-foo", "2")
assertThat(container.value("x-foo")).containsExactly("1", "2")
}

@Test
fun `adding header is case insensitive and preserves header name casing`() {
fun `adding header performs a case-insensitive header lookup and preserves header name casing`() {
val container = HeadersContainer(mapOf())
container.add("x-FOO", "1")
container.add("x-foo", "2")

assertThat(container.value("x-foo")).isEqualTo(listOf("1", "2"))
assertThat(container.caseSensitiveHeaders()).isEqualTo(mapOf("x-FOO" to listOf("1", "2")))
}

@Test
fun `setting header adds to list of headers keys`() {
val container = HeadersContainer(mapOf())
container.set("x-foo", mutableListOf("abc"))

assertThat( container.value("x-foo")).isEqualTo(listOf("abc"))
}

@Test
fun `setting header overrides previous header values`() {
val container = HeadersContainer(mapOf())
container.add("x-FOO", "1")
container.add("x-foo", "2")
container.set("x-foo", mutableListOf("3"))

assertThat(container.value("x-foo")).isEqualTo(listOf("3"))
}

@Test
fun `removing header removes all of its values`() {
val container = HeadersContainer(mapOf())
container.add("x-foo", "1")
container.add("x-foo", "2")
container.remove("x-foo")

assertThat(container.value("x-foo")).isNull()
}

@Test
fun `removing header performs case-insensitive header name lookup`() {
val container = HeadersContainer(mapOf())
container.add("x-FOO", "1")
container.add("x-foo", "2")
container.remove("x-fOo")

assertThat(container.value("x-foo")).isNull()
}
}

0 comments on commit 363fa4f

Please sign in to comment.