Skip to content

Commit 7c698d1

Browse files
committed
chore: case-insenstive header checks for integration tests
1 parent 8f3da9d commit 7c698d1

File tree

12 files changed

+35
-21
lines changed

12 files changed

+35
-21
lines changed

integration_test/binary_models/binary_models_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response based on path and status
56
def response = respond().withStatusCode(Integer.parseInt(responseStatus))

integration_test/boolean_schemas/boolean_schemas_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import groovy.json.JsonSlurper
22
import groovy.json.JsonOutput
33

44
// Get the response status from the request header
5-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
5+
def headers = context.request.headers
6+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
67

78
// Set the response status code
89
def response = respond()

integration_test/fastify_type_provider_zod/fastify_type_provider_zod_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
respond()

integration_test/gov/gov_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
respond()

integration_test/inference/inference_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34
def statusCode = Integer.parseInt(responseStatus)
45
def path = context.request.path
56
def method = context.request.method

integration_test/medama/medama_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34
def statusCode = Integer.parseInt(responseStatus)
45

56
// Add required headers based on endpoint and status code

integration_test/music_streaming/music_streaming_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
respond()
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
1+
// Get the response status from the request header (case-insensitive for Windows compatibility)
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
def response = respond()
67
.withStatusCode(Integer.parseInt(responseStatus))
8+
.usingDefaultBehaviour()
79

10+
// Override specific endpoints that need custom responses (without resetting default behavior)
811
if (context.request.path == '/api/v3/user/login' && responseStatus == '200') {
912
// For login endpoint with 200 status, return a properly formatted JSON string
10-
response.withHeader('Content-Type', 'application/json')
11-
.withContent('"example return value"')
13+
response = respond()
14+
.withStatusCode(Integer.parseInt(responseStatus))
15+
.withHeader('Content-Type', 'application/json')
16+
.withContent('"example return value"')
1217

1318
} else if (context.request.path.matches('/api/v3/pet/\\d+/health') && responseStatus == '200') {
1419
// For pet health endpoint with 200 status, return RFC 7807 Problem Details JSON
1520
def petId = context.request.path.replaceAll('.*/pet/(\\d+)/health', '$1')
16-
response.withHeader('Content-Type', 'application/problem+json')
17-
.withContent("""
21+
response = respond()
22+
.withStatusCode(Integer.parseInt(responseStatus))
23+
.withHeader('Content-Type', 'application/problem+json')
24+
.withContent("""
1825
{
1926
"type": "https://example.com/probs/pet-health",
2027
"title": "Pet Health Report",
@@ -24,8 +31,4 @@ if (context.request.path == '/api/v3/user/login' && responseStatus == '200') {
2431
"healthStatus": "healthy"
2532
}
2633
""".trim())
27-
28-
} else {
29-
// For all other cases, use default behavior
30-
response.usingDefaultBehaviour()
3134
}

integration_test/petstore_config/petstore_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
def response = respond()

integration_test/query_parameters/query_parameters_test/imposter/response.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Get the response status from the request header
2-
def responseStatus = context.request.headers['X-Response-Status'] ?: '200'
2+
def headers = context.request.headers
3+
def responseStatus = headers['X-Response-Status'] ?: headers['x-response-status'] ?: '200'
34

45
// Set the response status code and use the OpenAPI specification
56
respond()

0 commit comments

Comments
 (0)