Skip to content

Commit

Permalink
Merge branch 'main' into maxday/add-integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxday committed Aug 12, 2024
2 parents 92846c8 + 6bbd1c1 commit b00f95c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
29 changes: 16 additions & 13 deletions lambda-events/src/event/bedrock_agent_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,34 @@ pub struct Agent {

#[cfg(test)]
mod tests {

use crate::event::bedrock_agent_runtime::AgentEvent;

#[test]
#[cfg(feature = "bedrock-agent-runtime")]
fn example_bedrock_agent__runtime_event() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
#[cfg(feature = "bedrock_agent_runtime")]
fn example_bedrock_agent_runtime_event() {
let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event.json");
let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "bedrock-agent-runtime")]
#[cfg(feature = "bedrock_agent_runtime")]
fn example_bedrock_agent_runtime_event_without_parameters() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "bedrock-agent-runtime")]
#[cfg(feature = "bedrock_agent_runtime")]
fn example_bedrock_agent_runtime_event_without_request_body() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}
30 changes: 0 additions & 30 deletions lambda-runtime/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,6 @@ impl<'a> IntoRequest for EventErrorRequest<'a> {
}
}

// /runtime/init/error
struct InitErrorRequest;

impl IntoRequest for InitErrorRequest {
fn into_req(self) -> Result<Request<Body>, Error> {
let uri = "/2018-06-01/runtime/init/error".to_string();
let uri = Uri::from_str(&uri)?;

let req = build_request()
.method(Method::POST)
.uri(uri)
.header("lambda-runtime-function-error-type", "unhandled")
.body(Body::empty())?;
Ok(req)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -237,17 +220,4 @@ mod tests {
None => false,
});
}

#[test]
fn test_init_error_request() {
let req = InitErrorRequest;
let req = req.into_req().unwrap();
let expected = Uri::from_static("/2018-06-01/runtime/init/error");
assert_eq!(req.method(), Method::POST);
assert_eq!(req.uri(), &expected);
assert!(match req.headers().get("User-Agent") {
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
None => false,
});
}
}

0 comments on commit b00f95c

Please sign in to comment.