2022-10-24 01:50:31 +02:00
|
|
|
use crate::be::{Backend, BackendConfig};
|
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::schema::Schema;
|
|
|
|
|
2024-02-28 22:04:33 +01:00
|
|
|
pub struct TestConfiguration {
|
|
|
|
pub domain_level: DomainVersion,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TestConfiguration {
|
|
|
|
fn default() -> Self {
|
|
|
|
TestConfiguration {
|
|
|
|
domain_level: DOMAIN_TGT_LEVEL,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 01:23:49 +01:00
|
|
|
#[allow(clippy::expect_used)]
|
2024-02-28 22:04:33 +01:00
|
|
|
pub async fn setup_test(config: TestConfiguration) -> QueryServer {
|
2022-11-11 01:23:49 +01:00
|
|
|
sketching::test_init();
|
2022-10-24 01:50:31 +02:00
|
|
|
|
|
|
|
// Create an in memory BE
|
|
|
|
let schema_outer = Schema::new().expect("Failed to init schema");
|
|
|
|
let idxmeta = {
|
|
|
|
let schema_txn = schema_outer.write();
|
|
|
|
schema_txn.reload_idxmeta()
|
|
|
|
};
|
2023-01-25 05:14:16 +01:00
|
|
|
let be =
|
|
|
|
Backend::new(BackendConfig::new_test("main"), idxmeta, false).expect("Failed to init BE");
|
2022-10-24 01:50:31 +02:00
|
|
|
|
2024-02-28 22:04:33 +01:00
|
|
|
let test_server = QueryServer::new(be, schema_outer, "example.com".to_string(), Duration::ZERO)
|
|
|
|
.expect("Failed to setup Query Server");
|
|
|
|
|
|
|
|
test_server
|
|
|
|
.initialise_helper(duration_from_epoch_now(), config.domain_level)
|
|
|
|
.await
|
|
|
|
.expect("init failed!");
|
|
|
|
|
|
|
|
test_server
|
2022-10-24 01:50:31 +02:00
|
|
|
}
|
2022-11-02 10:46:09 +01:00
|
|
|
|
2023-01-25 05:14:16 +01:00
|
|
|
#[allow(clippy::expect_used)]
|
2024-02-28 22:04:33 +01:00
|
|
|
pub async fn setup_pair_test(config: TestConfiguration) -> (QueryServer, QueryServer) {
|
2023-01-25 05:14:16 +01:00
|
|
|
sketching::test_init();
|
|
|
|
|
|
|
|
let qs_a = {
|
|
|
|
// Create an in memory BE
|
|
|
|
let schema_outer = Schema::new().expect("Failed to init schema");
|
|
|
|
let idxmeta = {
|
|
|
|
let schema_txn = schema_outer.write();
|
|
|
|
schema_txn.reload_idxmeta()
|
|
|
|
};
|
|
|
|
let be = Backend::new(BackendConfig::new_test("db_a"), idxmeta, false)
|
|
|
|
.expect("Failed to init BE");
|
|
|
|
|
|
|
|
// Init is called via the proc macro
|
2024-02-02 06:38:45 +01:00
|
|
|
QueryServer::new(be, schema_outer, "example.com".to_string(), Duration::ZERO)
|
2023-10-08 09:39:00 +02:00
|
|
|
.expect("Failed to setup Query Server")
|
2023-01-25 05:14:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let qs_b = {
|
|
|
|
// Create an in memory BE
|
|
|
|
let schema_outer = Schema::new().expect("Failed to init schema");
|
|
|
|
let idxmeta = {
|
|
|
|
let schema_txn = schema_outer.write();
|
|
|
|
schema_txn.reload_idxmeta()
|
|
|
|
};
|
|
|
|
let be = Backend::new(BackendConfig::new_test("db_b"), idxmeta, false)
|
|
|
|
.expect("Failed to init BE");
|
|
|
|
|
|
|
|
// Init is called via the proc macro
|
2024-02-02 06:38:45 +01:00
|
|
|
QueryServer::new(be, schema_outer, "example.com".to_string(), Duration::ZERO)
|
2023-10-08 09:39:00 +02:00
|
|
|
.expect("Failed to setup Query Server")
|
2023-01-25 05:14:16 +01:00
|
|
|
};
|
|
|
|
|
2024-02-28 22:04:33 +01:00
|
|
|
qs_a.initialise_helper(duration_from_epoch_now(), config.domain_level)
|
|
|
|
.await
|
|
|
|
.expect("init failed!");
|
|
|
|
|
|
|
|
qs_b.initialise_helper(duration_from_epoch_now(), config.domain_level)
|
|
|
|
.await
|
|
|
|
.expect("init failed!");
|
|
|
|
|
2023-01-25 05:14:16 +01:00
|
|
|
(qs_a, qs_b)
|
|
|
|
}
|
|
|
|
|
2022-11-11 01:23:49 +01:00
|
|
|
#[allow(clippy::expect_used)]
|
2024-02-28 22:04:33 +01:00
|
|
|
pub async fn setup_idm_test(
|
|
|
|
config: TestConfiguration,
|
|
|
|
) -> (IdmServer, IdmServerDelayed, IdmServerAudit) {
|
|
|
|
let qs = setup_test(config).await;
|
2022-11-02 10:46:09 +01:00
|
|
|
|
2023-03-03 08:53:54 +01:00
|
|
|
IdmServer::new(qs, "https://idm.example.com")
|
|
|
|
.await
|
|
|
|
.expect("Failed to setup idms")
|
2022-11-02 10:46:09 +01:00
|
|
|
}
|