-
Hi. I saw that into_body removed in this commit. I am using this pattern heavely in my test code: let resp_str = resp.into_body().into_string().await?;
let health_response: HealthResponse = from_str(&resp_str)?;
assert_eq!(health_response.data.health.status, "running"); I prefer to access the struct's field rather than doing I ported this way, it work during - let resp_str = resp.into_body().into_string().await?;
- let health_response: HealthResponse = from_str(&resp_str)?;
+ let resp_str = resp.json().await;
+ let health_response: HealthResponse = from_str(resp_str.value().string())?; I got: ✗ cargo test -- --nocapture --test health
Finished test [unoptimized + debuginfo] target(s) in 0.13s
Running unittests (/app/target/debug/deps/risachi_backend-b328c9a4d14547d1)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running unittests (app/target/debug/deps/risachi_backend-648dcf3cc2a054f3)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/tests.rs (/app/target/debug/deps/tests-4313d12b69de9d88)
running 1 test
thread 'health::tests::health' panicked at 'string', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/poem-1.3.14/src/test/json.rs:123:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test health::tests::health ... FAILED
failures:
failures:
health::tests::health
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.02s
error: test failed, to rerun pass '--test tests' The backtrace: running 1 test
thread 'health::tests::health' panicked at 'string', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/poem-1.3.14/src/test/json.rs:123:25
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::panicking::panic_display
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:72:5
3: core::panicking::panic_str
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:56:5
4: core::option::expect_failed
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/option.rs:1817:5
5: core::option::Option<T>::expect
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/option.rs:692:21
6: poem::test::json::TestJsonValue::string
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/poem-1.3.14/src/test/json.rs:123:9
7: tests::health::tests::health::{{closure}}
at ./tests/health/tests.rs:56:20
8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/future/mod.rs:84:19
9: <core::pin::Pin<P> as core::future::future::Future>::poll
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/future/future.rs:123:9
10: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:498:48
11: tokio::coop::with_budget::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:102:9
12: std::thread::local::LocalKey<T>::try_with
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:412:16
13: std::thread::local::LocalKey<T>::with
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:388:9
14: tokio::coop::with_budget
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:95:5
15: tokio::coop::budget
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/coop.rs:72:5
16: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:498:25
17: tokio::runtime::basic_scheduler::Context::enter
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:356:19
18: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:497:36
19: tokio::runtime::basic_scheduler::CoreGuard::enter::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:555:57
20: tokio::macros::scoped_tls::ScopedKey<T>::set
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/macros/scoped_tls.rs:61:9
21: tokio::runtime::basic_scheduler::CoreGuard::enter
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:555:27
22: tokio::runtime::basic_scheduler::CoreGuard::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:488:9
23: tokio::runtime::basic_scheduler::BasicScheduler::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/basic_scheduler.rs:168:24
24: tokio::runtime::Runtime::block_on
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/mod.rs:475:46
25: tests::health::tests::health
at ./tests/health/tests.rs:61:5
26: tests::health::tests::health::{{closure}}
at ./tests/health/tests.rs:18:7
27: core::ops::function::FnOnce::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
28: core::ops::function::FnOnce::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test health::tests::health ... FAILED
failures:
failures:
health::tests::health
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.06s
error: test failed, to rerun pass '--test tests' |
Beta Was this translation helpful? Give feedback.
Answered by
sunli829
Mar 14, 2022
Replies: 1 comment 2 replies
-
Because |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
azzamsa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because
resp.0.into_body()
can be used instead.