-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple connections (sessions) in a single test file (#…
…180)
- Loading branch information
Showing
23 changed files
with
376 additions
and
82 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
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,8 @@ | ||
[package] | ||
name = "connection" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
sqllogictest = { path = "../../sqllogictest" } |
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,41 @@ | ||
query I | ||
select counter() | ||
---- | ||
1 | ||
|
||
query I | ||
select counter() | ||
---- | ||
2 | ||
|
||
connection another | ||
query I | ||
select counter() | ||
---- | ||
1 | ||
|
||
# `default` is the name of the default connection if not specified | ||
connection default | ||
query I | ||
select counter() | ||
---- | ||
3 | ||
|
||
connection another | ||
query I | ||
select counter() | ||
---- | ||
2 | ||
|
||
# connection names are case sensitive | ||
connection AnOtHeR | ||
query I | ||
select counter() | ||
---- | ||
1 | ||
|
||
# connection only works for one record, the next one will use `default` | ||
query I | ||
select counter() | ||
---- | ||
4 |
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,53 @@ | ||
use std::path::PathBuf; | ||
|
||
use sqllogictest::{DBOutput, DefaultColumnType}; | ||
|
||
pub struct FakeDB { | ||
counter: u64, | ||
} | ||
|
||
impl FakeDB { | ||
#[allow(clippy::unused_async)] | ||
async fn connect() -> Result<Self, FakeDBError> { | ||
Ok(Self { counter: 0 }) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct FakeDBError; | ||
|
||
impl std::fmt::Display for FakeDBError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{self:?}") | ||
} | ||
} | ||
|
||
impl std::error::Error for FakeDBError {} | ||
|
||
impl sqllogictest::DB for FakeDB { | ||
type Error = FakeDBError; | ||
type ColumnType = DefaultColumnType; | ||
|
||
fn run(&mut self, sql: &str) -> Result<DBOutput<Self::ColumnType>, FakeDBError> { | ||
if sql == "select counter()" { | ||
self.counter += 1; | ||
Ok(DBOutput::Rows { | ||
types: vec![DefaultColumnType::Integer], | ||
rows: vec![vec![self.counter.to_string()]], | ||
}) | ||
} else { | ||
Err(FakeDBError) | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut tester = sqllogictest::Runner::new(FakeDB::connect); | ||
|
||
let mut filename = PathBuf::from(file!()); | ||
filename.pop(); | ||
filename.pop(); | ||
filename.push("connection.slt"); | ||
|
||
tester.run_file(filename).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
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
Oops, something went wrong.