Skip to content

Commit

Permalink
modify args option
Browse files Browse the repository at this point in the history
  • Loading branch information
tanruixiang committed Sep 28, 2023
1 parent 668a868 commit 5f867b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ clippy:

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
cd $(DIR)/sqlness-cli; cargo run -- -c tests/postgresql -i localhost -p 5432 -u postgres -P postgres -d postgres -r postgresql

example: good-example bad-example

Expand Down
10 changes: 5 additions & 5 deletions sqlness-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct Args {
db: Option<String>,

/// Which DBMS to test against
#[clap(short, long)]
#[arg(value_enum, default_value_t)]
r#type: DBType,
#[clap(short('r'), long)]
#[arg(value_enum, default_value_t = DBType::Mysql)]
db_type: DBType,
}

#[derive(clap::ValueEnum, Clone, Debug, Default, Copy)]
Expand Down Expand Up @@ -70,7 +70,7 @@ impl DBProxy {
Box::new(MysqlDatabase::try_new(db_config).expect("build db")) as Box<_>
}
DBType::Postgresql => {
Box::new(PostgresqlDatabase::new(&db_config).expect("build db")) as Box<_>
Box::new(PostgresqlDatabase::try_new(&db_config).expect("build db")) as Box<_>
}
};
Ok(DBProxy { database: db })
Expand Down Expand Up @@ -117,7 +117,7 @@ fn main() {
.expect("build config");

block_on(async {
let cli = CliController::new(db_config, args.r#type);
let cli = CliController::new(db_config, args.db_type);
let runner = Runner::new(config, cli);
runner.run().await.expect("run testcase")
});
Expand Down
3 changes: 1 addition & 2 deletions sqlness/src/database_impl/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct PostgresqlDatabase {
}

impl PostgresqlDatabase {
pub fn new(config: &DatabaseConfig) -> Result<Self, postgres::Error> {
pub fn try_new(config: &DatabaseConfig) -> Result<Self, postgres::Error> {
let mut postgres_config = Config::new();
postgres_config
.port(config.tcp_port)
Expand All @@ -29,7 +29,6 @@ impl PostgresqlDatabase {
if let Some(dbname) = &config.db_name {
postgres_config.dbname(dbname);
}

let client = postgres_config.connect(NoTls)?;
Ok(PostgresqlDatabase {
client: Arc::new(Mutex::new(client)),
Expand Down

0 comments on commit 5f867b0

Please sign in to comment.