mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 18:40:32 +00:00
reqwesthttpsrc: test for 404 error
This commit is contained in:
parent
b4efa42d8f
commit
e20a1ce947
2 changed files with 65 additions and 1 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue