#![cfg(feature = "draft14")]
use moqtap_client::draft14::fetch::*;
#[test]
fn fetch_initial_state_is_idle() {
let sm = FetchStateMachine::new();
assert_eq!(sm.state(), FetchState::Idle);
}
#[test]
fn fetch_idle_to_pending() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().expect("on_fetch_sent from Idle should succeed");
assert_eq!(sm.state(), FetchState::Pending);
}
#[test]
fn fetch_pending_to_receiving() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().expect("on_fetch_ok from Pending should succeed");
assert_eq!(sm.state(), FetchState::Receiving);
}
#[test]
fn fetch_receiving_to_done_via_fin() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
sm.on_stream_fin().expect("on_stream_fin from Receiving should succeed");
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_receiving_to_done_via_reset() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
sm.on_stream_reset().expect("on_stream_reset from Receiving should succeed");
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_full_lifecycle() {
let mut sm = FetchStateMachine::new();
assert_eq!(sm.state(), FetchState::Idle);
sm.on_fetch_sent().unwrap();
assert_eq!(sm.state(), FetchState::Pending);
sm.on_fetch_ok().unwrap();
assert_eq!(sm.state(), FetchState::Receiving);
sm.on_stream_fin().unwrap();
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_pending_to_done_via_cancel() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_cancel().expect("on_fetch_cancel from Pending should succeed");
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_receiving_to_done_via_cancel() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
sm.on_fetch_cancel().expect("on_fetch_cancel from Receiving should succeed");
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_pending_to_done_via_error() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_error().expect("on_fetch_error from Pending should succeed");
assert_eq!(sm.state(), FetchState::Done);
}
#[test]
fn fetch_cannot_fetch_ok_from_idle() {
let mut sm = FetchStateMachine::new();
let result = sm.on_fetch_ok();
assert!(result.is_err(), "on_fetch_ok from Idle should fail");
}
#[test]
fn fetch_cannot_cancel_from_idle() {
let mut sm = FetchStateMachine::new();
let result = sm.on_fetch_cancel();
assert!(result.is_err(), "on_fetch_cancel from Idle should fail");
}
#[test]
fn fetch_cannot_send_from_receiving() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
assert_eq!(sm.state(), FetchState::Receiving);
let result = sm.on_fetch_sent();
assert!(result.is_err(), "on_fetch_sent from Receiving should fail");
}
#[test]
fn fetch_cannot_reuse_after_done() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
sm.on_stream_fin().unwrap();
assert_eq!(sm.state(), FetchState::Done);
let result = sm.on_fetch_sent();
assert!(result.is_err(), "on_fetch_sent from Done should fail");
}
#[test]
fn fetch_cannot_stream_fin_from_idle() {
let mut sm = FetchStateMachine::new();
let result = sm.on_stream_fin();
assert!(result.is_err(), "on_stream_fin from Idle should fail");
}
#[test]
fn fetch_cannot_stream_fin_from_pending() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
assert_eq!(sm.state(), FetchState::Pending);
let result = sm.on_stream_fin();
assert!(result.is_err(), "on_stream_fin from Pending should fail");
}
#[test]
fn fetch_cannot_fetch_error_from_receiving() {
let mut sm = FetchStateMachine::new();
sm.on_fetch_sent().unwrap();
sm.on_fetch_ok().unwrap();
assert_eq!(sm.state(), FetchState::Receiving);
let result = sm.on_fetch_error();
assert!(result.is_err(), "on_fetch_error from Receiving should fail");
}