Skip to content

Commit

Permalink
Validate resolvedHost from httpRequestTests (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jun 6, 2024
1 parent cf9d6fe commit 78cb9a8
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ private void writeHttpRequestAssertions(HttpRequestTestCase testCase) {

writeHttpHeaderAssertions(testCase);
writeHttpQueryAssertions(testCase);
writeHttpHostAssertion(testCase);
testCase.getBody().ifPresent(body -> {
writeHttpBodyAssertions(body, testCase.getBodyMediaType().orElse("UNKNOWN"), true);
});
Expand Down Expand Up @@ -521,6 +522,14 @@ private void writeHttpHeaderAssertions(HttpMessageTestCase testCase) {
writer.write("");
}

private void writeHttpHostAssertion(HttpRequestTestCase testCase) {
testCase.getResolvedHost().ifPresent(resolvedHost -> {
writer.write("expect(r.headers[\"host\"]).toBeDefined();");
writer.write("expect(r.headers[\"host\"]).toBe($S);", resolvedHost);
writer.write("");
});
}

private void writeHttpBodyAssertions(String body, String mediaType, boolean isClientTest) {
// If we expect an empty body, expect it to be falsy.
if (body.isEmpty()) {
Expand Down

0 comments on commit 78cb9a8

Please sign in to comment.