Skip to content

Commit

Permalink
chore: fix and prevent clippy warnings on main (#4694)
Browse files Browse the repository at this point in the history
- Fix all clippy warnings in tests using `cargo clippy --fix
  --all-targets` (nothing required manual action).

- Change the `clippy` command in the GitHub Actions pipeline to check
  the whole codebase.
  • Loading branch information
aqrln authored Feb 6, 2024
1 parent 16a6fe5 commit 2b2cf0b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ jobs:
with:
components: clippy
targets: wasm32-unknown-unknown
# Check the whole workspace with clippy for the native compilation
# target, and query-engine-wasm and dependencies for wasm32-unknown-unknown.
# Note that `--all-targets` is unrelated to `--target` as in target platform,
# it is a shortcut for `--lib --bins --tests --benches --examples`.
- run: |
cargo clippy --all-features
cargo clippy --all-features -p query-engine-wasm --target wasm32-unknown-unknown
cargo clippy --workspace --all-features --all-targets
cargo clippy --all-features --all-targets -p query-engine-wasm --target wasm32-unknown-unknown
rustfmt:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod transactional {
];

let batch_results = runner.batch(queries, true, None).await?;
let batch_request_idx = batch_results.errors().get(0).unwrap().batch_request_idx();
let batch_request_idx = batch_results.errors().first().unwrap().batch_request_idx();

assert_eq!(batch_request_idx, Some(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ mod scalar_relations {

async fn create_common_children(runner: &Runner) -> TestResult<()> {
create_child(
&runner,
runner,
r#"{
childId: 1,
string: "abc",
Expand All @@ -291,7 +291,7 @@ mod scalar_relations {
.await?;

create_child(
&runner,
runner,
r#"{
childId: 2,
string: "def",
Expand All @@ -306,7 +306,7 @@ mod scalar_relations {
.await?;

create_parent(
&runner,
runner,
r#"{ id: 1, children: { connect: [{ childId: 1 }, { childId: 2 }] } }"#,
)
.await?;
Expand Down
76 changes: 38 additions & 38 deletions schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,44 +454,6 @@ fn check_datamodel_for_mysql_5_6(datamodel: &ValidatedSchema, errors: &mut Vec<S
});
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn debug_impl_does_not_leak_connection_info() {
let url = "mysql://myname:mypassword@myserver:8765/mydbname";

let mut flavour = MysqlFlavour::default();
let params = ConnectorParams {
connection_string: url.to_owned(),
preview_features: Default::default(),
shadow_database_connection_string: None,
};
flavour.set_params(params).unwrap();
let debugged = format!("{flavour:?}");

let words = &["myname", "mypassword", "myserver", "8765", "mydbname"];

for word in words {
assert!(!debugged.contains(word));
}
}

#[test]
fn qualified_name_re_matches_as_expected() {
let should_match = r#"ALTER TABLE `mydb`.`cat` DROP PRIMARY KEY"#;
let should_not_match = r#"ALTER TABLE `cat` ADD FOREIGN KEY (`ab`, cd`) REFERENCES `dog`(`id`)"#;

assert!(
QUALIFIED_NAME_RE.is_match_at(should_match, 12),
"captures: {:?}",
QUALIFIED_NAME_RE.captures(should_match)
);
assert!(!QUALIFIED_NAME_RE.is_match(should_not_match));
}
}

fn with_connection<'a, O, F, C>(state: &'a mut State, f: C) -> BoxFuture<'a, ConnectorResult<O>>
where
O: 'a,
Expand Down Expand Up @@ -600,3 +562,41 @@ fn scan_migration_script_impl(script: &str) {
fn is_planetscale(connection_string: &str) -> bool {
connection_string.contains(".psdb.cloud")
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn debug_impl_does_not_leak_connection_info() {
let url = "mysql://myname:mypassword@myserver:8765/mydbname";

let mut flavour = MysqlFlavour::default();
let params = ConnectorParams {
connection_string: url.to_owned(),
preview_features: Default::default(),
shadow_database_connection_string: None,
};
flavour.set_params(params).unwrap();
let debugged = format!("{flavour:?}");

let words = &["myname", "mypassword", "myserver", "8765", "mydbname"];

for word in words {
assert!(!debugged.contains(word));
}
}

#[test]
fn qualified_name_re_matches_as_expected() {
let should_match = r#"ALTER TABLE `mydb`.`cat` DROP PRIMARY KEY"#;
let should_not_match = r#"ALTER TABLE `cat` ADD FOREIGN KEY (`ab`, cd`) REFERENCES `dog`(`id`)"#;

assert!(
QUALIFIED_NAME_RE.is_match_at(should_match, 12),
"captures: {:?}",
QUALIFIED_NAME_RE.captures(should_match)
);
assert!(!QUALIFIED_NAME_RE.is_match(should_not_match));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ fn decimal_to_boolean_migrations_work(api: TestApi) {
}
"#;

api.create_migration("create-cats-decimal", &dm1, &dir)
api.create_migration("create-cats-decimal", dm1, &dir)
.send_sync()
.assert_migration_directories_count(1)
.assert_migration("create-cats-decimal", move |migration| {
Expand Down Expand Up @@ -497,7 +497,7 @@ fn decimal_to_boolean_migrations_work(api: TestApi) {
}
"#;

api.create_migration("migrate-cats-boolean", &dm2, &dir)
api.create_migration("migrate-cats-boolean", dm2, &dir)
.send_sync()
.assert_migration_directories_count(2)
.assert_migration("migrate-cats-boolean", move |migration| {
Expand Down
2 changes: 1 addition & 1 deletion schema-engine/sql-schema-describer/tests/test_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use expect_test::expect;
pub use indoc::{formatdoc, indoc};
pub use quaint::{prelude::Queryable, single::Quaint};
pub use test_macros::test_connector;
pub use test_setup::{runtime::run_with_thread_local_runtime as tok, BitFlags, Capabilities, Tags};
pub use test_setup::{runtime::run_with_thread_local_runtime as tok, BitFlags, Tags};

use quaint::prelude::SqlFamily;
use sql_schema_describer::{
Expand Down

0 comments on commit 2b2cf0b

Please sign in to comment.