mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update unit test
This commit is contained in:
19
src/server/unittest/auth.rs
Normal file
19
src/server/unittest/auth.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use super::UnitTestContext;
|
||||
use crate::error::PixivDownloaderError;
|
||||
use bytes::BytesMut;
|
||||
use hyper::{Body, Request};
|
||||
|
||||
/// Test authentification methods
|
||||
/// Returns token
|
||||
pub async fn test(ctx: &UnitTestContext) -> Result<BytesMut, PixivDownloaderError> {
|
||||
let re = Request::builder().uri("/auth").body(Body::empty())?;
|
||||
let res = ctx.request_json(re).await?.unwrap();
|
||||
assert_eq!(res["has_root_user"].as_bool(), Some(false));
|
||||
let re = Request::builder().uri("/auth/pubkey").body(Body::empty())?;
|
||||
let res = ctx.request_json(re).await?.unwrap();
|
||||
let ok = res["ok"].as_bool().unwrap();
|
||||
if !ok {
|
||||
panic!("Failed to get public key.");
|
||||
}
|
||||
Ok(BytesMut::new())
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod auth;
|
||||
mod version;
|
||||
|
||||
use super::context::ServerContext;
|
||||
@@ -76,5 +77,6 @@ async fn test() -> Result<(), PixivDownloaderError> {
|
||||
}
|
||||
let ctx = UnitTestContext::new().await;
|
||||
version::test(&ctx).await?;
|
||||
auth::test(&ctx).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user