;### Changed
Some checks failed
Deploy quoter Microservice on push / deploy (push) Failing after 39m16s

- 🔑 **JWT_SECRET → JWT_SECRET_KEY**: Используется `JWT_SECRET_KEY` для совместимости с `@core`, `@inbox`, `@presence`
  - Fallback на `JWT_SECRET` для обратной совместимости
  - Обновлена документация: README.md, configuration.md
  - **BREAKING**: Требует установки `JWT_SECRET_KEY` в production (или использование legacy `JWT_SECRET`)

### Fixed (Tests & Code Quality)
- 🧪 **Удален мертвый код**: Removed unused mock functions and structs from tests
- 🔧 **Исправлены async тесты**: Changed `#[test]` → `#[tokio::test]` для async функций
- 🧹 **Чистые warnings**: Все тесты компилируются без warnings
- 📝 **Префиксы unused полей**: `_field` вместо `#[allow(dead_code)]`
This commit is contained in:
2025-09-30 21:46:47 +03:00
parent a78ad938a5
commit 5baba346e0
12 changed files with 71 additions and 170 deletions

View File

@@ -1,7 +1,7 @@
use actix_web::{App, HttpResponse, test, web};
// Tests use direct assertions without actix_web framework
/// Тест для проверки JSON сериализации/десериализации
#[test]
#[tokio::test]
async fn test_json_serialization() {
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)]
struct TestStruct {
@@ -28,7 +28,7 @@ async fn test_json_serialization() {
}
/// Тест для проверки multipart form data
#[test]
#[tokio::test]
async fn test_multipart_form_data() {
let boundary = "test-boundary";
let filename = "test.png";
@@ -63,7 +63,7 @@ async fn test_multipart_form_data() {
}
/// Тест для проверки UUID генерации
#[test]
#[tokio::test]
async fn test_uuid_generation() {
use uuid::Uuid;
@@ -84,7 +84,7 @@ async fn test_uuid_generation() {
}
/// Тест для проверки MIME типов
#[test]
#[tokio::test]
async fn test_mime_type_detection() {
// Тестируем определение MIME типа по расширению
let get_mime_type = |ext: &str| -> Option<&'static str> {
@@ -113,7 +113,7 @@ async fn test_mime_type_detection() {
}
/// Тест для проверки парсинга путей файлов
#[test]
#[tokio::test]
async fn test_file_path_parsing() {
fn parse_file_path(path: &str) -> (String, u32, String) {
let parts: Vec<&str> = path.split('.').collect();
@@ -153,7 +153,7 @@ async fn test_file_path_parsing() {
}
/// Тест для проверки расчетов квот
#[test]
#[tokio::test]
async fn test_quota_calculations() {
const MAX_QUOTA_BYTES: u64 = 5 * 1024 * 1024 * 1024; // 5 ГБ
const MB: u64 = 1024 * 1024;
@@ -183,7 +183,7 @@ async fn test_quota_calculations() {
}
/// Тест для проверки форматирования размеров файлов
#[test]
#[tokio::test]
async fn test_file_size_formatting() {
fn format_file_size(bytes: u64) -> String {
const KB: u64 = 1024;
@@ -207,7 +207,7 @@ async fn test_file_size_formatting() {
}
/// Тест для проверки обработки ошибок
#[test]
#[tokio::test]
async fn test_error_handling() {
// Тестируем парсинг неверного JSON
let invalid_json = "{ invalid json }";
@@ -232,7 +232,7 @@ async fn test_error_handling() {
}
/// Тест для проверки производительности
#[test]
#[tokio::test]
async fn test_performance() {
use std::time::Instant;
@@ -288,7 +288,7 @@ async fn test_performance() {
}
/// Тест для проверки функций парсинга путей файлов (thumbnail.rs)
#[test]
#[tokio::test]
async fn test_thumbnail_path_parsing() {
// Мокаем функцию parse_file_path для тестов
fn parse_file_path(path: &str) -> (String, u32, String) {
@@ -357,7 +357,7 @@ async fn test_thumbnail_path_parsing() {
}
/// Тест для проверки определения формата изображения (thumbnail.rs)
#[test]
#[tokio::test]
async fn test_image_format_detection() {
// Мокаем функцию determine_image_format для тестов
fn determine_image_format(ext: &str) -> Result<image::ImageFormat, ()> {
@@ -406,7 +406,7 @@ async fn test_image_format_detection() {
}
/// Тест для проверки поиска ближайшей ширины (thumbnail.rs)
#[test]
#[tokio::test]
async fn test_find_closest_width() {
// Мокаем функцию find_closest_width для тестов
fn find_closest_width(requested: u32) -> u32 {
@@ -461,7 +461,7 @@ async fn test_find_closest_width() {
}
/// Тест для проверки функций lookup.rs
#[test]
#[tokio::test]
async fn test_lookup_functions() {
// Мокаем функции lookup для тестов
fn get_mime_type(ext: &str) -> Option<&'static str> {
@@ -475,10 +475,6 @@ async fn test_lookup_functions() {
}
}
fn find_file_by_pattern(_pattern: &str) -> Option<String> {
Some("test_file.jpg".to_string())
}
// Тестируем get_mime_type
let mime_tests = vec![
("jpg", Some("image/jpeg")),
@@ -499,41 +495,12 @@ async fn test_lookup_functions() {
ext, result, expected
);
}
// Тестируем find_file_by_pattern (мокаем Redis)
// В реальном тесте здесь нужно было бы замокать Redis соединение
assert!(true, "lookup functions compile successfully");
}
/// Тест для проверки функций s3_utils.rs
#[test]
async fn test_s3_utils_functions() {
// Мокаем функции s3_utils для тестов
async fn get_s3_filelist(_bucket: &str) -> Result<Vec<String>, Box<dyn std::error::Error>> {
Ok(vec!["file1.jpg".to_string(), "file2.png".to_string()])
}
async fn check_file_exists(
_bucket: &str,
_key: &str,
) -> Result<bool, Box<dyn std::error::Error>> {
Ok(true)
}
async fn load_file_from_s3(
_bucket: &str,
_key: &str,
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
Ok(b"fake file content".to_vec())
}
// В реальном тесте здесь нужно было бы замокать AWS S3 клиент
// Пока что просто проверяем, что функции существуют и компилируются
assert!(true, "s3_utils functions compile successfully");
}
// S3 utils tests removed - mock functions not actually used
/// Тест для проверки функций overlay.rs
#[test]
#[tokio::test]
async fn test_overlay_functions() {
// Мокаем функцию generate_overlay для тестов
async fn generate_overlay(
@@ -571,7 +538,7 @@ async fn test_overlay_functions() {
}
/// Тест для проверки функций core.rs
#[test]
#[tokio::test]
async fn test_core_functions() {
// Мокаем функцию get_shout_by_id для тестов
async fn get_shout_by_id(id: u32) -> Result<String, Box<dyn std::error::Error>> {
@@ -591,7 +558,7 @@ async fn test_core_functions() {
}
/// Тест для проверки функций auth.rs
#[test]
#[tokio::test]
async fn test_auth_functions() {
// Мокаем функции auth для тестов
async fn get_id_by_token(token: &str) -> Result<u32, Box<dyn std::error::Error>> {
@@ -601,73 +568,17 @@ async fn test_auth_functions() {
Ok(123)
}
async fn user_added_file(
_user_id: u32,
_filename: &str,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
// Тестируем get_id_by_token с неверным токеном
let result = get_id_by_token("invalid_token").await;
assert!(result.is_err(), "Should fail with invalid token");
// Тестируем user_added_file (мокаем Redis)
// В реальном тесте здесь нужно было бы замокать Redis соединение
assert!(true, "auth functions compile successfully");
}
/// Тест для проверки функций app_state.rs
#[test]
async fn test_app_state_functions() {
// Мокаем структуру AppState для тестов
struct AppState {
redis: String,
storj_client: String,
aws_client: String,
bucket: String,
}
// AppState tests removed - mock struct not actually used
// В реальном тесте здесь нужно было бы замокать Redis и S3 клиенты
// Пока что просто проверяем, что структура существует и компилируется
assert!(true, "app_state functions compile successfully");
}
/// Тест для проверки функций handlers
#[test]
async fn test_handlers_functions() {
// Мокаем функции handlers для тестов
async fn get_quota_handler() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().json(serde_json::json!({"quota": 1024}))
}
async fn increase_quota_handler() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().json(serde_json::json!({"status": "increased"}))
}
async fn set_quota_handler() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().json(serde_json::json!({"status": "set"}))
}
async fn proxy_handler() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().body("proxy response")
}
async fn serve_file() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().body("file content")
}
async fn upload_handler() -> actix_web::HttpResponse {
actix_web::HttpResponse::Ok().json(serde_json::json!({"status": "uploaded"}))
}
// В реальном тесте здесь нужно было бы замокать зависимости
// Пока что просто проверяем, что функции существуют и компилируются
assert!(true, "handler functions compile successfully");
}
// Handler tests removed - mock functions not actually used
/// Тест для проверки интеграции основных компонентов
#[test]
#[tokio::test]
async fn test_integration() {
// Тестируем, что основные модули могут работать вместе
// Мокаем функции для интеграционного теста
@@ -730,7 +641,7 @@ async fn test_integration() {
}
/// Тест для проверки обработки граничных случаев
#[test]
#[tokio::test]
async fn test_edge_cases() {
// Мокаем функцию parse_file_path для теста граничных случаев
fn parse_file_path(path: &str) -> (String, u32, String) {
@@ -796,7 +707,7 @@ async fn test_edge_cases() {
}
/// Тест для проверки производительности парсинга
#[test]
#[tokio::test]
async fn test_parsing_performance() {
use std::time::Instant;