Skip to content

Commit 90d62ae

Browse files
committed
Store the .sql dump of the database in the repository, rather than the actual database file.
1 parent 0b0227d commit 90d62ae

File tree

6 files changed

+533
-6
lines changed

6 files changed

+533
-6
lines changed

Cargo.lock

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "A Model Context Protocol server for Bear.app"
88
homepage = "https://github.com/jakubadamw/bear-mcp-server"
99
repository = "https://github.com/jakubadamw/bear-mcp-server"
1010
documentation = "https://github.com/jakubadamw/bear-mcp-server"
11+
build = "build.rs"
1112

1213
[dependencies]
1314
anyhow = "1"
@@ -33,3 +34,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3334
[dev-dependencies]
3435
insta = { version = "1", features = ["json"] }
3536
rstest = "0.24"
37+
38+
[build-dependencies]
39+
rusqlite = { version = "0.32", features = ["functions"] }

build.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use rusqlite::Connection;
2+
3+
use std::path::Path;
4+
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
6+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?;
7+
let sql_path = Path::new(&manifest_dir)
8+
.join("test_data")
9+
.join("database.sql");
10+
println!("cargo:rerun-if-changed={}", sql_path.display());
11+
12+
let sql = std::fs::read_to_string(&sql_path)?;
13+
14+
let out_dir_path = std::env::var("OUT_DIR")?;
15+
let database_path = std::path::Path::new(&out_dir_path).join("test_database.sqlite");
16+
17+
if database_path.exists() {
18+
std::fs::remove_file(&database_path)?;
19+
}
20+
21+
let connection = Connection::open(&database_path)?;
22+
connection.execute_batch(&sql)?;
23+
24+
println!(
25+
"cargo:rustc-env=TEST_DATABASE_PATH={}",
26+
database_path.display()
27+
);
28+
29+
Ok(())
30+
}

src/tests.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ async fn test_list_notes(
1414
#[case] query: Option<&str>,
1515
#[case] tag: Option<&str>,
1616
) {
17-
let path = PathBuf::from(env!("CARGO_MANIFEST_PATH"))
18-
.parent()
19-
.expect("must have a parent")
20-
.join("test_data")
21-
.join("database.sqlite");
17+
let path = PathBuf::from(env!("OUT_DIR")).join("test_database.sqlite");
2218

2319
let bear_database = BearDatabase::new(path).await.expect("must succeed");
2420
let result = bear_database

0 commit comments

Comments
 (0)