Skip to content

Commit 0f6e2a2

Browse files
authored
add test for basic-lambda (#551) (#612)
1 parent 847b060 commit 0f6e2a2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

examples/basic-lambda/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ serde = "1.0.136"
1616
tokio = { version = "1", features = ["macros"] }
1717
tracing = { version = "0.1", features = ["log"] }
1818
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }
19+
tokio-test = "0.4.2"

examples/basic-lambda/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,27 @@ pub(crate) async fn my_handler(event: LambdaEvent<Request>) -> Result<Response,
5454
// return `Response` (it will be serialized to JSON automatically by the runtime)
5555
Ok(resp)
5656
}
57+
58+
#[cfg(test)]
59+
mod tests {
60+
use crate::{my_handler, Request};
61+
use lambda_runtime::{Context, LambdaEvent};
62+
63+
#[tokio::test]
64+
async fn response_is_good_for_simple_input() {
65+
let id = "ID";
66+
67+
let mut context = Context::default();
68+
context.request_id = id.to_string();
69+
70+
let payload = Request {
71+
command: "X".to_string(),
72+
};
73+
let event = LambdaEvent { payload, context };
74+
75+
let result = my_handler(event).await.unwrap();
76+
77+
assert_eq!(result.msg, "Command X executed.");
78+
assert_eq!(result.req_id, id.to_string());
79+
}
80+
}

0 commit comments

Comments
 (0)