mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: database methods to compute percentiles on analysis records
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use std::env;
|
||||
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::migrate::MigrateDatabase;
|
||||
use url::Url;
|
||||
|
||||
use crate::*;
|
||||
|
||||
use db_core::tests::*;
|
||||
@@ -26,28 +29,6 @@ async fn everyting_works() {
|
||||
const HEADING: &str = "testing notifications get db postgres";
|
||||
const MESSAGE: &str = "testing notifications get message db postgres";
|
||||
|
||||
// easy traffic pattern
|
||||
const TRAFFIC_PATTERN: TrafficPattern = TrafficPattern {
|
||||
avg_traffic: 500,
|
||||
peak_sustainable_traffic: 5_000,
|
||||
broke_my_site_traffic: Some(10_000),
|
||||
};
|
||||
|
||||
const LEVELS: [Level; 3] = [
|
||||
Level {
|
||||
difficulty_factor: 1,
|
||||
visitor_threshold: 1,
|
||||
},
|
||||
Level {
|
||||
difficulty_factor: 2,
|
||||
visitor_threshold: 2,
|
||||
},
|
||||
Level {
|
||||
difficulty_factor: 3,
|
||||
visitor_threshold: 3,
|
||||
},
|
||||
];
|
||||
|
||||
const ADD_NOTIFICATION: AddNotification = AddNotification {
|
||||
from: NAME,
|
||||
to: NAME,
|
||||
@@ -56,10 +37,21 @@ async fn everyting_works() {
|
||||
};
|
||||
|
||||
let url = env::var("POSTGRES_DATABASE_URL").unwrap();
|
||||
|
||||
let mut parsed = Url::parse(&url).unwrap();
|
||||
parsed.set_path("db_postgres_test");
|
||||
let url = parsed.to_string();
|
||||
|
||||
if sqlx::Postgres::database_exists(&url).await.unwrap() {
|
||||
sqlx::Postgres::drop_database(&url).await.unwrap();
|
||||
}
|
||||
sqlx::Postgres::create_database(&url).await.unwrap();
|
||||
|
||||
|
||||
let pool_options = PgPoolOptions::new().max_connections(2);
|
||||
let connection_options = ConnectionOptions::Fresh(Fresh {
|
||||
pool_options,
|
||||
url,
|
||||
url: url.clone(),
|
||||
disable_logging: false,
|
||||
});
|
||||
let db = connection_options.connect().await.unwrap();
|
||||
@@ -78,4 +70,6 @@ async fn everyting_works() {
|
||||
description: CAPTCHA_DESCRIPTION,
|
||||
};
|
||||
database_works(&db, &p, &c, &LEVELS, &TRAFFIC_PATTERN, &ADD_NOTIFICATION).await;
|
||||
drop(db);
|
||||
sqlx::Postgres::drop_database(&url).await.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user