Skip to content

Commit f895ff9

Browse files
committed
fix: properly canonicalize config path for sqlx mig add test
1 parent 0ffc8df commit f895ff9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

sqlx-cli/tests/add.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use assert_cmd::Command;
23
use std::cmp::Ordering;
34
use std::fs::read_dir;
@@ -94,9 +95,18 @@ impl AddMigrations {
9495
})
9596
}
9697

97-
fn with_config(mut self, path: &str) -> Self {
98+
fn with_config(mut self, filename: &str) -> anyhow::Result<Self> {
99+
let path = format!("sqlx-cli/tests/assets/{filename}");
100+
101+
let path = std::fs::canonicalize(&path)
102+
.with_context(|| format!("error canonicalizing path {path:?}"))?;
103+
104+
let path = path
105+
.to_str()
106+
.with_context(|| format!("canonicalized version of path {path:?} is not UTF-8"))?;
107+
98108
self.config_arg = Some(format!("--config={path}"));
99-
self
109+
Ok(self)
100110
}
101111

102112
fn run(
@@ -311,7 +321,7 @@ fn add_migration_timestamp_reversible() -> anyhow::Result<()> {
311321
#[test]
312322
fn add_migration_config_default_type_reversible() -> anyhow::Result<()> {
313323
let files = AddMigrations::new()?
314-
.with_config("sqlx-cli/tests/assets/config_default_type_reversible.toml")
324+
.with_config("config_default_type_reversible.toml")?
315325
// Type should default to reversible without any flags
316326
.run("hello world", false, false, false, true)?
317327
.run("hello world2", false, false, false, true)?
@@ -331,7 +341,7 @@ fn add_migration_config_default_type_reversible() -> anyhow::Result<()> {
331341
#[test]
332342
fn add_migration_config_default_versioning_sequential() -> anyhow::Result<()> {
333343
let files = AddMigrations::new()?
334-
.with_config("sqlx-cli/tests/assets/config_default_versioning_sequential.toml")
344+
.with_config("config_default_versioning_sequential.toml")?
335345
// Versioning should default to timestamp without any flags
336346
.run("hello world", false, false, false, true)?
337347
.run("hello world2", false, false, false, true)?
@@ -368,8 +378,7 @@ fn add_migration_config_default_versioning_timestamp() -> anyhow::Result<()> {
368378
assert_eq!(files[2].id, 3);
369379

370380
// Now set a config that uses `default-versioning = "timestamp"`
371-
let migrations =
372-
migrations.with_config("sqlx-cli/tests/assets/config_default_versioning_timestamp.toml");
381+
let migrations = migrations.with_config("config_default_versioning_timestamp.toml")?;
373382

374383
// Now the default should be a timestamp
375384
migrations

0 commit comments

Comments
 (0)