test dump v5

This commit is contained in:
ad hoc 2022-06-09 18:08:26 +02:00
parent c3003065e8
commit 1425d62a31
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643
4 changed files with 82 additions and 5 deletions

View File

@ -52,16 +52,13 @@ impl Server {
} }
} }
pub async fn new_auth() -> Self { pub async fn new_auth_with_options(mut options: Opt, dir: TempDir) -> Self {
let dir = TempDir::new().unwrap();
if cfg!(windows) { if cfg!(windows) {
std::env::set_var("TMP", TEST_TEMP_DIR.path()); std::env::set_var("TMP", TEST_TEMP_DIR.path());
} else { } else {
std::env::set_var("TMPDIR", TEST_TEMP_DIR.path()); std::env::set_var("TMPDIR", TEST_TEMP_DIR.path());
} }
let mut options = default_settings(dir.path());
options.master_key = Some("MASTER_KEY".to_string()); options.master_key = Some("MASTER_KEY".to_string());
let meilisearch = setup_meilisearch(&options).unwrap(); let meilisearch = setup_meilisearch(&options).unwrap();
@ -79,6 +76,12 @@ impl Server {
} }
} }
pub async fn new_auth() -> Self {
let dir = TempDir::new().unwrap();
let options = default_settings(dir.path());
Self::new_auth_with_options(options, dir).await
}
pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> { pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> {
let meilisearch = setup_meilisearch(&options)?; let meilisearch = setup_meilisearch(&options)?;
let auth = AuthController::new(&options.db_path, &options.master_key)?; let auth = AuthController::new(&options.db_path, &options.master_key)?;

View File

@ -18,6 +18,8 @@ pub enum GetDump {
MoviesRawV4, MoviesRawV4,
MoviesWithSettingsV4, MoviesWithSettingsV4,
RubyGemsWithSettingsV4, RubyGemsWithSettingsV4,
TestV5,
} }
impl GetDump { impl GetDump {
@ -63,6 +65,9 @@ impl GetDump {
GetDump::RubyGemsWithSettingsV4 => { GetDump::RubyGemsWithSettingsV4 => {
exist_relative_path!("tests/assets/v4_v0.25.2_rubygems_with_settings.dump").into() exist_relative_path!("tests/assets/v4_v0.25.2_rubygems_with_settings.dump").into()
} }
GetDump::TestV5 => {
exist_relative_path!("tests/assets/v5_v0.28.0_test_dump.dump").into()
}
} }
} }
} }

View File

@ -1,6 +1,6 @@
mod data; mod data;
use crate::common::{default_settings, Server}; use crate::common::{default_settings, GetAllDocumentsOptions, Server};
use meilisearch_http::Opt; use meilisearch_http::Opt;
use serde_json::json; use serde_json::json;
@ -605,3 +605,72 @@ async fn import_dump_v4_rubygems_with_settings() {
json!({ "name": "vortex-of-agony", "summary": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "description": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "id": "159227", "version": "0.1.0", "total_downloads": "1007"}) json!({ "name": "vortex-of-agony", "summary": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "description": "You dont need to use nodejs or go, just install this plugin. It will crash your application at random", "id": "159227", "version": "0.1.0", "total_downloads": "1007"})
); );
} }
#[actix_rt::test]
async fn import_dump_v5() {
let temp = tempfile::tempdir().unwrap();
let options = Opt {
import_dump: Some(GetDump::TestV5.path()),
..default_settings(temp.path())
};
let mut server = Server::new_auth_with_options(options, temp).await;
server.use_api_key("MASTER_KEY");
let (indexes, code) = server.list_indexes(None, None).await;
assert_eq!(code, 200, "{indexes}");
assert_eq!(indexes["results"].as_array().unwrap().len(), 2);
assert_eq!(indexes["results"][0]["uid"], json!("test"));
assert_eq!(indexes["results"][1]["uid"], json!("test2"));
assert_eq!(indexes["results"][0]["primaryKey"], json!("id"));
let expected_stats = json!({
"numberOfDocuments": 10,
"isIndexing": false,
"fieldDistribution": {
"cast": 10,
"director": 10,
"genres": 10,
"id": 10,
"overview": 10,
"popularity": 10,
"poster_path": 10,
"producer": 10,
"production_companies": 10,
"release_date": 10,
"tagline": 10,
"title": 10,
"vote_average": 10,
"vote_count": 10
}
});
let index1 = server.index("test");
let index2 = server.index("test2");
let (stats, code) = index1.stats().await;
assert_eq!(code, 200);
assert_eq!(stats, expected_stats);
let (docs, code) = index2
.get_all_documents(GetAllDocumentsOptions::default())
.await;
assert_eq!(code, 200);
assert_eq!(docs["results"].as_array().unwrap().len(), 10);
let (docs, code) = index1
.get_all_documents(GetAllDocumentsOptions::default())
.await;
assert_eq!(code, 200);
assert_eq!(docs["results"].as_array().unwrap().len(), 10);
let (stats, code) = index2.stats().await;
assert_eq!(code, 200);
assert_eq!(stats, expected_stats);
let (keys, code) = server.list_api_keys().await;
assert_eq!(code, 200);
let key = &keys["results"][0];
assert_eq!(key["name"], "my key");
}