Skip to content

Commit

Permalink
Fix to how tests load extra headers from config
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed Oct 31, 2024
1 parent 0397657 commit 9e09638
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ data class HttpHeadersPattern(
.filter { exampleHeaderName -> !specPattern.containsKey(exampleHeaderName) && !specPattern.containsKey("${exampleHeaderName}?") }
.filter { exampleHeaderName -> exampleHeaderName.lowercase() !in getHeadersToExcludeNotInExamples(row.requestExample) }
.filter { exampleHeaderName -> exampleHeaderName !in row.requestExample.metadata.securityHeaderNames }
.associateWith { StringPattern() }
.associateWith { exampleHeaderName -> ExactValuePattern(StringValue(row.requestExample.headers.getValue(exampleHeaderName))) }
} else {
emptyMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ components:

val results = feature.executeTests(object : TestExecutor {
override fun execute(request: HttpRequest): HttpResponse {
assertThat(request.headers).containsEntry("Authenticate", "abc123")
return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also {
println(request.toLogString())
println(it.toLogString())
Expand All @@ -366,6 +367,7 @@ components:

val results = feature.executeTests(object : TestExecutor {
override fun execute(request: HttpRequest): HttpResponse {
assertThat(request.headers).containsEntry("Authenticate", "abc123")
return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also {
println(request.toLogString())
println(it.toLogString())
Expand All @@ -386,6 +388,7 @@ components:

val results = feature.executeTests(object : TestExecutor {
override fun execute(request: HttpRequest): HttpResponse {
assertThat(request.headers).containsEntry("Authenticate", "abc123")
return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also {
println(request.toLogString())
println(it.toLogString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.specmatic.conversions

import io.specmatic.core.HttpHeadersPattern
import io.specmatic.core.NoBodyValue
import io.specmatic.core.Resolver
import io.specmatic.core.SpecmaticConfig
import io.specmatic.core.pattern.parsedJSONObject
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -135,5 +137,8 @@ class ExampleFromFileTest {
example.toRow(SpecmaticConfig(additionalExampleParamsFilePath = "src/test/resources/additionalParamsFile.json"))

assertThat(row.requestExample?.headers.orEmpty()).containsEntry("X-Tra", "info")

val generatedHeaders = HttpHeadersPattern().newBasedOn(row, Resolver()).first().value.generate(Resolver())
assertThat(generatedHeaders).containsEntry("X-Tra", "info")
}
}

0 comments on commit 9e09638

Please sign in to comment.