Skip to content

Commit 94f7e10

Browse files
authored
Remove unused code. (#868)
Cleanup an unused trait. Move tests into a tests module. Signed-off-by: David Calavera <[email protected]>
1 parent 41f5fb5 commit 94f7e10

File tree

1 file changed

+48
-59
lines changed

1 file changed

+48
-59
lines changed

lambda-runtime/src/requests.rs

+48-59
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::types::ToStreamErrorTrailer;
22
use crate::{types::Diagnostic, Error, FunctionResponse, IntoFunctionResponse};
33
use bytes::Bytes;
44
use http::header::CONTENT_TYPE;
5-
use http::{Method, Request, Response, Uri};
5+
use http::{Method, Request, Uri};
66
use lambda_runtime_api_client::{body::Body, build_request};
77
use serde::Serialize;
88
use std::fmt::Debug;
@@ -14,10 +14,6 @@ pub(crate) trait IntoRequest {
1414
fn into_req(self) -> Result<Request<Body>, Error>;
1515
}
1616

17-
pub(crate) trait IntoResponse {
18-
fn into_rsp(self) -> Result<Response<Body>, Error>;
19-
}
20-
2117
// /runtime/invocation/next
2218
#[derive(Debug, Eq, PartialEq)]
2319
pub(crate) struct NextEventRequest;
@@ -46,30 +42,6 @@ pub struct NextEventResponse<'a> {
4642
pub body: Vec<u8>,
4743
}
4844

49-
impl<'a> IntoResponse for NextEventResponse<'a> {
50-
fn into_rsp(self) -> Result<Response<Body>, Error> {
51-
// let body: BoxyBody< = BoxBody::new();
52-
let rsp = Response::builder()
53-
.header("lambda-runtime-aws-request-id", self.request_id)
54-
.header("lambda-runtime-deadline-ms", self.deadline)
55-
.header("lambda-runtime-invoked-function-arn", self.arn)
56-
.header("lambda-runtime-trace-id", self.trace_id)
57-
.body(Body::from(self.body))?;
58-
Ok(rsp)
59-
}
60-
}
61-
#[test]
62-
fn test_next_event_request() {
63-
let req = NextEventRequest;
64-
let req = req.into_req().unwrap();
65-
assert_eq!(req.method(), Method::GET);
66-
assert_eq!(req.uri(), &Uri::from_static("/2018-06-01/runtime/invocation/next"));
67-
assert!(match req.headers().get("User-Agent") {
68-
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
69-
None => false,
70-
});
71-
}
72-
7345
// /runtime/invocation/{AwsRequestId}/response
7446
pub(crate) struct EventCompletionRequest<'a, R, B, S, D, E>
7547
where
@@ -218,25 +190,6 @@ impl<'a> IntoRequest for EventErrorRequest<'a> {
218190
}
219191
}
220192

221-
#[test]
222-
fn test_event_error_request() {
223-
let req = EventErrorRequest {
224-
request_id: "id",
225-
diagnostic: Diagnostic {
226-
error_type: std::borrow::Cow::Borrowed("InvalidEventDataError"),
227-
error_message: std::borrow::Cow::Borrowed("Error parsing event data"),
228-
},
229-
};
230-
let req = req.into_req().unwrap();
231-
let expected = Uri::from_static("/2018-06-01/runtime/invocation/id/error");
232-
assert_eq!(req.method(), Method::POST);
233-
assert_eq!(req.uri(), &expected);
234-
assert!(match req.headers().get("User-Agent") {
235-
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
236-
None => false,
237-
});
238-
}
239-
240193
// /runtime/init/error
241194
struct InitErrorRequest;
242195

@@ -254,15 +207,51 @@ impl IntoRequest for InitErrorRequest {
254207
}
255208
}
256209

257-
#[test]
258-
fn test_init_error_request() {
259-
let req = InitErrorRequest;
260-
let req = req.into_req().unwrap();
261-
let expected = Uri::from_static("/2018-06-01/runtime/init/error");
262-
assert_eq!(req.method(), Method::POST);
263-
assert_eq!(req.uri(), &expected);
264-
assert!(match req.headers().get("User-Agent") {
265-
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
266-
None => false,
267-
});
210+
#[cfg(test)]
211+
mod tests {
212+
use super::*;
213+
214+
#[test]
215+
fn test_next_event_request() {
216+
let req = NextEventRequest;
217+
let req = req.into_req().unwrap();
218+
assert_eq!(req.method(), Method::GET);
219+
assert_eq!(req.uri(), &Uri::from_static("/2018-06-01/runtime/invocation/next"));
220+
assert!(match req.headers().get("User-Agent") {
221+
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
222+
None => false,
223+
});
224+
}
225+
226+
#[test]
227+
fn test_event_error_request() {
228+
let req = EventErrorRequest {
229+
request_id: "id",
230+
diagnostic: Diagnostic {
231+
error_type: std::borrow::Cow::Borrowed("InvalidEventDataError"),
232+
error_message: std::borrow::Cow::Borrowed("Error parsing event data"),
233+
},
234+
};
235+
let req = req.into_req().unwrap();
236+
let expected = Uri::from_static("/2018-06-01/runtime/invocation/id/error");
237+
assert_eq!(req.method(), Method::POST);
238+
assert_eq!(req.uri(), &expected);
239+
assert!(match req.headers().get("User-Agent") {
240+
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
241+
None => false,
242+
});
243+
}
244+
245+
#[test]
246+
fn test_init_error_request() {
247+
let req = InitErrorRequest;
248+
let req = req.into_req().unwrap();
249+
let expected = Uri::from_static("/2018-06-01/runtime/init/error");
250+
assert_eq!(req.method(), Method::POST);
251+
assert_eq!(req.uri(), &expected);
252+
assert!(match req.headers().get("User-Agent") {
253+
Some(header) => header.to_str().unwrap().starts_with("aws-lambda-rust/"),
254+
None => false,
255+
});
256+
}
268257
}

0 commit comments

Comments
 (0)