diff --git a/Makefile b/Makefile index f51e065..a6db970 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ clippy: cd $(DIR); cargo clippy --all-targets --all-features --workspace -- -D warnings cli-test: - cd $(DIR)/sqlness-cli; cargo run -- -c tests/mysql -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public - cd $(DIR)/sqlness-cli; cargo run -- -c tests/postgresql -i localhost -p 5432 -u postgres -P postgres -d postgres -r postgresql + cd $(DIR)/sqlness-cli; cargo run -- -t mysql -c tests/mysql -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public + cd $(DIR)/sqlness-cli; cargo run -- -t postgresql -c tests/postgresql -i 127.0.0.1 -p 5432 -u postgres -P postgres -d postgres example: good-example bad-example diff --git a/sqlness-cli/src/main.rs b/sqlness-cli/src/main.rs index 7ec7e98..7a1e425 100644 --- a/sqlness-cli/src/main.rs +++ b/sqlness-cli/src/main.rs @@ -1,6 +1,6 @@ // Copyright 2023 CeresDB Project Authors. Licensed under Apache-2.0. -use std::{error::Error, fmt::Display, path::Path}; +use std::{fmt::Display, path::Path}; use async_trait::async_trait; use clap::Parser; @@ -40,8 +40,8 @@ struct Args { db: Option, /// Which DBMS to test against - #[clap(short('r'), long)] - #[arg(value_enum, default_value_t = DBType::Mysql)] + #[clap(short('t'), long("type"))] + #[arg(value_enum, default_value_t)] db_type: DBType, } @@ -64,16 +64,15 @@ impl Database for DBProxy { } impl DBProxy { - pub fn try_new(db_config: DatabaseConfig, db_type: DBType) -> Result> { - let db = match db_type { - DBType::Mysql => { - Box::new(MysqlDatabase::try_new(db_config).expect("build db")) as Box<_> - } + pub fn new(db_config: DatabaseConfig, db_type: DBType) -> Self { + let database: Box = match db_type { + DBType::Mysql => Box::new(MysqlDatabase::try_new(db_config).expect("build mysql db")), DBType::Postgresql => { - Box::new(PostgresqlDatabase::try_new(&db_config).expect("build db")) as Box<_> + Box::new(PostgresqlDatabase::try_new(&db_config).expect("build postgresql db")) } }; - Ok(DBProxy { database: db }) + + DBProxy { database } } } @@ -93,7 +92,7 @@ impl EnvController for CliController { type DB = DBProxy; async fn start(&self, _env: &str, _config: Option<&Path>) -> Self::DB { - DBProxy::try_new(self.db_config.clone(), self.db_type).expect("build db") + DBProxy::new(self.db_config.clone(), self.db_type) } async fn stop(&self, _env: &str, _db: Self::DB) {} @@ -117,8 +116,8 @@ fn main() { .expect("build config"); block_on(async { - let cli = CliController::new(db_config, args.db_type); - let runner = Runner::new(config, cli); + let ctrl = CliController::new(db_config, args.db_type); + let runner = Runner::new(config, ctrl); runner.run().await.expect("run testcase") });