Skip to content

Commit 09da50b

Browse files
ilslvtyranron
authored andcommitted
Upgrade actix-web to latest beta versions
1 parent 7bc8a2b commit 09da50b

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

juniper_actix/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ subscriptions = ["juniper_graphql_ws", "tokio"]
1313

1414
[dependencies]
1515
actix = "0.12"
16-
actix-http = "3.0.0-beta.13"
16+
actix-http = "3.0.0-beta.15"
1717
http = "0.2.4"
18-
actix-web = "4.0.0-beta.12"
19-
actix-web-actors = "4.0.0-beta.7"
18+
actix-web = "4.0.0-beta.14"
19+
actix-web-actors = "4.0.0-beta.8"
2020

2121
juniper = { version = "0.15.7", path = "../juniper", default-features = false }
2222
juniper_graphql_ws = { version = "0.3.0", path = "../juniper_graphql_ws", optional = true }
@@ -30,11 +30,11 @@ tokio = { version = "1.0", features = ["sync"], optional = true }
3030

3131
[dev-dependencies]
3232
actix-rt = "2"
33-
actix-cors = "0.6.0-beta.4"
34-
actix-identity = "0.4.0-beta.4"
33+
actix-cors = "0.6.0-beta.6"
34+
actix-identity = "0.4.0-beta.5"
3535
tokio = "1.0"
3636
async-stream = "0.3"
37-
actix-test = "0.1.0-beta.6"
37+
actix-test = "0.1.0-beta.8"
3838

3939
juniper = { version = "0.15.7", path = "../juniper", features = ["expose-test-schema"] }
4040

juniper_actix/src/lib.rs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ pub mod subscriptions {
466466

467467
#[cfg(test)]
468468
mod tests {
469-
use actix_http::body::AnyBody;
469+
use std::pin::Pin;
470+
471+
use actix_http::body::MessageBody;
470472
use actix_web::{
471473
dev::ServiceResponse,
472474
http,
@@ -475,6 +477,7 @@ mod tests {
475477
web::Data,
476478
App,
477479
};
480+
use futures::future;
478481
use juniper::{
479482
http::tests::{run_http_test_suite, HttpIntegration, TestResponse},
480483
tests::fixtures::starwars::schema::{Database, Query},
@@ -487,11 +490,16 @@ mod tests {
487490
type Schema =
488491
juniper::RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<Database>>;
489492

490-
async fn take_response_body_string(resp: &mut ServiceResponse) -> String {
491-
match resp.response().body() {
492-
AnyBody::Bytes(body) => String::from_utf8(body.to_vec()).unwrap(),
493-
_ => String::from(""),
494-
}
493+
async fn take_response_body_string(resp: ServiceResponse) -> String {
494+
let mut body = resp.into_body();
495+
String::from_utf8(
496+
future::poll_fn(|cx| Pin::new(&mut body).poll_next(cx))
497+
.await
498+
.unwrap()
499+
.unwrap()
500+
.to_vec(),
501+
)
502+
.unwrap()
495503
}
496504

497505
async fn index(
@@ -537,13 +545,13 @@ mod tests {
537545
.append_header((ACCEPT, "text/html"))
538546
.to_request();
539547

540-
let mut resp = test::call_service(&mut app, req).await;
541-
let body = take_response_body_string(&mut resp).await;
548+
let resp = test::call_service(&mut app, req).await;
542549
assert_eq!(resp.status(), http::StatusCode::OK);
543550
assert_eq!(
544551
resp.headers().get(CONTENT_TYPE).unwrap().to_str().unwrap(),
545552
"text/html; charset=utf-8"
546553
);
554+
let body = take_response_body_string(resp).await;
547555
assert!(body.contains("<script>var GRAPHQL_URL = '/dogs-api/graphql';</script>"));
548556
assert!(body.contains(
549557
"<script>var GRAPHQL_SUBSCRIPTIONS_URL = '/dogs-api/subscriptions';</script>"
@@ -578,13 +586,13 @@ mod tests {
578586
.append_header((ACCEPT, "text/html"))
579587
.to_request();
580588

581-
let mut resp = test::call_service(&mut app, req).await;
582-
let body = take_response_body_string(&mut resp).await;
589+
let resp = test::call_service(&mut app, req).await;
583590
assert_eq!(resp.status(), http::StatusCode::OK);
584591
assert_eq!(
585592
resp.headers().get(CONTENT_TYPE).unwrap().to_str().unwrap(),
586593
"text/html; charset=utf-8"
587594
);
595+
let body = take_response_body_string(resp).await;
588596
assert!(body.contains("GraphQLPlayground.init(root, { endpoint: '/dogs-api/graphql', subscriptionEndpoint: '/dogs-api/subscriptions' })"));
589597
}
590598

@@ -611,17 +619,16 @@ mod tests {
611619
)
612620
.await;
613621

614-
let mut resp = test::call_service(&mut app, req).await;
615-
dbg!(take_response_body_string(&mut resp).await);
622+
let resp = test::call_service(&mut app, req).await;
616623
assert_eq!(resp.status(), http::StatusCode::OK);
617-
assert_eq!(
618-
take_response_body_string(&mut resp).await,
619-
r#"{"data":{"hero":{"name":"R2-D2"}}}"#
620-
);
621624
assert_eq!(
622625
resp.headers().get("content-type").unwrap(),
623626
"application/json",
624627
);
628+
assert_eq!(
629+
take_response_body_string(resp).await,
630+
r#"{"data":{"hero":{"name":"R2-D2"}}}"#
631+
);
625632
}
626633

627634
#[actix_web::rt::test]
@@ -644,17 +651,17 @@ mod tests {
644651
)
645652
.await;
646653

647-
let mut resp = test::call_service(&mut app, req).await;
654+
let resp = test::call_service(&mut app, req).await;
648655

649656
assert_eq!(resp.status(), http::StatusCode::OK);
650-
assert_eq!(
651-
take_response_body_string(&mut resp).await,
652-
r#"{"data":{"hero":{"name":"R2-D2"}}}"#
653-
);
654657
assert_eq!(
655658
resp.headers().get("content-type").unwrap(),
656659
"application/json",
657660
);
661+
assert_eq!(
662+
take_response_body_string(resp).await,
663+
r#"{"data":{"hero":{"name":"R2-D2"}}}"#
664+
);
658665
}
659666

660667
#[actix_web::rt::test]
@@ -688,17 +695,17 @@ mod tests {
688695
)
689696
.await;
690697

691-
let mut resp = test::call_service(&mut app, req).await;
698+
let resp = test::call_service(&mut app, req).await;
692699

693700
assert_eq!(resp.status(), http::StatusCode::OK);
694-
assert_eq!(
695-
take_response_body_string(&mut resp).await,
696-
r#"[{"data":{"hero":{"name":"R2-D2"}}},{"data":{"hero":{"id":"1000","name":"Luke Skywalker"}}}]"#
697-
);
698701
assert_eq!(
699702
resp.headers().get("content-type").unwrap(),
700703
"application/json",
701704
);
705+
assert_eq!(
706+
take_response_body_string(resp).await,
707+
r#"[{"data":{"hero":{"name":"R2-D2"}}},{"data":{"hero":{"id":"1000","name":"Luke Skywalker"}}}]"#
708+
);
702709
}
703710

704711
#[test]
@@ -757,14 +764,20 @@ mod tests {
757764
}
758765
}
759766

760-
async fn make_test_response(mut resp: ServiceResponse) -> TestResponse {
761-
let body = take_response_body_string(&mut resp).await;
767+
async fn make_test_response(resp: ServiceResponse) -> TestResponse {
762768
let status_code = resp.status().as_u16();
763-
let content_type = resp.headers().get(CONTENT_TYPE).unwrap();
769+
let content_type = resp
770+
.headers()
771+
.get(CONTENT_TYPE)
772+
.unwrap()
773+
.to_str()
774+
.unwrap()
775+
.to_string();
776+
let body = take_response_body_string(resp).await;
764777
TestResponse {
765778
status_code: status_code as i32,
766779
body: Some(body),
767-
content_type: content_type.to_str().unwrap().to_string(),
780+
content_type,
768781
}
769782
}
770783

0 commit comments

Comments
 (0)