Skip to content

Commit

Permalink
Add tests for httpResponseCode (#1241)
Browse files Browse the repository at this point in the history
Add tests for httpResponseCode

These tests ensure that
* @required and @httpResponseCode are correctly handled
* @http's code is used in place of @httpResponseCode when the latter is
  not used

They were not handled correctly in
smithy-lang/smithy-rs#1229.
  • Loading branch information
82marbag authored Jun 15, 2022
1 parent 5c319a2 commit 359fc17
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ structure HttpResponseCodeOutput {
Status: Integer
}

@http(method: "GET", uri: "/responseCodeRequired", code: 200)
operation ResponseCodeRequired {
output: ResponseCodeRequiredOutput,
}

@output
structure ResponseCodeRequiredOutput {
@required
@httpResponseCode
responseCode: Integer,
}

@http(method: "GET", uri: "/responseCodeHttpFallback", code: 201)
operation ResponseCodeHttpFallback {
input: ResponseCodeHttpFallbackInputOutput,
output: ResponseCodeHttpFallbackInputOutput,
}

structure ResponseCodeHttpFallbackInputOutput {}

apply HttpResponseCode @httpResponseTests([
{
id: "RestJsonHttpResponseCode",
Expand Down Expand Up @@ -73,3 +93,39 @@ apply HttpResponseCode @httpResponseTests([
appliesTo: "client"
},
])

apply ResponseCodeRequired @httpResponseTests([
{
id: "RestJsonHttpResponseCodeRequired",
documentation: """
This test ensures that servers handle @httpResponseCode being @required.""",
protocol: restJson1,
code: 201,
headers: {
"Content-Type": "application/json"
},
body: "{}",
bodyMediaType: "application/json",
params: {
responseCode: 201,
},
appliesTo: "server"
}
])

apply ResponseCodeHttpFallback @httpResponseTests([
{
id: "RestJsonHttpResponseCodeNotSetFallsBackToHttpCode",
documentation: """
This test ensures that servers fall back to the code set
by @http if @httpResponseCode is not set.""",
protocol: restJson1,
code: 201,
headers: {
"Content-Type": "application/json"
},
body: "{}",
bodyMediaType: "application/json",
appliesTo: "server"
}
])

0 comments on commit 359fc17

Please sign in to comment.