use async_trait::async_trait;
use crate::token_source::{TokenSource, TokenSourceError};
#[derive(Clone)]
pub struct MockTokenSource {
watch_tx: tokio::sync::watch::Sender<Option<Result<String, TokenSourceError>>>,
}
#[async_trait]
impl TokenSource for MockTokenSource {
fn watch(&self) -> tokio::sync::watch::Receiver<Option<Result<String, TokenSourceError>>> {
self.watch_tx.subscribe()
}
}
impl MockTokenSource {
pub fn new(initial_token: String) -> Self {
let (watch_tx, _watch_rx) = tokio::sync::watch::channel(Some(Ok(initial_token.clone())));
Self { watch_tx }
}
pub fn update_token(&self, new_token: String) {
let _ = self.watch_tx.send(Some(Ok(new_token)));
}
}