MCPcopy Create free account
hub / github.com/actix/examples / handle_post_2_unit_test

Function handle_post_2_unit_test

forms/form/src/main.rs:134–156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

132
133 #[actix_web::test]
134 async fn handle_post_2_unit_test() {
135 let state = TestRequest::default()
136 .data(AppState {
137 foo: "bar".to_owned(),
138 })
139 .to_http_request();
140 let data = state.app_data::<actix_web::web::Data<AppState>>().unwrap();
141 let params = Form(MyParams {
142 name: "John".to_owned(),
143 });
144 let resp = handle_post_2(data.clone(), params).await.unwrap();
145
146 assert_eq!(resp.status(), StatusCode::OK);
147 assert_eq!(
148 resp.headers().get(CONTENT_TYPE).unwrap(),
149 HeaderValue::from_static("text/plain")
150 );
151 let body = to_bytes(resp.into_body()).await.unwrap();
152 assert_eq!(
153 body.as_str(),
154 "Your name is John, and in AppState I have foo: bar"
155 );
156 }
157
158 #[actix_web::test]
159 async fn handle_post_2_integration_test() {

Callers

nothing calls this directly

Calls 1

handle_post_2Function · 0.85

Tested by

no test coverage detected