use orion_accessor::{
addr::{Address, HttpResource, accessor::HttpAccessor},
types::ResourceDownloader,
update::DownloadOptions,
};
use tempfile::tempdir;
#[tokio::test]
async fn test_http_accessor_download() {
let temp_dir = tempdir().unwrap();
let dest_dir = temp_dir.path();
let accessor = HttpAccessor::default();
let http_addr = HttpResource::from("https://httpbin.org/robots.txt");
let options = DownloadOptions::default();
let result = accessor
.download_to_local(&Address::from(http_addr), dest_dir, &options)
.await;
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_http_accessor_creation() {
let accessor = HttpAccessor::default();
assert!(accessor.ctrl().is_none());
}
#[test]
fn test_http_addr_creation() {
let http_addr = HttpResource::from("https://example.com/file.txt");
assert_eq!(http_addr.url(), "https://example.com/file.txt");
assert!(http_addr.username().is_none());
assert!(http_addr.password().is_none());
}
#[test]
fn test_http_addr_with_credentials() {
let http_addr =
HttpResource::from("https://example.com/file.txt").with_credentials("user", "pass");
assert_eq!(http_addr.url(), "https://example.com/file.txt");
assert_eq!(http_addr.username().as_deref(), Some("user"));
assert_eq!(http_addr.password().as_deref(), Some("pass"));
}