@@ -123,10 +123,14 @@ pub(crate) fn adding_field_with_default(ctx: &mut Linter, parse: &Parse<SourceFi
123123
124124#[ cfg( test) ]
125125mod test {
126- use insta:: assert_debug_snapshot ;
126+ use insta:: assert_snapshot ;
127127
128- use crate :: Rule ;
129- use crate :: test_utils:: { lint, lint_with_postgres_version} ;
128+ use crate :: test_utils:: { lint_errors, lint_ok} ;
129+ use crate :: { LinterSettings , Rule } ;
130+
131+ fn lint_errors_with ( sql : & str , settings : LinterSettings ) -> String {
132+ crate :: test_utils:: lint_errors_with ( sql, settings, Rule :: AddingFieldWithDefault )
133+ }
130134
131135 #[ test]
132136 fn docs_example_ok_post_pg_11 ( ) {
@@ -135,9 +139,7 @@ mod test {
135139ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
136140 "# ;
137141
138- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
139- assert ! ( errors. is_empty( ) ) ;
140- assert_debug_snapshot ! ( errors) ;
142+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
141143 }
142144
143145 #[ test]
@@ -150,9 +152,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
150152-- remove nullability
151153 "# ;
152154
153- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
154- assert ! ( errors. is_empty( ) ) ;
155- assert_debug_snapshot ! ( errors) ;
155+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
156156 }
157157
158158 #[ test]
@@ -161,9 +161,7 @@ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET DEFAULT 10;
161161alter table t set logged, add column c integer default uuid();
162162 "# ;
163163
164- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
165- assert ! ( !errors. is_empty( ) ) ;
166- assert_debug_snapshot ! ( errors) ;
164+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
167165 }
168166
169167 #[ test]
@@ -172,9 +170,7 @@ alter table t set logged, add column c integer default uuid();
172170ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
173171 "# ;
174172
175- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
176- assert ! ( !errors. is_empty( ) ) ;
177- assert_debug_snapshot ! ( errors) ;
173+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
178174 }
179175
180176 #[ test]
@@ -184,9 +180,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
184180ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
185181 "# ;
186182
187- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
188- assert ! ( !errors. is_empty( ) ) ;
189- assert_debug_snapshot ! ( errors) ;
183+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
190184 }
191185
192186 #[ test]
@@ -196,9 +190,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
196190ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT true;
197191 "# ;
198192
199- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
200- assert ! ( errors. is_empty( ) ) ;
201- assert_debug_snapshot ! ( errors) ;
193+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
202194 }
203195
204196 #[ test]
@@ -211,9 +203,7 @@ alter table t add column b bigint[] default cast(array[] as bigint[]);
211203alter table t add column c text[] default array['foo', 'bar']::text[];
212204 "# ;
213205
214- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
215- assert ! ( errors. is_empty( ) ) ;
216- assert_debug_snapshot ! ( errors) ;
206+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
217207 }
218208
219209 #[ test]
@@ -223,9 +213,7 @@ ALTER TABLE assessments
223213ADD COLUMN statistics_last_updated_at timestamptz NOT NULL DEFAULT now() - interval '100 years';
224214 "# ;
225215
226- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
227- assert ! ( errors. is_empty( ) ) ;
228- assert_debug_snapshot ! ( errors) ;
216+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
229217 }
230218
231219 #[ test]
@@ -235,9 +223,7 @@ ADD COLUMN statistics_last_updated_at timestamptz NOT NULL DEFAULT now() - inter
235223ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
236224 "# ;
237225
238- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
239- assert ! ( errors. is_empty( ) ) ;
240- assert_debug_snapshot ! ( errors) ;
226+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
241227 }
242228
243229 #[ test]
@@ -247,9 +233,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" text DEFAULT 'some-str';
247233ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-variant';
248234 "# ;
249235
250- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
251- assert ! ( errors. is_empty( ) ) ;
252- assert_debug_snapshot ! ( errors) ;
236+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
253237 }
254238
255239 #[ test]
@@ -259,9 +243,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" some_enum_type DEFAULT 'my-enum-varia
259243ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
260244 "# ;
261245
262- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
263- assert ! ( errors. is_empty( ) ) ;
264- assert_debug_snapshot ! ( errors) ;
246+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
265247 }
266248
267249 #[ test]
@@ -271,9 +253,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT '{}'::jsonb;
271253ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
272254 "# ;
273255
274- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
275- assert ! ( !errors. is_empty( ) ) ;
276- assert_debug_snapshot ! ( errors) ;
256+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
277257 }
278258
279259 #[ test]
@@ -283,9 +263,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
283263ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
284264 "# ;
285265
286- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
287- assert ! ( !errors. is_empty( ) ) ;
288- assert_debug_snapshot ! ( errors) ;
266+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
289267 }
290268
291269 #[ test]
@@ -295,9 +273,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
295273ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
296274 "# ;
297275
298- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
299- assert ! ( errors. is_empty( ) ) ;
300- assert_debug_snapshot ! ( errors) ;
276+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
301277 }
302278
303279 #[ test]
@@ -306,9 +282,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
306282alter table t add column c timestamptz default current_timestamp;
307283 "# ;
308284
309- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
310- assert ! ( errors. is_empty( ) ) ;
311- assert_debug_snapshot ! ( errors) ;
285+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
312286 }
313287
314288 #[ test]
@@ -317,9 +291,7 @@ alter table t add column c timestamptz default current_timestamp;
317291alter table account_metadata add column blah integer default 2 + 2;
318292 "# ;
319293
320- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
321- assert ! ( errors. is_empty( ) ) ;
322- assert_debug_snapshot ! ( errors) ;
294+ lint_ok ( sql, Rule :: AddingFieldWithDefault ) ;
323295 }
324296
325297 #[ test]
@@ -329,9 +301,7 @@ ALTER TABLE foo
329301ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;
330302 "# ;
331303
332- let errors = lint ( sql, Rule :: AddingFieldWithDefault ) ;
333- assert ! ( !errors. is_empty( ) ) ;
334- assert_debug_snapshot ! ( errors) ;
304+ assert_snapshot ! ( lint_errors( sql, Rule :: AddingFieldWithDefault ) ) ;
335305 }
336306
337307 #[ test]
@@ -341,8 +311,12 @@ ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;
341311ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
342312 "# ;
343313
344- let errors = lint_with_postgres_version ( sql, Rule :: AddingFieldWithDefault , "11" ) ;
345- assert ! ( !errors. is_empty( ) ) ;
346- assert_debug_snapshot ! ( errors) ;
314+ assert_snapshot ! ( lint_errors_with(
315+ sql,
316+ LinterSettings {
317+ pg_version: "11" . parse( ) . expect( "Invalid PostgreSQL version" ) ,
318+ ..Default :: default ( )
319+ } ,
320+ ) ) ;
347321 }
348322}
0 commit comments