Skip to content

Commit 99eb031

Browse files
authored
Test runtime with httpmock. (#780)
* Test runtime with httpmock. - Remove generic runtime over the client. - Make tests use httpmock for more concise assertions. Signed-off-by: David Calavera <[email protected]> * Bump MSRV to 1.65. Fixes compilation issues with the regex crate. Signed-off-by: David Calavera <[email protected]> --------- Signed-off-by: David Calavera <[email protected]>
1 parent 6e1c154 commit 99eb031

File tree

8 files changed

+134
-396
lines changed

8 files changed

+134
-396
lines changed

.github/workflows/build-events.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
toolchain:
17-
- "1.64.0" # Current MSRV
17+
- "1.65.0" # Current MSRV
1818
- stable
1919
env:
2020
RUST_BACKTRACE: 1

.github/workflows/build-extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
toolchain:
21-
- "1.64.0" # Current MSRV
21+
- "1.65.0" # Current MSRV
2222
- stable
2323
env:
2424
RUST_BACKTRACE: 1

.github/workflows/build-runtime.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
toolchain:
22-
- "1.64.0" # Current MSRV
22+
- "1.65.0" # Current MSRV
2323
- stable
2424
env:
2525
RUST_BACKTRACE: 1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ This will make your function compile much faster.
440440

441441
## Supported Rust Versions (MSRV)
442442

443-
The AWS Lambda Rust Runtime requires a minimum of Rust 1.64, and is not guaranteed to build on compiler versions earlier than that.
443+
The AWS Lambda Rust Runtime requires a minimum of Rust 1.65, and is not guaranteed to build on compiler versions earlier than that.
444444

445445
## Security
446446

lambda-runtime-api-client/src/lib.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
//! the AWS Lambda Runtime API.
77
use http::{uri::PathAndQuery, uri::Scheme, Request, Response, Uri};
88
use hyper::body::Incoming;
9-
use hyper_util::client::legacy::connect::{Connect, Connection, HttpConnector};
9+
use hyper_util::client::legacy::connect::HttpConnector;
1010
use std::{convert::TryInto, fmt::Debug};
11-
use tower_service::Service;
1211

1312
const USER_AGENT_HEADER: &str = "User-Agent";
1413
const DEFAULT_USER_AGENT: &str = concat!("aws-lambda-rust/", env!("CARGO_PKG_VERSION"));
@@ -20,27 +19,24 @@ pub mod body;
2019

2120
/// API client to interact with the AWS Lambda Runtime API.
2221
#[derive(Debug)]
23-
pub struct Client<C = HttpConnector> {
22+
pub struct Client {
2423
/// The runtime API URI
2524
pub base: Uri,
2625
/// The client that manages the API connections
27-
pub client: hyper_util::client::legacy::Client<C, body::Body>,
26+
pub client: hyper_util::client::legacy::Client<HttpConnector, body::Body>,
2827
}
2928

3029
impl Client {
3130
/// Create a builder struct to configure the client.
32-
pub fn builder() -> ClientBuilder<HttpConnector> {
31+
pub fn builder() -> ClientBuilder {
3332
ClientBuilder {
3433
connector: HttpConnector::new(),
3534
uri: None,
3635
}
3736
}
3837
}
3938

40-
impl<C> Client<C>
41-
where
42-
C: Connect + Sync + Send + Clone + 'static,
43-
{
39+
impl Client {
4440
/// Send a given request to the Runtime API.
4541
/// Use the client's base URI to ensure the API endpoint is correct.
4642
pub async fn call(&self, req: Request<body::Body>) -> Result<Response<Incoming>, BoxError> {
@@ -49,7 +45,7 @@ where
4945
}
5046

5147
/// Create a new client with a given base URI and HTTP connector.
52-
pub fn with(base: Uri, connector: C) -> Self {
48+
fn with(base: Uri, connector: HttpConnector) -> Self {
5349
let client = hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new())
5450
.http1_max_buf_size(1024 * 1024)
5551
.build(connector);
@@ -80,26 +76,14 @@ where
8076
}
8177

8278
/// Builder implementation to construct any Runtime API clients.
83-
pub struct ClientBuilder<C: Service<http::Uri> = HttpConnector> {
84-
connector: C,
79+
pub struct ClientBuilder {
80+
connector: HttpConnector,
8581
uri: Option<http::Uri>,
8682
}
8783

88-
impl<C> ClientBuilder<C>
89-
where
90-
C: Service<http::Uri> + Clone + Send + Sync + Unpin + 'static,
91-
<C as Service<http::Uri>>::Future: Unpin + Send,
92-
<C as Service<http::Uri>>::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
93-
<C as Service<http::Uri>>::Response: Connection + Unpin + Send + 'static,
94-
{
84+
impl ClientBuilder {
9585
/// Create a new builder with a given HTTP connector.
96-
pub fn with_connector<C2>(self, connector: C2) -> ClientBuilder<C2>
97-
where
98-
C2: Service<http::Uri> + Clone + Send + Sync + Unpin + 'static,
99-
<C2 as Service<http::Uri>>::Future: Unpin + Send,
100-
<C2 as Service<http::Uri>>::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
101-
<C2 as Service<http::Uri>>::Response: Connection + Unpin + Send + 'static,
102-
{
86+
pub fn with_connector(self, connector: HttpConnector) -> ClientBuilder {
10387
ClientBuilder {
10488
connector,
10589
uri: self.uri,
@@ -113,10 +97,7 @@ where
11397
}
11498

11599
/// Create the new client to interact with the Runtime API.
116-
pub fn build(self) -> Result<Client<C>, Error>
117-
where
118-
C: Connect + Sync + Send + Clone + 'static,
119-
{
100+
pub fn build(self) -> Result<Client, Error> {
120101
let uri = match self.uri {
121102
Some(uri) => uri,
122103
None => {

lambda-runtime/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tower = { workspace = true, features = ["util"] }
5151
tracing = { version = "0.1", features = ["log"] }
5252

5353
[dev-dependencies]
54+
httpmock = "0.7.0"
5455
hyper-util = { workspace = true, features = [
5556
"client",
5657
"client-legacy",
@@ -59,4 +60,4 @@ hyper-util = { workspace = true, features = [
5960
"server-auto",
6061
"tokio",
6162
] }
62-
pin-project-lite = { workspace = true }
63+
pin-project-lite = { workspace = true }

0 commit comments

Comments
 (0)