Skip to content

Commit 3cade6f

Browse files
Fix tests
1 parent 77fd5db commit 3cade6f

5 files changed

Lines changed: 94 additions & 13 deletions

File tree

src/config.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ pub struct AppConfig {
175175
#[cfg(feature = "http")]
176176
#[serde(default)]
177177
pub http_server: HttpServerConfig,
178-
#[serde(default = "defaul_file_cache_dir")]
179-
pub db_dir: PathBuf,
178+
#[serde(default = "default_db_config")]
179+
pub db: DbConfig,
180180
}
181181

182182
fn default_execution_config() -> ExecutionConfig {
@@ -191,7 +191,25 @@ fn default_interaction_config() -> InteractionConfig {
191191
InteractionConfig::default()
192192
}
193193

194-
fn defaul_file_cache_dir() -> PathBuf {
194+
#[derive(Debug, Clone, Deserialize)]
195+
pub struct DbConfig {
196+
#[serde(default = "default_db_path")]
197+
pub path: PathBuf,
198+
}
199+
200+
impl Default for DbConfig {
201+
fn default() -> Self {
202+
default_db_config()
203+
}
204+
}
205+
206+
fn default_db_config() -> DbConfig {
207+
DbConfig {
208+
path: default_db_path(),
209+
}
210+
}
211+
212+
fn default_db_path() -> PathBuf {
195213
let base = directories::BaseDirs::new().expect("Base directories should be available");
196214
base.data_dir().to_path_buf().join("dft")
197215
}

src/tpch.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ impl TryFrom<&str> for GeneratorType {
6666
}
6767

6868
fn create_tpch_dirs(config: &AppConfig) -> Result<Vec<(GeneratorType, PathBuf)>> {
69-
info!("...configured `db_dir` is {:?}", config.db_dir);
70-
if config.db_dir.is_file() {
71-
eyre::bail!("config `db_path` is a file and it must be a dir")
69+
info!("...configured DB directory is {:?}", config.db.path);
70+
if config.db.path.is_file() {
71+
eyre::bail!("config DB directory is a file and it must be a directory")
7272
}
7373

74-
if !config.db_dir.exists() {
75-
info!("...`db_dir` does not exist, creating");
76-
std::fs::create_dir_all(config.db_dir.clone())?;
74+
if !config.db.path.exists() {
75+
info!("...DB directory does not exist, creating");
76+
std::fs::create_dir_all(config.db.path.clone())?;
7777
} else {
78-
info!("...`db_dir` exists");
78+
info!("...DB directory exists");
7979
}
80-
let tpch_dir = config.db_dir.join("tables").join("tpch");
80+
let tpch_dir = config.db.path.join("tables").join("tpch");
8181
if !tpch_dir.exists() {
8282
info!(
8383
"...TPC-H table directory ({:?}) does not exist, creating",
84-
config.db_dir
84+
config.db.path
8585
);
8686
create_dir_all(&tpch_dir)?;
8787
} else {

tests/cli_cases/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
mod basic;
1919
mod bench;
2020
mod config;
21+
mod tpch;
2122

2223
use assert_cmd::Command;
2324
use predicates::str::ContainsPredicate;

tests/cli_cases/tpch.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Tests for the CLI (e.g. run from files) to make sure config works as expected
19+
20+
use std::fs::DirEntry;
21+
22+
use crate::config::TestConfigBuilder;
23+
use assert_cmd::Command;
24+
25+
#[test]
26+
fn test_custom_config() {
27+
let tempdir = tempfile::tempdir().unwrap();
28+
let db_path = tempdir.path().join("db");
29+
std::fs::create_dir_all(&db_path).unwrap();
30+
let mut config_builder = TestConfigBuilder::default();
31+
config_builder.with_db_path(db_path.to_str().unwrap());
32+
let config = config_builder.build("my_config.toml");
33+
34+
Command::cargo_bin("dft")
35+
.unwrap()
36+
.arg("--config")
37+
.arg(config.path)
38+
.arg("generate-tpch")
39+
.assert()
40+
.success();
41+
42+
let needed_dirs = [
43+
"customers",
44+
"orders",
45+
"line_items",
46+
"nations",
47+
"parts",
48+
"part_supps",
49+
"regions",
50+
"suppliers",
51+
];
52+
let tables_path = db_path.join("tables").join("tpch");
53+
std::fs::read_dir(tables_path).unwrap().for_each(|e| {
54+
let entry = e.unwrap();
55+
assert!(needed_dirs.contains(&entry.file_name().to_str().unwrap()));
56+
let data = entry.path().join("data.parquet");
57+
assert!(data.exists());
58+
let metadata = data.metadata().unwrap();
59+
assert!(metadata.len() > 1000);
60+
})
61+
}

tests/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ impl TestConfigBuilder {
227227
}
228228

229229
pub fn with_db_path(&mut self, path: &str) -> &mut Self {
230-
self.config_text.push_str(&format!("db_dir = {path}\n"));
230+
self.config_text.push_str("[db]\n");
231+
self.config_text.push_str(&format!("path = \"{path}\""));
231232
self
232233
}
233234
}

0 commit comments

Comments
 (0)