Skip to content

Commit

Permalink
tweak: Refine rust in integration tests (#4683)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jul 1, 2024
1 parent f32c97d commit d3ed63e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
3 changes: 2 additions & 1 deletion prqlc/prqlc/tests/integration/dbs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl DbConnection {
})
}

pub fn setup(&mut self) {
pub fn setup(mut self) -> Self {
let schema = include_str!("../data/chinook/schema.sql");
schema
.split(';')
Expand All @@ -92,6 +92,7 @@ impl DbConnection {
let path = format!("{}/{}.csv", self.cfg.data_file_root, stem);
self.runner.import_csv(&mut *self.protocol, &path, stem);
}
self
}

// If it's supported, test unless it has `duckdb:skip`. If it's not
Expand Down
35 changes: 13 additions & 22 deletions prqlc/prqlc/tests/integration/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod results {
static CONNECTIONS: OnceLock<Mutex<Vec<DbConnection>>> = OnceLock::new();
CONNECTIONS.get_or_init(|| {
Mutex::new({
let configs = [
[
ConnectionCfg {
dialect: Dialect::SQLite,
data_file_root: "tests/integration/data/chinook".to_string(),
Expand Down Expand Up @@ -155,29 +155,20 @@ mod results {

protocol: DbProtocol::MsSql,
},
];

let mut connections = Vec::new();
for cfg in configs {
if !matches!(
]
.into_iter()
.filter(|cfg| {
matches!(
cfg.dialect.support_level(),
SupportLevel::Supported | SupportLevel::Unsupported
) {
continue;
}

// The filtering is not a great design, since it doesn't proactively
// check that we can get connections; but it's a compromise given we
// implement the external_dbs feature using this.
let Some(mut connection) = DbConnection::new(cfg) else {
continue;
};

connection.setup();

connections.push(connection);
}
connections
)
})
// The filtering is not a great design, since it doesn't proactively
// check that we can get connections; but it's a compromise given we
// implement the external_dbs feature using this.
.filter_map(DbConnection::new)
.map(|conn| conn.setup())
.collect()
})
})
}
Expand Down

0 comments on commit d3ed63e

Please sign in to comment.