Hi, I was attempting to write a test that not only made a request, but also sent a body. Am I doing something wrong here? I keep getting an empty body in my request:
use spin_test_sdk::{
bindings::{
fermyon::spin_test::http_helper::OutgoingRequest,
wasi::http::types::{Headers, Method},
},
spin_test,
};
#[spin_test]
fn make_request() {
let headers =
Headers::from_list(&[("content-type".to_owned(), "text-plain".as_bytes().to_vec())])
.unwrap();
let request = OutgoingRequest::new(headers);
request.set_method(&Method::Post).unwrap();
let body = request.body().unwrap();
body.write_bytes("hello".as_bytes());
let response = spin_test_sdk::perform_request(request);
assert_eq!(response.status(), 200);
let body = String::from_utf8(response.body().unwrap()).unwrap();
assert_eq!(body, "hello");
}
The handler just reads and echos the body for now, and I can confirm it works via spin up and a curl call. But it fails to set the body in the test.
Hi, I was attempting to write a test that not only made a request, but also sent a body. Am I doing something wrong here? I keep getting an empty body in my request:
The handler just reads and echos the body for now, and I can confirm it works via
spin up
and acurl
call. But it fails to set the body in the test.