Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod test_config {
use super::*;

#[test]
fn test_load_cfg_full() {
fn load_cfg_full() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
pg_version = "19.1"
Expand All @@ -117,7 +117,7 @@ assume_in_transaction = true
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_pg_version() {
fn load_pg_version() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
pg_version = "19.1"
Expand All @@ -127,7 +127,7 @@ pg_version = "19.1"
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_excluded_rules() {
fn load_excluded_rules() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
excluded_rules = ["require-concurrent-index-creation"]
Expand All @@ -137,7 +137,7 @@ excluded_rules = ["require-concurrent-index-creation"]
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_excluded_paths() {
fn load_excluded_paths() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
excluded_paths = ["example.sql"]
Expand All @@ -147,7 +147,7 @@ excluded_paths = ["example.sql"]
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_assume_in_transaction() {
fn load_assume_in_transaction() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r"
assume_in_transaction = false
Expand All @@ -157,7 +157,7 @@ assume_in_transaction = false
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_fail_on_violations() {
fn load_fail_on_violations() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r"
[upload_to_github]
Expand Down
20 changes: 10 additions & 10 deletions cli/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ mod test_github_comment {
/// Most cases, hopefully, will be a single migration for a given PR, but
/// let's check the case of multiple migrations
#[test]
fn test_generating_comment_multiple_files() {
fn generating_comment_multiple_files() {
let violations = vec![ViolationContent {
filename: "alpha.sql".into(),
sql: r"
Expand Down Expand Up @@ -588,7 +588,7 @@ SELECT 1;
/// Even when we don't have violations we still want to output the SQL for
/// easy human reading.
#[test]
fn test_generating_comment_no_violations() {
fn generating_comment_no_violations() {
let violations = vec![
ViolationContent {
filename: "alpha.sql".into(),
Expand Down Expand Up @@ -623,7 +623,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
/// Ideally the logic won't leave a comment when there are no migrations but
/// better safe than sorry
#[test]
fn test_generating_no_violations_no_files() {
fn generating_no_violations_no_files() {
let violations = vec![];

let body = get_comment_body(&violations, "0.2.3");
Expand All @@ -642,7 +642,7 @@ mod test_check_files {
use super::process_violations;

#[test]
fn test_check_files_invalid_syntax() {
fn check_files_invalid_syntax() {
let sql = r"
select \;
";
Expand Down Expand Up @@ -672,7 +672,7 @@ mod test_reporter {
}

#[test]
fn test_display_violations_gcc() {
fn display_violations_gcc() {
let sql = r#"
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
Expand All @@ -698,7 +698,7 @@ SELECT 1;
}

#[test]
fn test_display_violations_tty() {
fn display_violations_tty() {
let sql = r#"
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
Expand All @@ -719,7 +719,7 @@ SELECT 1;
assert_display_snapshot!(strip_ansi_codes(&String::from_utf8_lossy(&buff)));
}
#[test]
fn test_display_no_violations_tty() {
fn display_no_violations_tty() {
let mut buff = Vec::new();

let res = print_violations(
Expand All @@ -734,7 +734,7 @@ SELECT 1;
}

#[test]
fn test_display_violations_json() {
fn display_violations_json() {
let sql = r#"
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
Expand All @@ -757,7 +757,7 @@ SELECT 1;
}

#[test]
fn test_span_offsets() {
fn span_offsets() {
let sql = r#"

ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
Expand All @@ -773,7 +773,7 @@ SELECT 1;
/// `pretty_violations` was slicing the SQL improperly, trimming off the first
/// letter.
#[test]
fn test_trimming_sql_newlines() {
fn trimming_sql_newlines() {
let sql = r#"ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;"#;
let violations = lint_sql(sql);

Expand Down
8 changes: 4 additions & 4 deletions linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ mod test_rules {
}
/// Ensure we handle both serializing and deserializing `RuleViolationKind`
#[test]
fn test_parsing_rule_kind() {
fn parsing_rule_kind() {
let rule_names = RULES.iter().map(|r| r.name.clone());
for rule in rule_names {
let rule_str = rule.to_string();
Expand All @@ -435,19 +435,19 @@ mod test_rules {
}
/// Ensure rule names don't change
#[test]
fn test_rule_names_debug_snap() {
fn rule_names_debug_snap() {
let rule_names: Vec<String> = RULES.iter().map(|r| r.name.to_string()).collect();
assert_debug_snapshot!(rule_names);
}
#[test]
fn test_rule_names_display_snap() {
fn rule_names_display_snap() {
let rule_names: Vec<String> = RULES.iter().map(|r| r.name.to_string()).collect();
assert_display_snapshot!(rule_names.join("\n"));
}

/// Ensure we stort the resulting violations by where they occur in the file.
#[test]
fn test_check_rules_orderin() {
fn check_rules_orderin() {
let sql = r#"
ALTER TABLE "table_name" RENAME COLUMN "column_name" TO "new_column_name";
CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
Expand Down
28 changes: 14 additions & 14 deletions linter/src/rules/adding_field_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ mod test_rules {
/// -- remove nullability
/// ```
#[test]
fn test_docs_example_bad() {
fn docs_example_bad() {
let bad_sql = r#"
-- instead of
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
"#;
assert_debug_snapshot!(lint_sql(bad_sql, None));
}
#[test]
fn test_docs_example_ok() {
fn docs_example_ok() {
let ok_sql = r#"
-- use
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer;
Expand All @@ -151,7 +151,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
}

#[test]
fn test_default_integer_ok() {
fn default_integer_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
Expand All @@ -162,7 +162,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
}

#[test]
fn test_default_uuid_err() {
fn default_uuid_err() {
let bad_sql = r#"
-- VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
Expand All @@ -173,7 +173,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
}

#[test]
fn test_default_volatile_func_err() {
fn default_volatile_func_err() {
let bad_sql = r#"
-- VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
Expand All @@ -182,7 +182,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
assert_debug_snapshot!(lint_sql(bad_sql, pg_version_11));
}
#[test]
fn test_default_bool_ok() {
fn default_bool_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
Expand All @@ -191,7 +191,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_str_ok() {
fn default_str_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
Expand All @@ -200,7 +200,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_enum_ok() {
fn default_enum_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-variant';
Expand All @@ -209,7 +209,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-varia
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_jsonb_ok() {
fn default_jsonb_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
Expand All @@ -218,7 +218,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_arbitrary_func_err() {
fn default_arbitrary_func_err() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
Expand All @@ -227,7 +227,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_random_with_args_err() {
fn default_random_with_args_err() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
Expand All @@ -236,7 +236,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_default_now_func_ok() {
fn default_now_func_ok() {
let ok_sql = r#"
-- NON-VOLATILE
ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
Expand All @@ -245,7 +245,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
#[test]
fn test_add_numbers_ok() {
fn add_numbers_ok() {
// This should be okay, but we don't handle expressions like this at the moment.
let ok_sql = r"
alter table account_metadata add column blah integer default 2 + 2;
Expand All @@ -255,7 +255,7 @@ alter table account_metadata add column blah integer default 2 + 2;
}

#[test]
fn test_generated_stored() {
fn generated_stored() {
let bad_sql = r"
ALTER TABLE foo
ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;
Expand Down
8 changes: 4 additions & 4 deletions linter/src/rules/adding_foreign_key_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test_rules {
}

#[test]
fn test_create_table_with_foreign_key_constraint() {
fn create_table_with_foreign_key_constraint() {
let sql = r#"
BEGIN;
CREATE TABLE email (
Expand All @@ -104,7 +104,7 @@ COMMIT;
assert_eq!(violations.len(), 0);
}
#[test]
fn test_add_foreign_key_constraint_not_valid_validate() {
fn add_foreign_key_constraint_not_valid_validate() {
let sql = r#"
BEGIN;
ALTER TABLE "email" ADD COLUMN "user_id" INT;
Expand All @@ -117,7 +117,7 @@ COMMIT;
assert_eq!(violations.len(), 0);
}
#[test]
fn test_add_foreign_key_constraint_lock() {
fn add_foreign_key_constraint_lock() {
let sql = r#"
BEGIN;
ALTER TABLE "email" ADD COLUMN "user_id" INT;
Expand All @@ -133,7 +133,7 @@ COMMIT;
);
}
#[test]
fn test_add_column_references_lock() {
fn add_column_references_lock() {
let sql = r#"
BEGIN;
ALTER TABLE "emails" ADD COLUMN "user_id" INT REFERENCES "user" ("id");
Expand Down
8 changes: 4 additions & 4 deletions linter/src/rules/adding_not_null_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ mod test_rules {
use insta::assert_debug_snapshot;

#[test]
fn test_set_not_null() {
fn set_not_null() {
let sql = r#"
ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL;
"#;
assert_debug_snapshot!(lint_sql(sql, None));
}

#[test]
fn test_adding_field_that_is_not_nullable() {
fn adding_field_that_is_not_nullable() {
let ok_sql = r#"
BEGIN;
-- This will cause a table rewrite for Postgres versions before 11, but that is handled by
Expand All @@ -84,7 +84,7 @@ COMMIT;
}

#[test]
fn test_adding_field_that_is_not_nullable_without_default() {
fn adding_field_that_is_not_nullable_without_default() {
let ok_sql = r#"
-- This won't work if the table is populated, but that error is caught by adding-required-field.
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
Expand All @@ -93,7 +93,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
}

#[test]
fn test_adding_field_that_is_not_nullable_in_version_11() {
fn adding_field_that_is_not_nullable_in_version_11() {
let ok_sql = r#"
BEGIN;
--
Expand Down
4 changes: 2 additions & 2 deletions linter/src/rules/adding_primary_key_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod test_rules {
}

#[test]
fn test_serial_primary_key() {
fn serial_primary_key() {
let bad_sql = r"
ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
";
Expand All @@ -86,7 +86,7 @@ ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
}

#[test]
fn test_plain_primary_key() {
fn plain_primary_key() {
let bad_sql = r"
ALTER TABLE items ADD PRIMARY KEY (id);
";
Expand Down
Loading
Loading