Modernize the UI and isolate fixture tests.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
//! Verify that the Rust Diesel models read the compatibility fixture produced by bDS.
|
||||
|
||||
mod support;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bds_core::db::Database;
|
||||
use bds_core::db::queries::{
|
||||
media, post, post_link, post_media, post_translation, project, script, setting, tag, template,
|
||||
};
|
||||
@@ -17,11 +19,21 @@ const GHOSTTY_ID: &str = "6745981d-da41-4cfd-80ec-95ad339acf6f";
|
||||
const CMUX_ID: &str = "2665bfaa-8251-468d-a710-a4cf34dd81e2";
|
||||
const SPIDER_ID: &str = "eb0cf9d7-6fbd-4b74-9be3-759d6e16f240";
|
||||
|
||||
fn fixture_db() -> Database {
|
||||
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample/bds.db");
|
||||
assert!(path.exists(), "fixture DB not found at {}", path.display());
|
||||
Database::open(&path).unwrap()
|
||||
fn fixture_db() -> support::FixtureDatabase {
|
||||
support::fixture_database()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixture_database_files_are_not_modified_by_tests() {
|
||||
let directory = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample");
|
||||
let paths = ["bds.db", "bds.db-shm", "bds.db-wal"].map(|name| directory.join(name));
|
||||
let before = paths.each_ref().map(|path| fs::read(path).unwrap());
|
||||
|
||||
drop(fixture_db());
|
||||
|
||||
let after = paths.each_ref().map(|path| fs::read(path).unwrap());
|
||||
assert_eq!(after, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Executable checks for storage-related Allium claims.
|
||||
|
||||
mod support;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bds_core::db::Database;
|
||||
use bds_core::db::queries::{
|
||||
@@ -13,12 +14,8 @@ use bds_core::model::{
|
||||
};
|
||||
use diesel::prelude::*;
|
||||
|
||||
fn fixture_db() -> Database {
|
||||
Database::open(
|
||||
&PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample/bds.db"),
|
||||
)
|
||||
.unwrap()
|
||||
fn fixture_db() -> support::FixtureDatabase {
|
||||
support::fixture_database()
|
||||
}
|
||||
|
||||
fn memory_db() -> Database {
|
||||
|
||||
34
crates/bds-core/tests/support/mod.rs
Normal file
34
crates/bds-core/tests/support/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::fs;
|
||||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bds_core::db::Database;
|
||||
use tempfile::TempDir;
|
||||
|
||||
pub struct FixtureDatabase {
|
||||
database: Database,
|
||||
_directory: TempDir,
|
||||
}
|
||||
|
||||
impl Deref for FixtureDatabase {
|
||||
type Target = Database;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.database
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixture_database() -> FixtureDatabase {
|
||||
let source = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../fixtures/compatibility-projects/rfc1437-sample");
|
||||
let directory = TempDir::new().unwrap();
|
||||
|
||||
for name in ["bds.db", "bds.db-shm", "bds.db-wal"] {
|
||||
fs::copy(source.join(name), directory.path().join(name)).unwrap();
|
||||
}
|
||||
|
||||
FixtureDatabase {
|
||||
database: Database::open(&directory.path().join("bds.db")).unwrap(),
|
||||
_directory: directory,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user