Skip to content

Remove unused code. #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 48 additions & 59 deletions lambda-runtime/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::types::ToStreamErrorTrailer;
use crate::{types::Diagnostic, Error, FunctionResponse, IntoFunctionResponse};
use bytes::Bytes;
use http::header::CONTENT_TYPE;
use http::{Method, Request, Response, Uri};
use http::{Method, Request, Uri};
use lambda_runtime_api_client::{body::Body, build_request};
use serde::Serialize;
use std::fmt::Debug;
Expand All @@ -14,10 +14,6 @@ pub(crate) trait IntoRequest {
fn into_req(self) -> Result<Request<Body>, Error>;
}

pub(crate) trait IntoResponse {
fn into_rsp(self) -> Result<Response<Body>, Error>;
}

// /runtime/invocation/next
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct NextEventRequest;
Expand Down Expand Up @@ -46,30 +42,6 @@ pub struct NextEventResponse<'a> {
pub body: Vec<u8>,
}

impl<'a> IntoResponse for NextEventResponse<'a> {
fn into_rsp(self) -> Result<Response<Body>, Error> {
// let body: BoxyBody< = BoxBody::new();
let rsp = Response::builder()
.header("lambda-runtime-aws-request-id", self.request_id)
.header("lambda-runtime-deadline-ms", self.deadline)
.header("lambda-runtime-invoked-function-arn", self.arn)
.header("lambda-runtime-trace-id", self.trace_id)
.body(Body::from(self.body))?;
Ok(rsp)
}
}
#[test]
fn test_next_event_request() {
let req = NextEventRequest;
let req = req.into_req().unwrap();
assert_eq!(req.method(), Method::GET);
assert_eq!(req.uri(), &Uri::from_static("/2018-06-01/runtime/invocation/next"));
assert!(match req.headers().get("User-Agent") {
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
None => false,
});
}

// /runtime/invocation/{AwsRequestId}/response
pub(crate) struct EventCompletionRequest<'a, R, B, S, D, E>
where
Expand Down Expand Up @@ -218,25 +190,6 @@ impl<'a> IntoRequest for EventErrorRequest<'a> {
}
}

#[test]
fn test_event_error_request() {
let req = EventErrorRequest {
request_id: "id",
diagnostic: Diagnostic {
error_type: std::borrow::Cow::Borrowed("InvalidEventDataError"),
error_message: std::borrow::Cow::Borrowed("Error parsing event data"),
},
};
let req = req.into_req().unwrap();
let expected = Uri::from_static("/2018-06-01/runtime/invocation/id/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,
});
}

// /runtime/init/error
struct InitErrorRequest;

Expand All @@ -254,15 +207,51 @@ impl IntoRequest for InitErrorRequest {
}
}

#[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,
});
#[cfg(test)]
mod tests {
use super::*;

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

#[test]
fn test_event_error_request() {
let req = EventErrorRequest {
request_id: "id",
diagnostic: Diagnostic {
error_type: std::borrow::Cow::Borrowed("InvalidEventDataError"),
error_message: std::borrow::Cow::Borrowed("Error parsing event data"),
},
};
let req = req.into_req().unwrap();
let expected = Uri::from_static("/2018-06-01/runtime/invocation/id/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,
});
}

#[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,
});
}
}
Loading