feat(tests): make sure tests that should require admin privs, use admin
This commit is contained in:
parent
fd5923f297
commit
a5464c1a50
|
|
@ -52,12 +52,14 @@ impl OCRQueueTestClient {
|
||||||
return Err(format!("Server not running: {}", e).into());
|
return Err(format!("Server not running: {}", e).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestamp = std::time::SystemTime::now()
|
// Use UUID for guaranteed uniqueness across concurrent test execution
|
||||||
|
let test_id = Uuid::new_v4().simple().to_string();
|
||||||
|
let nanos = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis();
|
.as_nanos();
|
||||||
let username = format!("ocr_queue_test_{}_{}", role.to_string(), timestamp);
|
let username = format!("ocr_queue_{}_{}_{}_{}", role.to_string(), test_id, nanos, Uuid::new_v4().simple());
|
||||||
let email = format!("ocr_queue_test_{}@example.com", timestamp);
|
let email = format!("ocr_queue_{}_{}@{}.example.com", test_id, nanos, Uuid::new_v4().simple());
|
||||||
let password = "testpassword123";
|
let password = "testpassword123";
|
||||||
|
|
||||||
// Register user
|
// Register user
|
||||||
|
|
@ -297,8 +299,8 @@ impl Clone for OCRQueueTestClient {
|
||||||
async fn test_queue_stats_monitoring() {
|
async fn test_queue_stats_monitoring() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
// Register and login
|
// Register and login as admin (queue stats require admin access)
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
@ -353,7 +355,7 @@ async fn test_queue_stats_monitoring() {
|
||||||
async fn test_failed_job_requeue_functionality() {
|
async fn test_failed_job_requeue_functionality() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
@ -403,7 +405,7 @@ async fn test_failed_job_requeue_functionality() {
|
||||||
async fn test_concurrent_ocr_processing() {
|
async fn test_concurrent_ocr_processing() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
@ -521,7 +523,7 @@ async fn test_concurrent_ocr_processing() {
|
||||||
async fn test_queue_performance_monitoring() {
|
async fn test_queue_performance_monitoring() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
@ -598,7 +600,7 @@ async fn test_queue_performance_monitoring() {
|
||||||
async fn test_queue_error_handling() {
|
async fn test_queue_error_handling() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
@ -641,7 +643,7 @@ async fn test_queue_error_handling() {
|
||||||
async fn test_queue_stats_consistency() {
|
async fn test_queue_stats_consistency() {
|
||||||
let mut client = OCRQueueTestClient::new();
|
let mut client = OCRQueueTestClient::new();
|
||||||
|
|
||||||
client.register_and_login(UserRole::User).await
|
client.register_and_login(UserRole::Admin).await
|
||||||
.expect("Failed to register and login");
|
.expect("Failed to register and login");
|
||||||
|
|
||||||
println!("✅ User registered and logged in");
|
println!("✅ User registered and logged in");
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use std::time::{Duration, Instant};
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use chrono;
|
||||||
|
|
||||||
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole, DocumentResponse};
|
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole, DocumentResponse};
|
||||||
|
|
||||||
|
|
@ -130,12 +131,14 @@ impl LoadTestClient {
|
||||||
|
|
||||||
/// Setup a test user for load testing
|
/// Setup a test user for load testing
|
||||||
async fn setup_user(&mut self, user_index: usize) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
|
async fn setup_user(&mut self, user_index: usize) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let timestamp = std::time::SystemTime::now()
|
// Use UUID for guaranteed uniqueness across concurrent test execution
|
||||||
|
let test_id = Uuid::new_v4().simple().to_string();
|
||||||
|
let nanos = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis();
|
.as_nanos();
|
||||||
let username = format!("load_test_user_{}_{}", user_index, timestamp);
|
let username = format!("load_test_user_{}_{}_{}_{}_{}", user_index, test_id, nanos, Uuid::new_v4().simple(), chrono::Utc::now().timestamp_millis());
|
||||||
let email = format!("load_test_{}@example.com", timestamp);
|
let email = format!("load_test_{}_{}@{}.example.com", user_index, test_id, nanos);
|
||||||
let password = "loadtestpassword123";
|
let password = "loadtestpassword123";
|
||||||
|
|
||||||
// Register user
|
// Register user
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use readur::{
|
||||||
fn get_test_db_url() -> String {
|
fn get_test_db_url() -> String {
|
||||||
std::env::var("DATABASE_URL")
|
std::env::var("DATABASE_URL")
|
||||||
.or_else(|_| std::env::var("TEST_DATABASE_URL"))
|
.or_else(|_| std::env::var("TEST_DATABASE_URL"))
|
||||||
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/readur_test".to_string())
|
.unwrap_or_else(|_| "postgresql://readur:readur@localhost:5432/readur".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SimpleThrottleTest {
|
struct SimpleThrottleTest {
|
||||||
|
|
@ -56,10 +56,14 @@ impl SimpleThrottleTest {
|
||||||
|
|
||||||
async fn create_test_user(&self) -> Result<Uuid> {
|
async fn create_test_user(&self) -> Result<Uuid> {
|
||||||
let user_id = Uuid::new_v4();
|
let user_id = Uuid::new_v4();
|
||||||
let timestamp = std::time::SystemTime::now()
|
// Use UUID for guaranteed uniqueness across concurrent test execution
|
||||||
|
let test_id = Uuid::new_v4().simple().to_string();
|
||||||
|
let nanos = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis();
|
.as_nanos();
|
||||||
|
let username = format!("throttle_test_{}_{}_{}", test_id, nanos, Uuid::new_v4().simple());
|
||||||
|
let email = format!("throttle_{}_{}@{}.example.com", test_id, nanos, Uuid::new_v4().simple());
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
|
|
@ -68,8 +72,8 @@ impl SimpleThrottleTest {
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(format!("throttle_test_{}", timestamp))
|
.bind(&username)
|
||||||
.bind(format!("throttle_{}@example.com", timestamp))
|
.bind(&email)
|
||||||
.bind("test_hash")
|
.bind("test_hash")
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,12 @@ use readur::{
|
||||||
|
|
||||||
/// Create a test app state
|
/// Create a test app state
|
||||||
async fn create_test_app_state() -> Arc<AppState> {
|
async fn create_test_app_state() -> Arc<AppState> {
|
||||||
|
let database_url = std::env::var("TEST_DATABASE_URL")
|
||||||
|
.or_else(|_| std::env::var("DATABASE_URL"))
|
||||||
|
.unwrap_or_else(|_| "postgresql://readur:readur@localhost:5432/readur".to_string());
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
database_url: "sqlite::memory:".to_string(),
|
database_url,
|
||||||
server_address: "127.0.0.1:8080".to_string(),
|
server_address: "127.0.0.1:8080".to_string(),
|
||||||
jwt_secret: "test_secret".to_string(),
|
jwt_secret: "test_secret".to_string(),
|
||||||
upload_path: "/tmp/test_uploads".to_string(),
|
upload_path: "/tmp/test_uploads".to_string(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue