insta icon indicating copy to clipboard operation
insta copied to clipboard

Group multiple assertions into one file

Open tisonkun opened this issue 1 year ago • 4 comments

Hi @mitsuhiko! Thanks for releasing this amazing crate for snapshot tests :D

I'm currently using insta to write SQL tests and assert the result set as snapshot. For demonstration, it looks like:

assert_snapshot!(execute("<sql-statements>"));

// result set
+------------+---------------+
| col_0::int | col_1::string |
+------------+---------------+
|         42 |       'tison' |
+------------+---------------+

This works well. But it generates one snapshot file per assertions, and I will have thousands of SQL statements to test and it creates too many files to store the snapshot.

Thus, I wonder if it's possible to group multiple assertions so that their snapshots are stored into one file.

Looking forward to your feedback.

tisonkun avatar May 26 '24 06:05 tisonkun

Other solutions for SQL tests can be found like:

  • https://github.com/GreptimeTeam/greptimedb/blob/main/tests/cases/standalone/common/basic.result
  • https://github.com/risinglightdb/sqllogictest-rs/blob/main/tests/slt/basic.slt

Despite the DSL and inputs part, you may notice it contains multiple statements and all the output in one file.

tisonkun avatar May 26 '24 06:05 tisonkun

Do inline snapshots help here? Over at PRQL we use them a lot for small snapshots...

max-sixty avatar May 26 '24 16:05 max-sixty

@max-sixty Yeah ... This sounds reasonable and it would take almost the same lines like sqllogictest/sqlness linked above.

So snapshot files are mainly for large outputs and inline snapshots are encouraged for other scenarios?

tisonkun avatar May 26 '24 22:05 tisonkun

So snapshot files are mainly for large outputs and inline snapshots are encouraged for other scenarios?

Yes, that's how I generally think about them (though just my view, not necessarily the project's...)

max-sixty avatar May 26 '24 22:05 max-sixty

I think this is fairly well covered by inline snapshots, so I'll close, but feel free to reopen if you disagree

max-sixty avatar Jul 07 '24 17:07 max-sixty