Commit e20a1ce9 authored by Sajeer Ahamed's avatar Sajeer Ahamed

reqwesthttpsrc: test for 404 error

parent b4efa42d
......@@ -163,10 +163,11 @@ impl ReqwestHttpSrc {
})
})?;
//I have to read statusCode and produce error accordingly
if !response.status().is_success() {
gst_error!(cat, obj: src, "Request status failed: {:?}", response);
return Err(gst_error_msg!(
gst::ResourceError::Read,
gst::ResourceError::NotFound,
["Failed to fetch {}: {}", uri, response.status()]
));
}
......
......@@ -134,6 +134,39 @@ impl Harness {
}
}
fn wait_for_error(&mut self) -> glib::Error {
loop {
match self.receiver.recv().unwrap() {
Message::ServerError(err) => {
panic!("Got server error: {}", err);
}
Message::Event(ev) => {
use gst::EventView;
match ev.view() {
EventView::Eos(_) => {
panic!("Got EOS");
}
_ => (),
}
}
Message::Message(msg) => {
use gst::MessageView;
match msg.view() {
MessageView::Error(err) => {
return err.get_error();
}
_ => (),
}
}
Message::Buffer(buffer) => {
panic!("Got buffer {:?}", buffer);
}
}
}
}
/// Wait until a buffer is available or EOS was reached
///
/// This function will panic on errors.
......@@ -246,3 +279,33 @@ fn test_basic_request() {
// Check if everything was read
assert_eq!(cursor.position(), 11);
}
#[test]
fn test_404_error() {
init();
let mut h = Harness::new(
|_req| {
use hyper::{Body, Response};
Response::builder().status(404).body(Body::empty()).unwrap()
},
|_src| {},
);
h.run(|src| {
let _ = src.set_state(gst::State::Playing);
});
let expected_error = gst::ResourceError::NotFound;
let err_code = h.wait_for_error();
if let Some(err) = err_code.kind::<gst::ResourceError>() {
match err {
gst::ResourceError::NotFound => {
assert_eq!(err, expected_error);
}
_ => panic!("unexpected error : {:?}", err),
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment