-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 'sqlness-cli' to run sqlness in blackbox mode
- Loading branch information
Showing
10 changed files
with
230 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "sqlness-cli" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
async-trait = "0.1" | ||
clap = { version = "4.0", features = ["derive"] } | ||
client = { workspace = true } | ||
sqlness = { version = "0.5" } | ||
sqlness-util = { workspace = true } | ||
tokio.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::fmt::Display; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::exit; | ||
|
||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use client::{Client, Database as DB, DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; | ||
use sqlness::{ConfigBuilder, Database, EnvController, QueryContext, Runner}; | ||
use tokio::sync::Mutex as TokioMutex; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, version, about, long_about = None)] | ||
/// A cli to run sqlness tests. | ||
struct Args { | ||
/// Directory of test cases | ||
#[clap(short, long)] | ||
case_dir: Option<PathBuf>, | ||
|
||
/// Fail this run as soon as one case fails if true | ||
#[arg(short, long, default_value = "false")] | ||
fail_fast: bool, | ||
|
||
/// Name of test cases to run. Accept as a regexp. | ||
#[clap(short, long, default_value = ".*")] | ||
test_filter: String, | ||
|
||
/// Address of the server | ||
#[clap(short, long, default_value = "127.0.0.1:4001")] | ||
server_addr: String, | ||
} | ||
|
||
pub struct GreptimeDB { | ||
client: TokioMutex<DB>, | ||
} | ||
|
||
#[async_trait] | ||
impl Database for GreptimeDB { | ||
async fn query(&self, ctx: QueryContext, query: String) -> Box<dyn Display> { | ||
sqlness_util::do_query(ctx, self.client.lock().await, query).await | ||
} | ||
} | ||
|
||
pub struct CliController { | ||
server_addr: String, | ||
} | ||
|
||
impl CliController { | ||
pub fn new(server_addr: String) -> Self { | ||
Self { server_addr } | ||
} | ||
|
||
async fn connect(&self) -> GreptimeDB { | ||
let client = Client::with_urls(vec![self.server_addr.clone()]); | ||
let db = DB::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, client); | ||
|
||
GreptimeDB { | ||
client: TokioMutex::new(db), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl EnvController for CliController { | ||
type DB = GreptimeDB; | ||
|
||
async fn start(&self, mode: &str, _config: Option<&Path>) -> Self::DB { | ||
match mode { | ||
"standalone" => self.connect().await, | ||
"distributed" => self.connect().await, | ||
_ => panic!("Unexpected mode: {mode}"), | ||
} | ||
} | ||
|
||
async fn stop(&self, _mode: &str, _database: Self::DB) {} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let args = Args::parse(); | ||
let config = ConfigBuilder::default() | ||
.case_dir(sqlness_util::get_case_dir(args.case_dir)) | ||
.fail_fast(args.fail_fast) | ||
.test_filter(args.test_filter) | ||
.follow_links(true) | ||
.build() | ||
.unwrap(); | ||
let runner = Runner::new(config, CliController::new(args.server_addr)); | ||
runner.run().await.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "sqlness-util" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
client = { workspace = true } | ||
common-error = { workspace = true } | ||
common-query = { workspace = true } | ||
common-recordbatch = { workspace = true } | ||
sqlness = { version = "0.5" } | ||
tokio.workspace = true |
Oops, something went wrong.