Skip to content

Commit 283a3b2

Browse files
authored
tests: refactor names to not prefix with test_ (#410)
``` fastmod --fixed-strings 'fn test_' 'fn ' --extensions rs ``` ideally we'd have a lint
1 parent ea24ec5 commit 283a3b2

File tree

39 files changed

+374
-242
lines changed

39 files changed

+374
-242
lines changed

cli/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mod test_config {
104104
use super::*;
105105

106106
#[test]
107-
fn test_load_cfg_full() {
107+
fn load_cfg_full() {
108108
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
109109
let file = r#"
110110
pg_version = "19.1"
@@ -117,7 +117,7 @@ assume_in_transaction = true
117117
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
118118
}
119119
#[test]
120-
fn test_load_pg_version() {
120+
fn load_pg_version() {
121121
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
122122
let file = r#"
123123
pg_version = "19.1"
@@ -127,7 +127,7 @@ pg_version = "19.1"
127127
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
128128
}
129129
#[test]
130-
fn test_load_excluded_rules() {
130+
fn load_excluded_rules() {
131131
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
132132
let file = r#"
133133
excluded_rules = ["require-concurrent-index-creation"]
@@ -137,7 +137,7 @@ excluded_rules = ["require-concurrent-index-creation"]
137137
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
138138
}
139139
#[test]
140-
fn test_load_excluded_paths() {
140+
fn load_excluded_paths() {
141141
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
142142
let file = r#"
143143
excluded_paths = ["example.sql"]
@@ -147,7 +147,7 @@ excluded_paths = ["example.sql"]
147147
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
148148
}
149149
#[test]
150-
fn test_load_assume_in_transaction() {
150+
fn load_assume_in_transaction() {
151151
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
152152
let file = r"
153153
assume_in_transaction = false
@@ -157,7 +157,7 @@ assume_in_transaction = false
157157
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
158158
}
159159
#[test]
160-
fn test_load_fail_on_violations() {
160+
fn load_fail_on_violations() {
161161
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
162162
let file = r"
163163
[upload_to_github]

cli/src/reporter.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ mod test_github_comment {
556556
/// Most cases, hopefully, will be a single migration for a given PR, but
557557
/// let's check the case of multiple migrations
558558
#[test]
559-
fn test_generating_comment_multiple_files() {
559+
fn generating_comment_multiple_files() {
560560
let violations = vec![ViolationContent {
561561
filename: "alpha.sql".into(),
562562
sql: r"
@@ -588,7 +588,7 @@ SELECT 1;
588588
/// Even when we don't have violations we still want to output the SQL for
589589
/// easy human reading.
590590
#[test]
591-
fn test_generating_comment_no_violations() {
591+
fn generating_comment_no_violations() {
592592
let violations = vec![
593593
ViolationContent {
594594
filename: "alpha.sql".into(),
@@ -623,7 +623,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
623623
/// Ideally the logic won't leave a comment when there are no migrations but
624624
/// better safe than sorry
625625
#[test]
626-
fn test_generating_no_violations_no_files() {
626+
fn generating_no_violations_no_files() {
627627
let violations = vec![];
628628

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

644644
#[test]
645-
fn test_check_files_invalid_syntax() {
645+
fn check_files_invalid_syntax() {
646646
let sql = r"
647647
select \;
648648
";
@@ -672,7 +672,7 @@ mod test_reporter {
672672
}
673673

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

700700
#[test]
701-
fn test_display_violations_tty() {
701+
fn display_violations_tty() {
702702
let sql = r#"
703703
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
704704
ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
@@ -719,7 +719,7 @@ SELECT 1;
719719
assert_display_snapshot!(strip_ansi_codes(&String::from_utf8_lossy(&buff)));
720720
}
721721
#[test]
722-
fn test_display_no_violations_tty() {
722+
fn display_no_violations_tty() {
723723
let mut buff = Vec::new();
724724

725725
let res = print_violations(
@@ -734,7 +734,7 @@ SELECT 1;
734734
}
735735

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

759759
#[test]
760-
fn test_span_offsets() {
760+
fn span_offsets() {
761761
let sql = r#"
762762
763763
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
@@ -773,7 +773,7 @@ SELECT 1;
773773
/// `pretty_violations` was slicing the SQL improperly, trimming off the first
774774
/// letter.
775775
#[test]
776-
fn test_trimming_sql_newlines() {
776+
fn trimming_sql_newlines() {
777777
let sql = r#"ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;"#;
778778
let violations = lint_sql(sql);
779779

linter/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ mod test_rules {
425425
}
426426
/// Ensure we handle both serializing and deserializing `RuleViolationKind`
427427
#[test]
428-
fn test_parsing_rule_kind() {
428+
fn parsing_rule_kind() {
429429
let rule_names = RULES.iter().map(|r| r.name.clone());
430430
for rule in rule_names {
431431
let rule_str = rule.to_string();
@@ -435,19 +435,19 @@ mod test_rules {
435435
}
436436
/// Ensure rule names don't change
437437
#[test]
438-
fn test_rule_names_debug_snap() {
438+
fn rule_names_debug_snap() {
439439
let rule_names: Vec<String> = RULES.iter().map(|r| r.name.to_string()).collect();
440440
assert_debug_snapshot!(rule_names);
441441
}
442442
#[test]
443-
fn test_rule_names_display_snap() {
443+
fn rule_names_display_snap() {
444444
let rule_names: Vec<String> = RULES.iter().map(|r| r.name.to_string()).collect();
445445
assert_display_snapshot!(rule_names.join("\n"));
446446
}
447447

448448
/// Ensure we stort the resulting violations by where they occur in the file.
449449
#[test]
450-
fn test_check_rules_orderin() {
450+
fn check_rules_orderin() {
451451
let sql = r#"
452452
ALTER TABLE "table_name" RENAME COLUMN "column_name" TO "new_column_name";
453453
CREATE INDEX "field_name_idx" ON "table_name" ("field_name");

linter/src/rules/adding_field_with_default.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ mod test_rules {
131131
/// -- remove nullability
132132
/// ```
133133
#[test]
134-
fn test_docs_example_bad() {
134+
fn docs_example_bad() {
135135
let bad_sql = r#"
136136
-- instead of
137137
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
138138
"#;
139139
assert_debug_snapshot!(lint_sql(bad_sql, None));
140140
}
141141
#[test]
142-
fn test_docs_example_ok() {
142+
fn docs_example_ok() {
143143
let ok_sql = r#"
144144
-- use
145145
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer;
@@ -151,7 +151,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
151151
}
152152

153153
#[test]
154-
fn test_default_integer_ok() {
154+
fn default_integer_ok() {
155155
let ok_sql = r#"
156156
-- NON-VOLATILE
157157
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
@@ -162,7 +162,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
162162
}
163163

164164
#[test]
165-
fn test_default_uuid_err() {
165+
fn default_uuid_err() {
166166
let bad_sql = r#"
167167
-- VOLATILE
168168
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
@@ -173,7 +173,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
173173
}
174174

175175
#[test]
176-
fn test_default_volatile_func_err() {
176+
fn default_volatile_func_err() {
177177
let bad_sql = r#"
178178
-- VOLATILE
179179
ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
@@ -182,7 +182,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
182182
assert_debug_snapshot!(lint_sql(bad_sql, pg_version_11));
183183
}
184184
#[test]
185-
fn test_default_bool_ok() {
185+
fn default_bool_ok() {
186186
let ok_sql = r#"
187187
-- NON-VOLATILE
188188
ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
@@ -191,7 +191,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
191191
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
192192
}
193193
#[test]
194-
fn test_default_str_ok() {
194+
fn default_str_ok() {
195195
let ok_sql = r#"
196196
-- NON-VOLATILE
197197
ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
@@ -200,7 +200,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
200200
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
201201
}
202202
#[test]
203-
fn test_default_enum_ok() {
203+
fn default_enum_ok() {
204204
let ok_sql = r#"
205205
-- NON-VOLATILE
206206
ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-variant';
@@ -209,7 +209,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-varia
209209
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
210210
}
211211
#[test]
212-
fn test_default_jsonb_ok() {
212+
fn default_jsonb_ok() {
213213
let ok_sql = r#"
214214
-- NON-VOLATILE
215215
ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
@@ -218,7 +218,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
218218
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
219219
}
220220
#[test]
221-
fn test_default_arbitrary_func_err() {
221+
fn default_arbitrary_func_err() {
222222
let ok_sql = r#"
223223
-- NON-VOLATILE
224224
ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
@@ -227,7 +227,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
227227
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
228228
}
229229
#[test]
230-
fn test_default_random_with_args_err() {
230+
fn default_random_with_args_err() {
231231
let ok_sql = r#"
232232
-- NON-VOLATILE
233233
ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
@@ -236,7 +236,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
236236
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
237237
}
238238
#[test]
239-
fn test_default_now_func_ok() {
239+
fn default_now_func_ok() {
240240
let ok_sql = r#"
241241
-- NON-VOLATILE
242242
ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
@@ -245,7 +245,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
245245
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
246246
}
247247
#[test]
248-
fn test_add_numbers_ok() {
248+
fn add_numbers_ok() {
249249
// This should be okay, but we don't handle expressions like this at the moment.
250250
let ok_sql = r"
251251
alter table account_metadata add column blah integer default 2 + 2;
@@ -255,7 +255,7 @@ alter table account_metadata add column blah integer default 2 + 2;
255255
}
256256

257257
#[test]
258-
fn test_generated_stored() {
258+
fn generated_stored() {
259259
let bad_sql = r"
260260
ALTER TABLE foo
261261
ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;

linter/src/rules/adding_foreign_key_constraint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod test_rules {
8585
}
8686

8787
#[test]
88-
fn test_create_table_with_foreign_key_constraint() {
88+
fn create_table_with_foreign_key_constraint() {
8989
let sql = r#"
9090
BEGIN;
9191
CREATE TABLE email (
@@ -104,7 +104,7 @@ COMMIT;
104104
assert_eq!(violations.len(), 0);
105105
}
106106
#[test]
107-
fn test_add_foreign_key_constraint_not_valid_validate() {
107+
fn add_foreign_key_constraint_not_valid_validate() {
108108
let sql = r#"
109109
BEGIN;
110110
ALTER TABLE "email" ADD COLUMN "user_id" INT;
@@ -117,7 +117,7 @@ COMMIT;
117117
assert_eq!(violations.len(), 0);
118118
}
119119
#[test]
120-
fn test_add_foreign_key_constraint_lock() {
120+
fn add_foreign_key_constraint_lock() {
121121
let sql = r#"
122122
BEGIN;
123123
ALTER TABLE "email" ADD COLUMN "user_id" INT;
@@ -133,7 +133,7 @@ COMMIT;
133133
);
134134
}
135135
#[test]
136-
fn test_add_column_references_lock() {
136+
fn add_column_references_lock() {
137137
let sql = r#"
138138
BEGIN;
139139
ALTER TABLE "emails" ADD COLUMN "user_id" INT REFERENCES "user" ("id");

linter/src/rules/adding_not_null_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ mod test_rules {
6363
use insta::assert_debug_snapshot;
6464

6565
#[test]
66-
fn test_set_not_null() {
66+
fn set_not_null() {
6767
let sql = r#"
6868
ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL;
6969
"#;
7070
assert_debug_snapshot!(lint_sql(sql, None));
7171
}
7272

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

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

9595
#[test]
96-
fn test_adding_field_that_is_not_nullable_in_version_11() {
96+
fn adding_field_that_is_not_nullable_in_version_11() {
9797
let ok_sql = r#"
9898
BEGIN;
9999
--

linter/src/rules/adding_primary_key_constraint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod test_rules {
7575
}
7676

7777
#[test]
78-
fn test_serial_primary_key() {
78+
fn serial_primary_key() {
7979
let bad_sql = r"
8080
ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
8181
";
@@ -86,7 +86,7 @@ ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
8686
}
8787

8888
#[test]
89-
fn test_plain_primary_key() {
89+
fn plain_primary_key() {
9090
let bad_sql = r"
9191
ALTER TABLE items ADD PRIMARY KEY (id);
9292
";

0 commit comments

Comments
 (0)