-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support multiple connections (sessions) in a single test file #180
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a22627
generic make connection
BugenZhao 96beaa2
loose bound
BugenZhao dab5c37
better impl and docs
BugenZhao 05eb083
add example
BugenZhao 48925cb
add more comments
BugenZhao d9017b3
add changelog and bump version
BugenZhao 5d9e210
fix dependency version
BugenZhao 8ce8d26
remove MakeWith
BugenZhao ed600a8
refine test
BugenZhao ffd63b6
refactor generic
BugenZhao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
BugenZhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example transaction test? Maybe use Postgres
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, but currently our CI doesn't have Postgres
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's ok even if it's only tested locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an example that basically shows how it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I see it, but I mean a more “real” one 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let's add a comprehensive set of tests for the
engines
crate in the future.